Skip to content

Commit d4f1fc7

Browse files
committed
C#: Add some integration tests for 'dotnet run' and do some minor validation of the output.
1 parent c978798 commit d4f1fc7

File tree

1 file changed

+31
-5
lines changed
  • csharp/ql/integration-tests/all-platforms/dotnet_run

1 file changed

+31
-5
lines changed
Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
1+
import os
12
from create_database_utils import *
23

4+
def run_codeql_database_create_stdout(args, dbname):
5+
stdout = open(dbname + "file.txt", 'w+')
6+
run_codeql_database_create(args, test_db=dbname, db=None, stdout=stdout, lang="csharp")
7+
stdout.seek(0)
8+
s = stdout.read()
9+
stdout.close()
10+
return s
11+
12+
def check_build_out(msg, s):
13+
if "[build-stdout] " + msg not in s:
14+
raise Exception("The C# extractor did not interpret the 'dotnet run' command correctly")
15+
316
# no arguments
4-
run_codeql_database_create(['dotnet run'], test_db="test-db", db=None, lang="csharp")
17+
s = run_codeql_database_create_stdout(['dotnet run'], "test-db")
18+
check_build_out("Default reply", s)
519

620
# no arguments, but `--`
7-
run_codeql_database_create(['dotnet clean', 'rm -rf test-db', 'dotnet run --'], test_db="test2-db", db=None, lang="csharp")
21+
s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test-db', 'dotnet run --'], "test2-db")
22+
check_build_out("Default reply", s)
23+
24+
# one argument, no `--`
25+
s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test2-db', 'dotnet run hello'], "test3-db")
26+
check_build_out("Default reply", s)
27+
28+
# one argument, but `--`
29+
s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test3-db', 'dotnet run hello'], "test4-db")
30+
check_build_out("Default reply", s)
831

932
# two arguments, no `--`
10-
run_codeql_database_create(['dotnet clean', 'rm -rf test2-db', 'dotnet run hello world'], test_db="test3-db", db=None, lang="csharp")
33+
s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test4-db', 'dotnet run hello world'], "test5-db")
34+
check_build_out("hello, world", s)
1135

1236
# two arguments, and `--`
13-
run_codeql_database_create(['dotnet clean', 'rm -rf test3-db', 'dotnet run -- hello world'], test_db="test4-db", db=None, lang="csharp")
37+
s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test5-db', 'dotnet run -- hello world'], "test6-db")
38+
check_build_out("hello, world", s)
1439

1540
# shared compilation enabled; tracer should override by changing the command
1641
# to `dotnet run -p:UseSharedCompilation=true -p:UseSharedCompilation=false -- hello world`
17-
run_codeql_database_create(['dotnet clean', 'rm -rf test4-db', 'dotnet run -p:UseSharedCompilation=true -- hello world'], test_db="test5-db", db=None, lang="csharp")
42+
s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test6-db', 'dotnet run -p:UseSharedCompilation=true -- hello world'], "test7-db")
43+
check_build_out("hello, world", s)

0 commit comments

Comments
 (0)