From f6c36af6bd5f1faf4c1474b78281235baa616eff Mon Sep 17 00:00:00 2001 From: Michael Nebel Date: Mon, 18 Nov 2024 11:19:04 +0100 Subject: [PATCH] C#: Use ConsoleLogger instead og TerminalLogger for test output. --- .../all-platforms/dotnet_build/test.py | 5 +++++ .../all-platforms/dotnet_run/test.py | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_build/test.py b/csharp/ql/integration-tests/all-platforms/dotnet_build/test.py index 2b0869a6823e3..227bcded77cf3 100644 --- a/csharp/ql/integration-tests/all-platforms/dotnet_build/test.py +++ b/csharp/ql/integration-tests/all-platforms/dotnet_build/test.py @@ -1,8 +1,12 @@ +import os + def check_build_out(msg, s): assert ( "[build-stdout] " + msg in s ), f"The C# tracer did not interpret the dotnet path-to-application command correctly." +def useConsoleLogger(): + os.environ["MSBUILDTERMINALLOGGER"]="off" def test1(codeql, csharp): codeql.database.create(command="dotnet build") @@ -10,6 +14,7 @@ def test1(codeql, csharp): # This test checks that we don't inject any flags when running the application using `dotnet` def test2(codeql, csharp, cwd): + useConsoleLogger() s = codeql.database.create( command=[ "dotnet build -o my_program", diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_run/test.py b/csharp/ql/integration-tests/all-platforms/dotnet_run/test.py index ad71240ff9bd8..8d886f8c5d05b 100644 --- a/csharp/ql/integration-tests/all-platforms/dotnet_run/test.py +++ b/csharp/ql/integration-tests/all-platforms/dotnet_run/test.py @@ -1,41 +1,50 @@ +import os def check_build_out(msg, s): assert ( "[build-stdout] " + msg in s ), "The C# tracer did not interpret the 'dotnet run' command correctly" +def useConsoleLogger(): + os.environ["MSBUILDTERMINALLOGGER"]="off" # no arguments def test_no_args(codeql, csharp): + useConsoleLogger() s = codeql.database.create(command="dotnet run", _capture="stdout") check_build_out("Default reply", s) # no arguments, but `--` def test_no_arg_dash_dash(codeql, csharp): + useConsoleLogger() s = codeql.database.create(command="dotnet run --", _capture="stdout") check_build_out("Default reply", s) # one argument, no `--` def test_one_arg_no_dash_dash(codeql, csharp): + useConsoleLogger() s = codeql.database.create(command="dotnet run hello", _capture="stdout") check_build_out("Default reply", s) # one argument, but `--` def test_one_arg_dash_dash(codeql, csharp): + useConsoleLogger() s = codeql.database.create(command="dotnet run -- hello", _capture="stdout") check_build_out("Default reply", s) # two arguments, no `--` def test_two_args_no_dash_dash(codeql, csharp): + useConsoleLogger() s = codeql.database.create(command="dotnet run hello world", _capture="stdout") check_build_out("hello, world", s) # two arguments, and `--` def test_two_args_dash_dash(codeql, csharp): + useConsoleLogger() s = codeql.database.create(command="dotnet run -- hello world", _capture="stdout") check_build_out("hello, world", s) @@ -43,6 +52,7 @@ def test_two_args_dash_dash(codeql, csharp): # shared compilation enabled; tracer should override by changing the command # to `dotnet run -p:UseSharedCompilation=true -p:UseSharedCompilation=false -- hello world` def test_shared_compilation(codeql, csharp): + useConsoleLogger() s = codeql.database.create( command="dotnet run -p:UseSharedCompilation=true -- hello world", _capture="stdout" ) @@ -51,6 +61,7 @@ def test_shared_compilation(codeql, csharp): # option passed into `dotnet run` def test_option(codeql, csharp): + useConsoleLogger() s = codeql.database.create( command=["dotnet build", "dotnet run --no-build hello world"], _capture="stdout" ) @@ -59,11 +70,13 @@ def test_option(codeql, csharp): # two arguments, no '--' (first argument quoted) def test_two_args_no_dash_dash_quote_first(codeql, csharp): + useConsoleLogger() s = codeql.database.create(command='dotnet run "hello world" part2', _capture="stdout") check_build_out("hello world, part2", s) # two arguments, no '--' (second argument quoted) and using dotnet to execute dotnet def test_two_args_no_dash_dash_quote_second(codeql, csharp): + useConsoleLogger() s = codeql.database.create(command='dotnet dotnet run hello "world part2"', _capture="stdout") check_build_out("hello, world part2", s)