Skip to content

Commit

Permalink
Merge pull request #13387 from michaelnebel/csharp/dotnettest
Browse files Browse the repository at this point in the history
C#: Dotnet test tracer improvements.
  • Loading branch information
hvitved authored Jun 8, 2023
2 parents 22b9ab4 + 2fece9d commit a896be7
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 2 deletions.
7 changes: 6 additions & 1 deletion csharp/ql/integration-tests/posix-only/dotnet_test/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from create_database_utils import *
from diagnostics_test_utils import *

run_codeql_database_create(['dotnet test'], db=None, lang="csharp")
# Implicitly build and then run tests.
run_codeql_database_create(['dotnet test'], test_db="test-db", lang="csharp")
check_diagnostics()

# Explicitly build and then run tests.
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")
check_diagnostics(test_db="test2-db")
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace dotnet_test_mstest;

[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<OutputType>Exe</OutputType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions csharp/ql/integration-tests/posix-only/dotnet_test_mstest/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from create_database_utils import *
from diagnostics_test_utils import *

# Implicitly build and then run tests.
run_codeql_database_create(['dotnet test'], test_db="test-db", lang="csharp")
check_diagnostics()

# Explicitly build and then run tests.
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")
check_diagnostics(test_db="test2-db")
4 changes: 4 additions & 0 deletions csharp/ql/lib/change-notes/2023-06-06-dotnettest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* 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.
13 changes: 12 additions & 1 deletion csharp/tools/tracing-config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function RegisterExtractorPack(id)
-- if that's `build`, we append `-p:UseSharedCompilation=false` to the command line,
-- otherwise we do nothing.
local match = false
local testMatch = false
local dotnetRunNeedsSeparator = false;
local dotnetRunInjectionIndex = nil;
local argv = compilerArguments.argv
Expand All @@ -37,7 +38,7 @@ function RegisterExtractorPack(id)
if (not match) then
Log(1, 'Dotnet subcommand detected: %s', arg)
end
if arg == 'build' or arg == 'msbuild' or arg == 'publish' or arg == 'pack' or arg == 'test' then
if arg == 'build' or arg == 'msbuild' or arg == 'publish' or arg == 'pack' then
match = true
break
end
Expand All @@ -48,6 +49,16 @@ function RegisterExtractorPack(id)
dotnetRunNeedsSeparator = true
dotnetRunInjectionIndex = i + 1
end
if arg == 'test' then
match = true
testMatch = true
end
-- for `dotnet test`, we should not append `-p:UseSharedCompilation=false` to the command line
-- if an `exe` or `dll` is passed as an argument as the call is forwarded to vstest.
if testMatch and (arg:match('%.exe$') or arg:match('%.dll')) then
match = false
break
end
end
-- if we see a separator to `dotnet run`, inject just prior to the existing separator
if arg == '--' then
Expand Down

0 comments on commit a896be7

Please sign in to comment.