|
| 1 | +import os |
1 | 2 | from create_database_utils import *
|
2 | 3 |
|
| 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 | + |
3 | 16 | # 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) |
5 | 19 |
|
6 | 20 | # no arguments, but `--`
|
7 |
| -run_codeql_database_create(['dotnet clean', 'rm -rf test-db obj bin', '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) |
8 | 31 |
|
9 | 32 | # two arguments, no `--`
|
10 |
| -run_codeql_database_create(['dotnet clean', 'rm -rf test2-db obj bin', '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) |
11 | 35 |
|
12 | 36 | # two arguments, and `--`
|
13 |
| -run_codeql_database_create(['dotnet clean', 'rm -rf test3-db obj bin', '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) |
14 | 39 |
|
15 | 40 | # shared compilation enabled; tracer should override by changing the command
|
16 | 41 | # to `dotnet run -p:UseSharedCompilation=true -p:UseSharedCompilation=false -- hello world`
|
17 |
| -run_codeql_database_create(['dotnet clean', 'rm -rf test4-db obj bin', '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