From 9cac76dc3769296d35b7ea117842039e0cd83049 Mon Sep 17 00:00:00 2001 From: Kevin Gosse Date: Fri, 3 Nov 2023 11:20:02 +0100 Subject: [PATCH] Properly feed the arguments to dd-dotnet (#4775) --- .../CheckCommand.cs | 10 +++++++--- .../CheckCommandTests.cs | 19 ++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tracer/src/Datadog.Trace.Tools.Runner/CheckCommand.cs b/tracer/src/Datadog.Trace.Tools.Runner/CheckCommand.cs index 286af3a52962..bc6b4aad3bb4 100644 --- a/tracer/src/Datadog.Trace.Tools.Runner/CheckCommand.cs +++ b/tracer/src/Datadog.Trace.Tools.Runner/CheckCommand.cs @@ -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}"); @@ -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); diff --git a/tracer/test/Datadog.Trace.Tools.Runner.ArtifactTests/CheckCommandTests.cs b/tracer/test/Datadog.Trace.Tools.Runner.ArtifactTests/CheckCommandTests.cs index ff278ad85d32..68f9f33b3af6 100644 --- a/tracer/test/Datadog.Trace.Tools.Runner.ArtifactTests/CheckCommandTests.cs +++ b/tracer/test/Datadog.Trace.Tools.Runner.ArtifactTests/CheckCommandTests.cs @@ -3,6 +3,7 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc. // +using Datadog.Trace.TestHelpers; using FluentAssertions; using Xunit; @@ -10,7 +11,7 @@ namespace Datadog.Trace.Tools.Runner.ArtifactTests; public class CheckCommandTests : RunnerTests { - [Fact] + [SkippableFact] public void Help() { using var helper = StartProcess("check"); @@ -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"); + } }