Skip to content

Commit 4963835

Browse files
authored
Merge pull request #10540 from michaelnebel/csharp/dotnet-run-validate
C# Integration test validations for `dotnet run`.
2 parents 71da217 + 1b25d23 commit 4963835

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Console.WriteLine(args.Length > 0 ? args[0] + ", " + args[1] : "");
1+
Console.WriteLine(args.Length > 1 ? args[0] + ", " + args[1] : "Default reply");

csharp/ql/integration-tests/all-platforms/dotnet_run/dotnet_run.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
<Nullable>enable</Nullable>
88
</PropertyGroup>
99

10+
<Target Name="DeleteBinObjFolders" BeforeTargets="Clean">
11+
<RemoveDir Directories=".\bin" />
12+
<RemoveDir Directories=".\obj" />
13+
</Target>
1014
</Project>
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 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)
831

932
# 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)
1135

1236
# 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)
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 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

Comments
 (0)