Skip to content

Commit a896be7

Browse files
authored
Merge pull request #13387 from michaelnebel/csharp/dotnettest
C#: Dotnet test tracer improvements.
2 parents 22b9ab4 + 2fece9d commit a896be7

File tree

7 files changed

+62
-2
lines changed

7 files changed

+62
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
from create_database_utils import *
22
from diagnostics_test_utils import *
33

4-
run_codeql_database_create(['dotnet test'], db=None, lang="csharp")
4+
# Implicitly build and then run tests.
5+
run_codeql_database_create(['dotnet test'], test_db="test-db", lang="csharp")
56
check_diagnostics()
7+
8+
# Explicitly build and then run tests.
9+
run_codeql_database_create(['dotnet clean', 'rm -rf test-db', 'dotnet build -o myout', 'dotnet test myout/dotnet_test.dll'], test_db="test2-db", lang="csharp")
10+
check_diagnostics(test_db="test2-db")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace dotnet_test_mstest;
2+
3+
[TestClass]
4+
public class UnitTest1
5+
{
6+
[TestMethod]
7+
public void TestMethod1()
8+
{
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using Microsoft.VisualStudio.TestTools.UnitTesting;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
8+
<IsPackable>false</IsPackable>
9+
<OutputType>Exe</OutputType>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
14+
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
15+
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
16+
<PackageReference Include="coverlet.collector" Version="3.1.2" />
17+
</ItemGroup>
18+
19+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from create_database_utils import *
2+
from diagnostics_test_utils import *
3+
4+
# Implicitly build and then run tests.
5+
run_codeql_database_create(['dotnet test'], test_db="test-db", lang="csharp")
6+
check_diagnostics()
7+
8+
# Explicitly build and then run tests.
9+
run_codeql_database_create(['dotnet clean', 'rm -rf test-db', 'dotnet build -o myout --os win', 'dotnet test myout/dotnet_test_mstest.exe'], test_db="test2-db", lang="csharp")
10+
check_diagnostics(test_db="test2-db")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* C#: Analysis of the `dotnet test` command supplied with a `dll` or `exe` file as argument no longer fails due to the addition of an erroneous `-p:SharedCompilation=false` argument.

csharp/tools/tracing-config.lua

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function RegisterExtractorPack(id)
2121
-- if that's `build`, we append `-p:UseSharedCompilation=false` to the command line,
2222
-- otherwise we do nothing.
2323
local match = false
24+
local testMatch = false
2425
local dotnetRunNeedsSeparator = false;
2526
local dotnetRunInjectionIndex = nil;
2627
local argv = compilerArguments.argv
@@ -37,7 +38,7 @@ function RegisterExtractorPack(id)
3738
if (not match) then
3839
Log(1, 'Dotnet subcommand detected: %s', arg)
3940
end
40-
if arg == 'build' or arg == 'msbuild' or arg == 'publish' or arg == 'pack' or arg == 'test' then
41+
if arg == 'build' or arg == 'msbuild' or arg == 'publish' or arg == 'pack' then
4142
match = true
4243
break
4344
end
@@ -48,6 +49,16 @@ function RegisterExtractorPack(id)
4849
dotnetRunNeedsSeparator = true
4950
dotnetRunInjectionIndex = i + 1
5051
end
52+
if arg == 'test' then
53+
match = true
54+
testMatch = true
55+
end
56+
-- for `dotnet test`, we should not append `-p:UseSharedCompilation=false` to the command line
57+
-- if an `exe` or `dll` is passed as an argument as the call is forwarded to vstest.
58+
if testMatch and (arg:match('%.exe$') or arg:match('%.dll')) then
59+
match = false
60+
break
61+
end
5162
end
5263
-- if we see a separator to `dotnet run`, inject just prior to the existing separator
5364
if arg == '--' then

0 commit comments

Comments
 (0)