Skip to content

Commit

Permalink
C#: Use ConsoleLogger instead og TerminalLogger for test output.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelnebel committed Nov 18, 2024
1 parent b4eac1a commit f6c36af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
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")


# 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",
Expand Down
13 changes: 13 additions & 0 deletions csharp/ql/integration-tests/all-platforms/dotnet_run/test.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,58 @@
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)


# 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"
)
Expand All @@ -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"
)
Expand All @@ -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)

0 comments on commit f6c36af

Please sign in to comment.