Skip to content

Commit

Permalink
Properly feed the arguments to dd-dotnet (#4775)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevingosse authored Nov 3, 2023
1 parent a444b97 commit 9cac76d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 7 additions & 3 deletions tracer/src/Datadog.Trace.Tools.Runner/CheckCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ private void Execute(InvocationContext context)
$"Unsupported platform/architecture combination: ({other.platform}{(other.musl ? " musl" : string.Empty)}/{other.arch})")
};

var commandLine = string.Join(' ', Environment.GetCommandLineArgs().Skip(1));

if (!File.Exists(ddDotnet))
{
Utils.WriteError($"dd-dotnet not found at {ddDotnet}");
Expand All @@ -72,7 +70,13 @@ private void Execute(InvocationContext context)
Process.Start("chmod", $"+x {ddDotnet}")!.WaitForExit();
}

var startInfo = new ProcessStartInfo(ddDotnet, commandLine) { UseShellExecute = false };
var startInfo = new ProcessStartInfo(ddDotnet) { UseShellExecute = false };

foreach (var arg in Environment.GetCommandLineArgs().Skip(1))
{
startInfo.ArgumentList.Add(arg);
}

startInfo.EnvironmentVariables["DD_INTERNAL_OVERRIDE_COMMAND"] = "dd-trace";

var process = Process.Start(startInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

using Datadog.Trace.TestHelpers;
using FluentAssertions;
using Xunit;

namespace Datadog.Trace.Tools.Runner.ArtifactTests;

public class CheckCommandTests : RunnerTests
{
[Fact]
[SkippableFact]
public void Help()
{
using var helper = StartProcess("check");
Expand All @@ -22,4 +23,20 @@ public void Help()
helper.StandardOutput.Should().Contain("dd-trace check [command] [options]");
helper.ErrorOutput.Should().Contain("Required command was not provided.");
}

[SkippableFact]
public void MultipleArguments()
{
// Currently we can only test this one Windows.
// The only command that accepts a space is "check iis" and it's not available on Linux.
SkipOn.Platform(SkipOn.PlatformValue.Linux);
using var helper = StartProcess("check iis \"hello world\"");

helper.Process.WaitForExit();
helper.Drain();

helper.Process.ExitCode.Should().Be(1);
helper.StandardOutput.Should().Contain("Could not find IIS application \"hello world/\".");
helper.ErrorOutput.Should().NotContain("Unrecognized command or argument");
}
}

0 comments on commit 9cac76d

Please sign in to comment.