From 59922e5c46c278c505701cbe0c4c2022918d91bc Mon Sep 17 00:00:00 2001 From: Cornelius Riemenschneider Date: Tue, 6 Aug 2024 16:51:25 +0200 Subject: [PATCH 1/3] Port C# tests to pytest. --- .../all-platforms/autobuild/test.py | 5 +- .../all-platforms/binlog/test.py | 11 ++- .../all-platforms/cshtml/test.py | 5 +- .../cshtml_standalone/Files.expected | 2 +- .../all-platforms/cshtml_standalone/Files.ql | 7 +- .../all-platforms/cshtml_standalone/test.py | 6 +- .../cshtml_standalone_disabled/test.py | 7 +- .../cshtml_standalone_flowsteps/test.py | 6 +- .../cshtml_standalone_net6/Files.expected | 2 +- .../cshtml_standalone_net6/Files.ql | 7 +- .../cshtml_standalone_net6/test.py | 6 +- .../diag_dotnet_incompatible/test.py | 7 +- .../diag_missing_project_files/test.py | 7 +- .../diag_missing_xamarin_sdk/test.py | 7 +- .../diag_recursive_generics/test.py | 5 +- .../dotnet_build/diagnostics.expected | 0 .../all-platforms/dotnet_build/test.py | 29 ++++--- .../dotnet_no_args_inject/test.py | 18 ++-- .../dotnet_pack/diagnostics.expected | 0 .../all-platforms/dotnet_pack/test.py | 13 ++- .../dotnet_publish/diagnostics.expected | 0 .../all-platforms/dotnet_publish/test.py | 13 +-- .../dotnet_run/diagnostics.expected | 0 .../all-platforms/dotnet_run/test.py | 82 +++++++++++-------- .../msbuild/diagnostics.expected | 0 .../all-platforms/msbuild/test.py | 9 +- .../all-platforms/source_generator/test.py | 5 +- .../all-platforms/standalone/test.py | 10 +-- .../standalone_buildless_option/test.py | 8 +- .../standalone_dependencies_net48/test.py | 5 +- .../all-platforms/standalone_failed/test.py | 8 +- .../all-platforms/standalone_resx/test.py | 6 +- .../all-platforms/standalone_winforms/test.py | 5 +- csharp/ql/integration-tests/legacy | 1 - .../linux-only/compiler_args/test.py | 7 +- .../test.py | 12 +-- .../posix-only/diag_autobuild_script/test.py | 9 +- .../posix-only/diag_multiple_scripts/test.py | 9 +- .../dotnet_test/diagnostics.expected | 0 .../posix-only/dotnet_test/test.py | 26 +++--- .../dotnet_test_mstest/diagnostics.expected | 0 .../posix-only/dotnet_test_mstest/test.py | 25 +++--- .../inherit-env-vars/diagnostics.expected | 0 .../posix-only/inherit-env-vars/test.py | 10 +-- .../standalone_dependencies/test.py | 7 +- .../test.py | 7 +- .../test.py | 7 +- .../test.py | 7 +- .../skip-on-platform-osx-arm | 1 - .../test.py | 13 ++- .../skip-on-platform-osx-arm | 1 - .../test.py | 14 ++-- .../skip-on-platform-osx-arm | 1 - .../standalone_dependencies_nuget/test.py | 9 +- .../test.py | 7 +- .../test.py | 35 +++++--- .../test.py | 26 +++--- .../skip-on-platform-osx-arm | 1 - .../test.py | 9 +- .../test.py | 7 +- .../posix-only/warn_as_error/test.py | 9 +- csharp/ql/integration-tests/qlpack.yml | 3 - .../diag_autobuild_script/test.py | 9 +- .../diag_multiple_scripts/test.py | 9 +- .../standalone_dependencies/test.py | 7 +- 65 files changed, 313 insertions(+), 276 deletions(-) create mode 100644 csharp/ql/integration-tests/all-platforms/dotnet_build/diagnostics.expected create mode 100644 csharp/ql/integration-tests/all-platforms/dotnet_pack/diagnostics.expected create mode 100644 csharp/ql/integration-tests/all-platforms/dotnet_publish/diagnostics.expected create mode 100644 csharp/ql/integration-tests/all-platforms/dotnet_run/diagnostics.expected create mode 100644 csharp/ql/integration-tests/all-platforms/msbuild/diagnostics.expected delete mode 100644 csharp/ql/integration-tests/legacy create mode 100644 csharp/ql/integration-tests/posix-only/dotnet_test/diagnostics.expected create mode 100644 csharp/ql/integration-tests/posix-only/dotnet_test_mstest/diagnostics.expected create mode 100644 csharp/ql/integration-tests/posix-only/inherit-env-vars/diagnostics.expected delete mode 100644 csharp/ql/integration-tests/posix-only/standalone_dependencies_no_framework/skip-on-platform-osx-arm delete mode 100644 csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget with_space/skip-on-platform-osx-arm delete mode 100644 csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget/skip-on-platform-osx-arm delete mode 100644 csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_no_sources/skip-on-platform-osx-arm delete mode 100644 csharp/ql/integration-tests/qlpack.yml diff --git a/csharp/ql/integration-tests/all-platforms/autobuild/test.py b/csharp/ql/integration-tests/all-platforms/autobuild/test.py index 89c7dbf7113..6edef5258f8 100644 --- a/csharp/ql/integration-tests/all-platforms/autobuild/test.py +++ b/csharp/ql/integration-tests/all-platforms/autobuild/test.py @@ -1,3 +1,2 @@ -from create_database_utils import * - -run_codeql_database_create([], lang="csharp") +def test(codeql, csharp): + codeql.database.create() diff --git a/csharp/ql/integration-tests/all-platforms/binlog/test.py b/csharp/ql/integration-tests/all-platforms/binlog/test.py index ad36c9599c3..d551651fb11 100644 --- a/csharp/ql/integration-tests/all-platforms/binlog/test.py +++ b/csharp/ql/integration-tests/all-platforms/binlog/test.py @@ -1,7 +1,6 @@ -import subprocess -from create_database_utils import * -from diagnostics_test_utils import * +import commands -subprocess.check_call(["dotnet", "build", "test.sln", "/bl:test.binlog"]) -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none", "-Obinlog=test.binlog"]) -check_diagnostics() + +def test(codeql, csharp): + commands.run(["dotnet", "build", "test.sln", "/bl:test.binlog"]) + codeql.database.create(build_mode="none", extractor_option="binlog=test.binlog") diff --git a/csharp/ql/integration-tests/all-platforms/cshtml/test.py b/csharp/ql/integration-tests/all-platforms/cshtml/test.py index b9be34f1efb..7085307904f 100644 --- a/csharp/ql/integration-tests/all-platforms/cshtml/test.py +++ b/csharp/ql/integration-tests/all-platforms/cshtml/test.py @@ -1,3 +1,2 @@ -from create_database_utils import * - -run_codeql_database_create(['dotnet build'], lang="csharp") +def test(codeql, csharp): + codeql.database.create(command="dotnet build") diff --git a/csharp/ql/integration-tests/all-platforms/cshtml_standalone/Files.expected b/csharp/ql/integration-tests/all-platforms/cshtml_standalone/Files.expected index ee3b14ffc8f..5d52ff6223d 100644 --- a/csharp/ql/integration-tests/all-platforms/cshtml_standalone/Files.expected +++ b/csharp/ql/integration-tests/all-platforms/cshtml_standalone/Files.expected @@ -1,4 +1,4 @@ | Program.cs | | Views/Home/Index.cshtml | -| _semmle_code_target_codeql_csharp_integration_tests_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_Views_Home_Index_cshtml.g.cs | +| _ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_test_test_Views_Home_Index_cshtml.g.cs | | test-db/working/implicitUsings/GlobalUsings.g.cs | diff --git a/csharp/ql/integration-tests/all-platforms/cshtml_standalone/Files.ql b/csharp/ql/integration-tests/all-platforms/cshtml_standalone/Files.ql index 2d983b86b7c..70a62a55481 100644 --- a/csharp/ql/integration-tests/all-platforms/cshtml_standalone/Files.ql +++ b/csharp/ql/integration-tests/all-platforms/cshtml_standalone/Files.ql @@ -2,15 +2,12 @@ import csharp private string getPath(File f) { result = f.getRelativePath() and - not exists( - result - .indexOf("_semmle_code_target_codeql_csharp_integration_tests_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_") - ) + not exists(result.indexOf("_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_")) or exists(int index | index = f.getRelativePath() - .indexOf("_semmle_code_target_codeql_csharp_integration_tests_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_") and + .indexOf("_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_") and result = f.getRelativePath().substring(index, f.getRelativePath().length()) ) } diff --git a/csharp/ql/integration-tests/all-platforms/cshtml_standalone/test.py b/csharp/ql/integration-tests/all-platforms/cshtml_standalone/test.py index 64b9f13b36b..237174a46c6 100644 --- a/csharp/ql/integration-tests/all-platforms/cshtml_standalone/test.py +++ b/csharp/ql/integration-tests/all-platforms/cshtml_standalone/test.py @@ -1,4 +1,2 @@ -import os -from create_database_utils import * - -run_codeql_database_create(lang="csharp", extra_args=["--build-mode=none"]) +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/all-platforms/cshtml_standalone_disabled/test.py b/csharp/ql/integration-tests/all-platforms/cshtml_standalone_disabled/test.py index 3e00c972b00..88ecf0e513a 100644 --- a/csharp/ql/integration-tests/all-platforms/cshtml_standalone_disabled/test.py +++ b/csharp/ql/integration-tests/all-platforms/cshtml_standalone_disabled/test.py @@ -1,5 +1,6 @@ import os -from create_database_utils import * -os.environ['CODEQL_EXTRACTOR_CSHARP_BUILDLESS_EXTRACT_WEB_VIEWS'] = 'false' -run_codeql_database_create(lang="csharp", extra_args=["--build-mode=none"]) + +def test(codeql, csharp): + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_EXTRACT_WEB_VIEWS"] = "false" + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/all-platforms/cshtml_standalone_flowsteps/test.py b/csharp/ql/integration-tests/all-platforms/cshtml_standalone_flowsteps/test.py index 64b9f13b36b..237174a46c6 100644 --- a/csharp/ql/integration-tests/all-platforms/cshtml_standalone_flowsteps/test.py +++ b/csharp/ql/integration-tests/all-platforms/cshtml_standalone_flowsteps/test.py @@ -1,4 +1,2 @@ -import os -from create_database_utils import * - -run_codeql_database_create(lang="csharp", extra_args=["--build-mode=none"]) +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/Files.expected b/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/Files.expected index b7396a111ab..3a66f337cff 100644 --- a/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/Files.expected +++ b/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/Files.expected @@ -1,4 +1,4 @@ | Program.cs | | Views/Home/Index.cshtml | -| _semmle_code_target_codeql_csharp_integration_tests_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_net6_Views_Home_Index_cshtml.g.cs | +| _ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_net6_test_test_Views_Home_Index_cshtml.g.cs | | test-db/working/implicitUsings/GlobalUsings.g.cs | diff --git a/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/Files.ql b/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/Files.ql index 2d983b86b7c..70a62a55481 100644 --- a/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/Files.ql +++ b/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/Files.ql @@ -2,15 +2,12 @@ import csharp private string getPath(File f) { result = f.getRelativePath() and - not exists( - result - .indexOf("_semmle_code_target_codeql_csharp_integration_tests_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_") - ) + not exists(result.indexOf("_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_")) or exists(int index | index = f.getRelativePath() - .indexOf("_semmle_code_target_codeql_csharp_integration_tests_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_") and + .indexOf("_ql_csharp_ql_integration_tests_all_platforms_cshtml_standalone_") and result = f.getRelativePath().substring(index, f.getRelativePath().length()) ) } diff --git a/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/test.py b/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/test.py index 64b9f13b36b..237174a46c6 100644 --- a/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/test.py +++ b/csharp/ql/integration-tests/all-platforms/cshtml_standalone_net6/test.py @@ -1,4 +1,2 @@ -import os -from create_database_utils import * - -run_codeql_database_create(lang="csharp", extra_args=["--build-mode=none"]) +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/all-platforms/diag_dotnet_incompatible/test.py b/csharp/ql/integration-tests/all-platforms/diag_dotnet_incompatible/test.py index 62c4d3934a4..a2676d16d9c 100644 --- a/csharp/ql/integration-tests/all-platforms/diag_dotnet_incompatible/test.py +++ b/csharp/ql/integration-tests/all-platforms/diag_dotnet_incompatible/test.py @@ -1,5 +1,2 @@ -from create_database_utils import * -from diagnostics_test_utils import * - -run_codeql_database_create([], db=None, lang="csharp", runFunction=runUnsuccessfully) -check_diagnostics() +def test(codeql, csharp): + codeql.database.create(_assert_failure=True) diff --git a/csharp/ql/integration-tests/all-platforms/diag_missing_project_files/test.py b/csharp/ql/integration-tests/all-platforms/diag_missing_project_files/test.py index 62c4d3934a4..a2676d16d9c 100644 --- a/csharp/ql/integration-tests/all-platforms/diag_missing_project_files/test.py +++ b/csharp/ql/integration-tests/all-platforms/diag_missing_project_files/test.py @@ -1,5 +1,2 @@ -from create_database_utils import * -from diagnostics_test_utils import * - -run_codeql_database_create([], db=None, lang="csharp", runFunction=runUnsuccessfully) -check_diagnostics() +def test(codeql, csharp): + codeql.database.create(_assert_failure=True) diff --git a/csharp/ql/integration-tests/all-platforms/diag_missing_xamarin_sdk/test.py b/csharp/ql/integration-tests/all-platforms/diag_missing_xamarin_sdk/test.py index 62c4d3934a4..a2676d16d9c 100644 --- a/csharp/ql/integration-tests/all-platforms/diag_missing_xamarin_sdk/test.py +++ b/csharp/ql/integration-tests/all-platforms/diag_missing_xamarin_sdk/test.py @@ -1,5 +1,2 @@ -from create_database_utils import * -from diagnostics_test_utils import * - -run_codeql_database_create([], db=None, lang="csharp", runFunction=runUnsuccessfully) -check_diagnostics() +def test(codeql, csharp): + codeql.database.create(_assert_failure=True) diff --git a/csharp/ql/integration-tests/all-platforms/diag_recursive_generics/test.py b/csharp/ql/integration-tests/all-platforms/diag_recursive_generics/test.py index b9be34f1efb..7085307904f 100644 --- a/csharp/ql/integration-tests/all-platforms/diag_recursive_generics/test.py +++ b/csharp/ql/integration-tests/all-platforms/diag_recursive_generics/test.py @@ -1,3 +1,2 @@ -from create_database_utils import * - -run_codeql_database_create(['dotnet build'], lang="csharp") +def test(codeql, csharp): + codeql.database.create(command="dotnet build") diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_build/diagnostics.expected b/csharp/ql/integration-tests/all-platforms/dotnet_build/diagnostics.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_build/test.py b/csharp/ql/integration-tests/all-platforms/dotnet_build/test.py index 6680a708e70..2b0869a6823 100644 --- a/csharp/ql/integration-tests/all-platforms/dotnet_build/test.py +++ b/csharp/ql/integration-tests/all-platforms/dotnet_build/test.py @@ -1,16 +1,21 @@ -from create_database_utils import * -from diagnostics_test_utils import * - def check_build_out(msg, s): - if "[build-stdout] " + msg not in s: - raise Exception("The C# tracer did not interpret the dotnet path-to-application command correctly.") + assert ( + "[build-stdout] " + msg in s + ), f"The C# tracer did not interpret the dotnet path-to-application command correctly." + + +def test1(codeql, csharp): + codeql.database.create(command="dotnet build") -run_codeql_database_create(['dotnet build'], test_db="test1-db", lang="csharp") -check_diagnostics(test_db="test1-db") # This test checks that we don't inject any flags when running the application using `dotnet` -my_dir = "my_program" -my_abs_path = os.path.abspath(f"{my_dir}/dotnet_build.dll") -s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test1-db', 'dotnet build -o my_program', f'dotnet {my_abs_path} build is not a subcommand'], "test2-db", "csharp") -check_build_out("build,is,not,a,subcommand", s) -check_diagnostics(test_db="test2-db") +def test2(codeql, csharp, cwd): + s = codeql.database.create( + command=[ + "dotnet build -o my_program", + f"dotnet {cwd / 'my_program'}/dotnet_build.dll build is not a subcommand", + ], + _capture="stdout", + ) + + check_build_out("build,is,not,a,subcommand", s) diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_no_args_inject/test.py b/csharp/ql/integration-tests/all-platforms/dotnet_no_args_inject/test.py index 0f2584104eb..d1a7fba4870 100644 --- a/csharp/ql/integration-tests/all-platforms/dotnet_no_args_inject/test.py +++ b/csharp/ql/integration-tests/all-platforms/dotnet_no_args_inject/test.py @@ -1,9 +1,9 @@ -from create_database_utils import * -from diagnostics_test_utils import * - -# the tracer configuration should not inject the extra command-line arguments for these commands -# and they should therefore run successfully -run_codeql_database_init(lang="csharp") -# this command fails on Windows for some reason, so we comment it out for now -# run_codeql_database_trace_command(['dotnet', 'tool', 'search', 'publish']) -run_codeql_database_trace_command(['dotnet', 'new', 'console', '--force', '--name', 'build', '--output', '.']) +def test(codeql, csharp): + codeql.database.init("test-db", source_root=".") + # the tracer configuration should not inject the extra command-line arguments for these commands + # and they should therefore run successfully + # this command fails on Windows for some reason, so we comment it out for now + # run_codeql_database_trace_command(['dotnet', 'tool', 'search', 'publish']) + codeql.database.trace_command( + "test-db", "dotnet", "new", "console", "--force", "--name", "build", "--output", "." + ) diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_pack/diagnostics.expected b/csharp/ql/integration-tests/all-platforms/dotnet_pack/diagnostics.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_pack/test.py b/csharp/ql/integration-tests/all-platforms/dotnet_pack/test.py index 258f5f3b764..fc75ed1870f 100644 --- a/csharp/ql/integration-tests/all-platforms/dotnet_pack/test.py +++ b/csharp/ql/integration-tests/all-platforms/dotnet_pack/test.py @@ -1,11 +1,8 @@ import os -from create_database_utils import * -from diagnostics_test_utils import * -run_codeql_database_create(['dotnet pack -o nugetpackage'], db=None, lang="csharp") -## Check that the NuGet package is created. -if not os.path.isfile("nugetpackage/dotnet_pack.1.0.0.nupkg"): - raise Exception("The NuGet package was not created.") - -check_diagnostics() +def test(codeql, csharp): + codeql.database.create(command="dotnet pack -o nugetpackage") + assert os.path.isfile( + "nugetpackage/dotnet_pack.1.0.0.nupkg" + ), "The NuGet package was not created." diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_publish/diagnostics.expected b/csharp/ql/integration-tests/all-platforms/dotnet_publish/diagnostics.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_publish/test.py b/csharp/ql/integration-tests/all-platforms/dotnet_publish/test.py index 10e617dd32e..ffe0332d663 100644 --- a/csharp/ql/integration-tests/all-platforms/dotnet_publish/test.py +++ b/csharp/ql/integration-tests/all-platforms/dotnet_publish/test.py @@ -1,12 +1,7 @@ import os -from create_database_utils import * -from diagnostics_test_utils import * -artifacts = 'bin/Temp' -run_codeql_database_create([f"dotnet publish -o {artifacts}"], db=None, lang="csharp") -## Check that the publish folder is created. -if not os.path.isdir(artifacts): - raise Exception("The publish artifact folder was not created.") - -check_diagnostics() +def test(codeql, csharp): + artifacts = "bin/Temp" + codeql.database.create(command=f"dotnet publish -o {artifacts}") + assert os.path.isdir(artifacts), "The publish artifact folder was not created." diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_run/diagnostics.expected b/csharp/ql/integration-tests/all-platforms/dotnet_run/diagnostics.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/csharp/ql/integration-tests/all-platforms/dotnet_run/test.py b/csharp/ql/integration-tests/all-platforms/dotnet_run/test.py index d1a44bdb1fe..ad71240ff9b 100644 --- a/csharp/ql/integration-tests/all-platforms/dotnet_run/test.py +++ b/csharp/ql/integration-tests/all-platforms/dotnet_run/test.py @@ -1,57 +1,69 @@ -from create_database_utils import * -from diagnostics_test_utils import * - def check_build_out(msg, s): - if "[build-stdout] " + msg not in s: - raise Exception("The C# tracer did not interpret the 'dotnet run' command correctly") + assert ( + "[build-stdout] " + msg in s + ), "The C# tracer did not interpret the 'dotnet run' command correctly" + # no arguments -s = run_codeql_database_create_stdout(['dotnet run'], "test-db", "csharp") -check_build_out("Default reply", s) -check_diagnostics() +def test_no_args(codeql, csharp): + s = codeql.database.create(command="dotnet run", _capture="stdout") + check_build_out("Default reply", s) + # no arguments, but `--` -s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test-db', 'dotnet run --'], "test2-db", "csharp") -check_build_out("Default reply", s) -check_diagnostics(test_db="test2-db") +def test_no_arg_dash_dash(codeql, csharp): + s = codeql.database.create(command="dotnet run --", _capture="stdout") + check_build_out("Default reply", s) + # one argument, no `--` -s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test2-db', 'dotnet run hello'], "test3-db", "csharp") -check_build_out("Default reply", s) -check_diagnostics(test_db="test3-db") +def test_one_arg_no_dash_dash(codeql, csharp): + s = codeql.database.create(command="dotnet run hello", _capture="stdout") + check_build_out("Default reply", s) + # one argument, but `--` -s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test3-db', 'dotnet run -- hello'], "test4-db", "csharp") -check_build_out("Default reply", s) -check_diagnostics(test_db="test4-db") +def test_one_arg_dash_dash(codeql, csharp): + s = codeql.database.create(command="dotnet run -- hello", _capture="stdout") + check_build_out("Default reply", s) + # two arguments, no `--` -s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test4-db', 'dotnet run hello world'], "test5-db", "csharp") -check_build_out("hello, world", s) -check_diagnostics(test_db="test5-db") +def test_two_args_no_dash_dash(codeql, csharp): + s = codeql.database.create(command="dotnet run hello world", _capture="stdout") + check_build_out("hello, world", s) + # two arguments, and `--` -s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test5-db', 'dotnet run -- hello world'], "test6-db", "csharp") -check_build_out("hello, world", s) -check_diagnostics(test_db="test6-db") +def test_two_args_dash_dash(codeql, csharp): + s = codeql.database.create(command="dotnet run -- hello world", _capture="stdout") + check_build_out("hello, world", s) + # shared compilation enabled; tracer should override by changing the command # to `dotnet run -p:UseSharedCompilation=true -p:UseSharedCompilation=false -- hello world` -s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test6-db', 'dotnet run -p:UseSharedCompilation=true -- hello world'], "test7-db", "csharp") -check_build_out("hello, world", s) -check_diagnostics(test_db="test7-db") +def test_shared_compilation(codeql, csharp): + s = codeql.database.create( + command="dotnet run -p:UseSharedCompilation=true -- hello world", _capture="stdout" + ) + check_build_out("hello, world", s) + # option passed into `dotnet run` -s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test7-db', 'dotnet build', 'dotnet run --no-build hello world'], "test8-db", "csharp") -check_build_out("hello, world", s) -check_diagnostics(test_db="test8-db") +def test_option(codeql, csharp): + s = codeql.database.create( + command=["dotnet build", "dotnet run --no-build hello world"], _capture="stdout" + ) + check_build_out("hello, world", s) + # two arguments, no '--' (first argument quoted) -s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test8-db', 'dotnet run "hello world part1" part2'], "test9-db", "csharp") -check_build_out("hello world part1, part2", s) -check_diagnostics(test_db="test9-db") +def test_two_args_no_dash_dash_quote_first(codeql, csharp): + s = codeql.database.create(command='dotnet run "hello world" part2', _capture="stdout") + check_build_out("hello world, part2", s) + # two arguments, no '--' (second argument quoted) and using dotnet to execute dotnet -s = run_codeql_database_create_stdout(['dotnet clean', 'rm -rf test9-db', 'dotnet dotnet run part1 "hello world part2"'], "test10-db", "csharp") -check_build_out("part1, hello world part2", s) -check_diagnostics(test_db="test10-db") +def test_two_args_no_dash_dash_quote_second(codeql, csharp): + s = codeql.database.create(command='dotnet dotnet run hello "world part2"', _capture="stdout") + check_build_out("hello, world part2", s) diff --git a/csharp/ql/integration-tests/all-platforms/msbuild/diagnostics.expected b/csharp/ql/integration-tests/all-platforms/msbuild/diagnostics.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/csharp/ql/integration-tests/all-platforms/msbuild/test.py b/csharp/ql/integration-tests/all-platforms/msbuild/test.py index 7471e3374e5..d9337907335 100644 --- a/csharp/ql/integration-tests/all-platforms/msbuild/test.py +++ b/csharp/ql/integration-tests/all-platforms/msbuild/test.py @@ -1,6 +1,3 @@ -from create_database_utils import * -from diagnostics_test_utils import * - -# force CodeQL to use MSBuild by setting `LGTM_INDEX_MSBUILD_TARGET` -run_codeql_database_create([], db=None, lang="csharp", extra_env={ 'LGTM_INDEX_MSBUILD_TARGET': 'Build' }) -check_diagnostics() +def test(codeql, csharp): + # force CodeQL to use MSBuild by setting `LGTM_INDEX_MSBUILD_TARGET` + codeql.database.create(_env={"LGTM_INDEX_MSBUILD_TARGET": "Build"}) diff --git a/csharp/ql/integration-tests/all-platforms/source_generator/test.py b/csharp/ql/integration-tests/all-platforms/source_generator/test.py index b9be34f1efb..7085307904f 100644 --- a/csharp/ql/integration-tests/all-platforms/source_generator/test.py +++ b/csharp/ql/integration-tests/all-platforms/source_generator/test.py @@ -1,3 +1,2 @@ -from create_database_utils import * - -run_codeql_database_create(['dotnet build'], lang="csharp") +def test(codeql, csharp): + codeql.database.create(command="dotnet build") diff --git a/csharp/ql/integration-tests/all-platforms/standalone/test.py b/csharp/ql/integration-tests/all-platforms/standalone/test.py index f7797467cf8..f93a36594c8 100644 --- a/csharp/ql/integration-tests/all-platforms/standalone/test.py +++ b/csharp/ql/integration-tests/all-platforms/standalone/test.py @@ -1,9 +1,7 @@ import os -from create_database_utils import * -from diagnostics_test_utils import * -os.environ['CODEQL_EXTRACTOR_CSHARP_OPTION_COMPILER_DIAGNOSTIC_LIMIT'] = '2' -os.environ['CODEQL_EXTRACTOR_CSHARP_OPTION_MESSAGE_LIMIT'] = '5' -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) -check_diagnostics() \ No newline at end of file +def test(codeql, csharp): + os.environ["CODEQL_EXTRACTOR_CSHARP_OPTION_COMPILER_DIAGNOSTIC_LIMIT"] = "2" + os.environ["CODEQL_EXTRACTOR_CSHARP_OPTION_MESSAGE_LIMIT"] = "5" + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/all-platforms/standalone_buildless_option/test.py b/csharp/ql/integration-tests/all-platforms/standalone_buildless_option/test.py index 6f52d5caa05..9a17ccf3b59 100644 --- a/csharp/ql/integration-tests/all-platforms/standalone_buildless_option/test.py +++ b/csharp/ql/integration-tests/all-platforms/standalone_buildless_option/test.py @@ -1,8 +1,6 @@ import os -from create_database_utils import * -from diagnostics_test_utils import * -os.environ['CODEQL_EXTRACTOR_CSHARP_OPTION_BUILDLESS'] = 'true' -run_codeql_database_create([], lang="csharp") -check_diagnostics() +def test(codeql, csharp): + os.environ["CODEQL_EXTRACTOR_CSHARP_OPTION_BUILDLESS"] = "true" + codeql.database.create() diff --git a/csharp/ql/integration-tests/all-platforms/standalone_dependencies_net48/test.py b/csharp/ql/integration-tests/all-platforms/standalone_dependencies_net48/test.py index a17966e148a..237174a46c6 100644 --- a/csharp/ql/integration-tests/all-platforms/standalone_dependencies_net48/test.py +++ b/csharp/ql/integration-tests/all-platforms/standalone_dependencies_net48/test.py @@ -1,3 +1,2 @@ -from create_database_utils import * - -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/all-platforms/standalone_failed/test.py b/csharp/ql/integration-tests/all-platforms/standalone_failed/test.py index 403e8efff23..2d8beed3deb 100644 --- a/csharp/ql/integration-tests/all-platforms/standalone_failed/test.py +++ b/csharp/ql/integration-tests/all-platforms/standalone_failed/test.py @@ -1,6 +1,2 @@ -from create_database_utils import * -from diagnostics_test_utils import * - -run_codeql_database_create([], db=None, lang="csharp", extra_args=["--build-mode=none"], runFunction=runUnsuccessfully) - -check_diagnostics() +def test(codeql, csharp): + codeql.database.create(build_mode="none", _assert_failure=True) diff --git a/csharp/ql/integration-tests/all-platforms/standalone_resx/test.py b/csharp/ql/integration-tests/all-platforms/standalone_resx/test.py index cda1034d075..ef1399f4cb2 100644 --- a/csharp/ql/integration-tests/all-platforms/standalone_resx/test.py +++ b/csharp/ql/integration-tests/all-platforms/standalone_resx/test.py @@ -1,6 +1,6 @@ import os -from create_database_utils import * -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_EXTRACT_RESOURCES"] = "true" -run_codeql_database_create(lang="csharp", extra_args=["--build-mode=none"]) +def test(codeql, csharp): + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_EXTRACT_RESOURCES"] = "true" + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/all-platforms/standalone_winforms/test.py b/csharp/ql/integration-tests/all-platforms/standalone_winforms/test.py index 8609eca2f16..237174a46c6 100644 --- a/csharp/ql/integration-tests/all-platforms/standalone_winforms/test.py +++ b/csharp/ql/integration-tests/all-platforms/standalone_winforms/test.py @@ -1,3 +1,2 @@ -from create_database_utils import * - -run_codeql_database_create(lang="csharp", extra_args=["--build-mode=none"]) +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/legacy b/csharp/ql/integration-tests/legacy deleted file mode 100644 index 52478f0a7ef..00000000000 --- a/csharp/ql/integration-tests/legacy +++ /dev/null @@ -1 +0,0 @@ -These tests are still run with the legacy test runner diff --git a/csharp/ql/integration-tests/linux-only/compiler_args/test.py b/csharp/ql/integration-tests/linux-only/compiler_args/test.py index 89c7dbf7113..2ba04abcd08 100644 --- a/csharp/ql/integration-tests/linux-only/compiler_args/test.py +++ b/csharp/ql/integration-tests/linux-only/compiler_args/test.py @@ -1,3 +1,6 @@ -from create_database_utils import * +import runs_on -run_codeql_database_create([], lang="csharp") + +@runs_on.linux +def test(codeql, csharp): + codeql.database.create() diff --git a/csharp/ql/integration-tests/linux-only/standalone_dependencies_non_utf8_filename/test.py b/csharp/ql/integration-tests/linux-only/standalone_dependencies_non_utf8_filename/test.py index c372671b20b..8759c484a0f 100644 --- a/csharp/ql/integration-tests/linux-only/standalone_dependencies_non_utf8_filename/test.py +++ b/csharp/ql/integration-tests/linux-only/standalone_dependencies_non_utf8_filename/test.py @@ -1,8 +1,10 @@ -from create_database_utils import * +import runs_on -path = b'\xd2abcd.cs' -with open(path, 'w') as file: - file.write('class X { }\n') +@runs_on.linux +def test(codeql, csharp): + path = b"\xd2abcd.cs" -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) + with open(path, "w") as file: + file.write("class X { }\n") + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/diag_autobuild_script/test.py b/csharp/ql/integration-tests/posix-only/diag_autobuild_script/test.py index 62c4d3934a4..f6a940c18c1 100644 --- a/csharp/ql/integration-tests/posix-only/diag_autobuild_script/test.py +++ b/csharp/ql/integration-tests/posix-only/diag_autobuild_script/test.py @@ -1,5 +1,6 @@ -from create_database_utils import * -from diagnostics_test_utils import * +import runs_on -run_codeql_database_create([], db=None, lang="csharp", runFunction=runUnsuccessfully) -check_diagnostics() + +@runs_on.posix +def test(codeql, csharp): + codeql.database.create(_assert_failure=True) diff --git a/csharp/ql/integration-tests/posix-only/diag_multiple_scripts/test.py b/csharp/ql/integration-tests/posix-only/diag_multiple_scripts/test.py index 62c4d3934a4..f6a940c18c1 100644 --- a/csharp/ql/integration-tests/posix-only/diag_multiple_scripts/test.py +++ b/csharp/ql/integration-tests/posix-only/diag_multiple_scripts/test.py @@ -1,5 +1,6 @@ -from create_database_utils import * -from diagnostics_test_utils import * +import runs_on -run_codeql_database_create([], db=None, lang="csharp", runFunction=runUnsuccessfully) -check_diagnostics() + +@runs_on.posix +def test(codeql, csharp): + codeql.database.create(_assert_failure=True) diff --git a/csharp/ql/integration-tests/posix-only/dotnet_test/diagnostics.expected b/csharp/ql/integration-tests/posix-only/dotnet_test/diagnostics.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/csharp/ql/integration-tests/posix-only/dotnet_test/test.py b/csharp/ql/integration-tests/posix-only/dotnet_test/test.py index 179b7901956..6417f6a1797 100644 --- a/csharp/ql/integration-tests/posix-only/dotnet_test/test.py +++ b/csharp/ql/integration-tests/posix-only/dotnet_test/test.py @@ -1,15 +1,19 @@ -from create_database_utils import * -from diagnostics_test_utils import * +import runs_on -# 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") +@runs_on.posix +def test_implicit_build_then_run(codeql, csharp): + codeql.database.create(command="dotnet test") + + +@runs_on.posix +def test_explicit_build_then_run(codeql, csharp): + codeql.database.create(command=["dotnet build -o myout", "dotnet test myout/dotnet_test.dll"]) + -thisDir = os.path.abspath(os.getcwd()) # Explicit build and then run tests using the absolute path. -run_codeql_database_create(['dotnet clean', 'rm -rf test2-db', 'dotnet build -o myout', f'dotnet test {thisDir}/myout/dotnet_test.dll'], test_db="test3-db", lang="csharp") -check_diagnostics(test_db="test3-db") \ No newline at end of file +@runs_on.posix +def test_explicit_build_then_run_abs_path(codeql, csharp, cwd): + codeql.database.create( + command=["dotnet build -o myout", f"dotnet test {cwd}/myout/dotnet_test.dll"] + ) diff --git a/csharp/ql/integration-tests/posix-only/dotnet_test_mstest/diagnostics.expected b/csharp/ql/integration-tests/posix-only/dotnet_test_mstest/diagnostics.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/csharp/ql/integration-tests/posix-only/dotnet_test_mstest/test.py b/csharp/ql/integration-tests/posix-only/dotnet_test_mstest/test.py index ff14366807d..e59a23edb60 100644 --- a/csharp/ql/integration-tests/posix-only/dotnet_test_mstest/test.py +++ b/csharp/ql/integration-tests/posix-only/dotnet_test_mstest/test.py @@ -1,14 +1,19 @@ -import platform -from create_database_utils import * -from diagnostics_test_utils import * +import runs_on -# Implicitly build and then run tests. -run_codeql_database_create(['dotnet test'], test_db="test-db", lang="csharp") -check_diagnostics() -# Fix `dotnet test` picking `x64` on arm-based macOS -architecture = '-a arm64' if platform.machine() == 'arm64' else '' +@runs_on.posix +def test_implicit_build_and_test(codeql, csharp): + codeql.database.create(command="dotnet test") + # 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 ' + architecture], test_db="test2-db", lang="csharp") -check_diagnostics(test_db="test2-db") +@runs_on.posix +def test_explicit_build_and_test(codeql, csharp): + # Fix `dotnet test` picking `x64` on arm-based macOS + architecture = "-a arm64" if runs_on.arm64 else "" + codeql.database.create( + command=[ + "dotnet build -o myout --os win", + f"dotnet test myout/dotnet_test_mstest.exe {architecture}", + ] + ) diff --git a/csharp/ql/integration-tests/posix-only/inherit-env-vars/diagnostics.expected b/csharp/ql/integration-tests/posix-only/inherit-env-vars/diagnostics.expected new file mode 100644 index 00000000000..e69de29bb2d diff --git a/csharp/ql/integration-tests/posix-only/inherit-env-vars/test.py b/csharp/ql/integration-tests/posix-only/inherit-env-vars/test.py index 92d90e53ec5..31e31c8565d 100644 --- a/csharp/ql/integration-tests/posix-only/inherit-env-vars/test.py +++ b/csharp/ql/integration-tests/posix-only/inherit-env-vars/test.py @@ -1,8 +1,8 @@ -from create_database_utils import * -from diagnostics_test_utils import * import os +import runs_on -os.environ["PROJECT_TO_BUILD"] = "proj.csproj.no_auto" -run_codeql_database_create([], db=None, lang="csharp") -check_diagnostics() +@runs_on.posix +def test(codeql, csharp): + os.environ["PROJECT_TO_BUILD"] = "proj.csproj.no_auto" + codeql.database.create() diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies/test.py index a17966e148a..5aaafca6a46 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies/test.py @@ -1,3 +1,6 @@ -from create_database_utils import * +import runs_on -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) + +@runs_on.posix +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_executing_runtime/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies_executing_runtime/test.py index a17966e148a..5aaafca6a46 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_executing_runtime/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies_executing_runtime/test.py @@ -1,3 +1,6 @@ -from create_database_utils import * +import runs_on -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) + +@runs_on.posix +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_multi_project/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies_multi_project/test.py index a17966e148a..5aaafca6a46 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_multi_project/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies_multi_project/test.py @@ -1,3 +1,6 @@ -from create_database_utils import * +import runs_on -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) + +@runs_on.posix +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_multi_target/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies_multi_target/test.py index a17966e148a..5aaafca6a46 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_multi_target/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies_multi_target/test.py @@ -1,3 +1,6 @@ -from create_database_utils import * +import runs_on -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) + +@runs_on.posix +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_no_framework/skip-on-platform-osx-arm b/csharp/ql/integration-tests/posix-only/standalone_dependencies_no_framework/skip-on-platform-osx-arm deleted file mode 100644 index 6ebb8d63fcc..00000000000 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_no_framework/skip-on-platform-osx-arm +++ /dev/null @@ -1 +0,0 @@ -Skipping the test on the ARM runners, as we're running into trouble with Mono and nuget. diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_no_framework/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies_no_framework/test.py index 277f7d92160..4d5c7b24bc9 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_no_framework/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies_no_framework/test.py @@ -1,5 +1,12 @@ -from create_database_utils import * +import runs_on +import pytest import os -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_DOTNET_FRAMEWORK_REFERENCES"] = "/non-existent-path" -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) + +# Skipping the test on the ARM runners, as we're running into trouble with Mono and nuget. +@pytest.mark.only_if(runs_on.linux or (runs_on.macos and runs_on.x86_64)) +def test(codeql, csharp): + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_DOTNET_FRAMEWORK_REFERENCES"] = ( + "/non-existent-path" + ) + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget with_space/skip-on-platform-osx-arm b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget with_space/skip-on-platform-osx-arm deleted file mode 100644 index 6ebb8d63fcc..00000000000 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget with_space/skip-on-platform-osx-arm +++ /dev/null @@ -1 +0,0 @@ -Skipping the test on the ARM runners, as we're running into trouble with Mono and nuget. diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget with_space/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget with_space/test.py index a8429653cea..5bfcb3bfd1c 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget with_space/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget with_space/test.py @@ -1,8 +1,12 @@ -from create_database_utils import * import os +import runs_on +import pytest -# making sure we're not doing any fallback restore: -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_TIMEOUT"] = "1" -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_LIMIT"] = "1" -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) +# Skipping the test on the ARM runners, as we're running into trouble with Mono and nuget. +@pytest.mark.only_if(runs_on.linux or (runs_on.macos and runs_on.x86_64)) +def test(codeql, csharp): + # making sure we're not doing any fallback restore: + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_TIMEOUT"] = "1" + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_LIMIT"] = "1" + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget/skip-on-platform-osx-arm b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget/skip-on-platform-osx-arm deleted file mode 100644 index 6ebb8d63fcc..00000000000 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget/skip-on-platform-osx-arm +++ /dev/null @@ -1 +0,0 @@ -Skipping the test on the ARM runners, as we're running into trouble with Mono and nuget. diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget/test.py index a17966e148a..c7728b64d2a 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget/test.py @@ -1,3 +1,8 @@ -from create_database_utils import * +import runs_on +import pytest -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) + +# Skipping the test on the ARM runners, as we're running into trouble with Mono and nuget. +@pytest.mark.only_if(runs_on.linux or (runs_on.macos and runs_on.x86_64)) +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_error/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_error/test.py index a17966e148a..5aaafca6a46 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_error/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_error/test.py @@ -1,3 +1,6 @@ -from create_database_utils import * +import runs_on -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) + +@runs_on.posix +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_error_timeout/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_error_timeout/test.py index 7345609d4d6..f94325769a1 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_error_timeout/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_error_timeout/test.py @@ -1,17 +1,26 @@ -from create_database_utils import * -from diagnostics_test_utils import * import os +import runs_on -# os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK"] = "true" # Nuget feed check is enabled by default -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_TIMEOUT"] = "1" # 1ms, the GET request should fail with such short timeout -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_LIMIT"] = "1" # Limit the count of checks to 1 -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_EXCLUDED"] = "https://abc.de:8000/packages/" # Exclude this feed from check -# Making sure the reachability test of `nuget.org` succeeds: -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_TIMEOUT"] = "1000" -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_LIMIT"] = "5" -# The second feed is ignored in the fallback restore, because of network issues: -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_FALLBACK"] = "https://api.nuget.org/v3/index.json https://abc.def:8000/packages/" +@runs_on.posix +def test(codeql, csharp): + # os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK"] = "true" # Nuget feed check is enabled by default + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_TIMEOUT"] = ( + "1" # 1ms, the GET request should fail with such short timeout + ) + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_LIMIT"] = ( + "1" # Limit the count of checks to 1 + ) + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_EXCLUDED"] = ( + "https://abc.de:8000/packages/" # Exclude this feed from check + ) -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) -check_diagnostics() \ No newline at end of file + # Making sure the reachability test of `nuget.org` succeeds: + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_TIMEOUT"] = "1000" + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_LIMIT"] = "5" + # The second feed is ignored in the fallback restore, because of network issues: + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_FALLBACK"] = ( + "https://api.nuget.org/v3/index.json https://abc.def:8000/packages/" + ) + + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_fallback/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_fallback/test.py index 630dbfc06d4..7f4bf019d00 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_fallback/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_config_fallback/test.py @@ -1,14 +1,20 @@ -from create_database_utils import * -from diagnostics_test_utils import * import os +import runs_on -# os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK"] = "true" # Nuget feed check is enabled by default -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_TIMEOUT"] = "1" # 1ms, the GET request should fail with such short timeout -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_LIMIT"] = "1" # Limit the count of checks to 1 -# Making sure the reachability test succeeds when doing a fallback restore: -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_TIMEOUT"] = "1000" -os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_LIMIT"] = "5" +@runs_on.posix +def test(codeql, csharp): -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) -check_diagnostics() \ No newline at end of file + # os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK"] = "true" # Nuget feed check is enabled by default + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_TIMEOUT"] = ( + "1" # 1ms, the GET request should fail with such short timeout + ) + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_LIMIT"] = ( + "1" # Limit the count of checks to 1 + ) + + # Making sure the reachability test succeeds when doing a fallback restore: + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_TIMEOUT"] = "1000" + os.environ["CODEQL_EXTRACTOR_CSHARP_BUILDLESS_NUGET_FEEDS_CHECK_FALLBACK_LIMIT"] = "5" + + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_no_sources/skip-on-platform-osx-arm b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_no_sources/skip-on-platform-osx-arm deleted file mode 100644 index 6ebb8d63fcc..00000000000 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_no_sources/skip-on-platform-osx-arm +++ /dev/null @@ -1 +0,0 @@ -Skipping the test on the ARM runners, as we're running into trouble with Mono and nuget. diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_no_sources/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_no_sources/test.py index ff2e3ba7d3b..a6a6123f019 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_no_sources/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_no_sources/test.py @@ -1,3 +1,8 @@ -from create_database_utils import * +import runs_on +import pytest -run_codeql_database_create([], source="proj", lang="csharp", extra_args=["--build-mode=none"]) + +# Skipping the test on the ARM runners, as we're running into trouble with Mono and nuget. +@pytest.mark.only_if(runs_on.linux or (runs_on.macos and runs_on.x86_64)) +def test(codeql, csharp): + codeql.database.create(source_root="proj", build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_versions/test.py b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_versions/test.py index a17966e148a..5aaafca6a46 100644 --- a/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_versions/test.py +++ b/csharp/ql/integration-tests/posix-only/standalone_dependencies_nuget_versions/test.py @@ -1,3 +1,6 @@ -from create_database_utils import * +import runs_on -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) + +@runs_on.posix +def test(codeql, csharp): + codeql.database.create(build_mode="none") diff --git a/csharp/ql/integration-tests/posix-only/warn_as_error/test.py b/csharp/ql/integration-tests/posix-only/warn_as_error/test.py index 60f5c6422b7..1b7bbd05123 100644 --- a/csharp/ql/integration-tests/posix-only/warn_as_error/test.py +++ b/csharp/ql/integration-tests/posix-only/warn_as_error/test.py @@ -1,7 +1,6 @@ -import os -from create_database_utils import * -from diagnostics_test_utils import * +import runs_on -run_codeql_database_create(["./build.sh"], lang="csharp") -check_diagnostics() +@runs_on.posix +def test(codeql, csharp): + codeql.database.create(command="./build.sh") diff --git a/csharp/ql/integration-tests/qlpack.yml b/csharp/ql/integration-tests/qlpack.yml deleted file mode 100644 index e66c1239b04..00000000000 --- a/csharp/ql/integration-tests/qlpack.yml +++ /dev/null @@ -1,3 +0,0 @@ -dependencies: - codeql/csharp-all: '*' -warnOnImplicitThis: true diff --git a/csharp/ql/integration-tests/windows-only/diag_autobuild_script/test.py b/csharp/ql/integration-tests/windows-only/diag_autobuild_script/test.py index 62c4d3934a4..2b7ad751411 100644 --- a/csharp/ql/integration-tests/windows-only/diag_autobuild_script/test.py +++ b/csharp/ql/integration-tests/windows-only/diag_autobuild_script/test.py @@ -1,5 +1,6 @@ -from create_database_utils import * -from diagnostics_test_utils import * +import runs_on -run_codeql_database_create([], db=None, lang="csharp", runFunction=runUnsuccessfully) -check_diagnostics() + +@runs_on.windows +def test(codeql, csharp): + codeql.database.create(_assert_failure=True) diff --git a/csharp/ql/integration-tests/windows-only/diag_multiple_scripts/test.py b/csharp/ql/integration-tests/windows-only/diag_multiple_scripts/test.py index 62c4d3934a4..2b7ad751411 100644 --- a/csharp/ql/integration-tests/windows-only/diag_multiple_scripts/test.py +++ b/csharp/ql/integration-tests/windows-only/diag_multiple_scripts/test.py @@ -1,5 +1,6 @@ -from create_database_utils import * -from diagnostics_test_utils import * +import runs_on -run_codeql_database_create([], db=None, lang="csharp", runFunction=runUnsuccessfully) -check_diagnostics() + +@runs_on.windows +def test(codeql, csharp): + codeql.database.create(_assert_failure=True) diff --git a/csharp/ql/integration-tests/windows-only/standalone_dependencies/test.py b/csharp/ql/integration-tests/windows-only/standalone_dependencies/test.py index a17966e148a..0c100a0bc2f 100644 --- a/csharp/ql/integration-tests/windows-only/standalone_dependencies/test.py +++ b/csharp/ql/integration-tests/windows-only/standalone_dependencies/test.py @@ -1,3 +1,6 @@ -from create_database_utils import * +import runs_on -run_codeql_database_create([], lang="csharp", extra_args=["--build-mode=none"]) + +@runs_on.windows +def test(codeql, csharp): + codeql.database.create(build_mode="none") From 67331fb8100f43a7924f2e290ab44bfe2b8ba286 Mon Sep 17 00:00:00 2001 From: Cornelius Riemenschneider Date: Wed, 7 Aug 2024 12:32:11 +0200 Subject: [PATCH 2/3] Accept test output changes. These test expectations change, as the test is now run in a temp directory that's not located in our checkout. Previously, `dotnet build` was picking up files from the repository, like the editor config and the sourcelink (which requires a git repository in a parent directory). --- .../compiler_args/CompilerArgs.expected | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/csharp/ql/integration-tests/linux-only/compiler_args/CompilerArgs.expected b/csharp/ql/integration-tests/linux-only/compiler_args/CompilerArgs.expected index 888a4be5409..a2f04cfb759 100644 --- a/csharp/ql/integration-tests/linux-only/compiler_args/CompilerArgs.expected +++ b/csharp/ql/integration-tests/linux-only/compiler_args/CompilerArgs.expected @@ -183,25 +183,19 @@ | 182 | /warnaserror- | | 183 | /utf8output | | 184 | /deterministic+ | -| 185 | /sourcelink:obj/Debug/net8.0/test.sourcelink.json | -| 186 | /langversion:12.0 | -| 187 | /embed:Program.cs | -| 188 | /embed:obj/Debug/net8.0/test.GlobalUsings.g.cs | -| 189 | /embed:"obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs" | -| 190 | /embed:obj/Debug/net8.0/test.AssemblyInfo.cs | -| 191 | /analyzerconfig:/home/runner/work/semmle-code/semmle-code/.editorconfig | -| 192 | /analyzerconfig:obj/Debug/net8.0/test.GeneratedMSBuildEditorConfig.editorconfig | -| 193 | /analyzerconfig:[...]/8.0.101/Sdks/Microsoft.NET.Sdk/analyzers/build/config/analysislevel_8_default.globalconfig | -| 194 | /analyzer:[...]/8.0.101/Sdks/Microsoft.NET.Sdk/targets/../analyzers/Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll | -| 195 | /analyzer:[...]/8.0.101/Sdks/Microsoft.NET.Sdk/targets/../analyzers/Microsoft.CodeAnalysis.NetAnalyzers.dll | -| 196 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/Microsoft.Interop.ComInterfaceGenerator.dll | -| 197 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/Microsoft.Interop.JavaScript.JSImportGenerator.dll | -| 198 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/Microsoft.Interop.LibraryImportGenerator.dll | -| 199 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/Microsoft.Interop.SourceGeneration.dll | -| 200 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/System.Text.Json.SourceGeneration.dll | -| 201 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/System.Text.RegularExpressions.Generator.dll | -| 202 | Program.cs | -| 203 | obj/Debug/net8.0/test.GlobalUsings.g.cs | -| 204 | obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs | -| 205 | obj/Debug/net8.0/test.AssemblyInfo.cs | -| 206 | /warnaserror+:NU1605,SYSLIB0011 | +| 185 | /langversion:12.0 | +| 186 | /analyzerconfig:obj/Debug/net8.0/test.GeneratedMSBuildEditorConfig.editorconfig | +| 187 | /analyzerconfig:[...]/8.0.101/Sdks/Microsoft.NET.Sdk/analyzers/build/config/analysislevel_8_default.globalconfig | +| 188 | /analyzer:[...]/8.0.101/Sdks/Microsoft.NET.Sdk/targets/../analyzers/Microsoft.CodeAnalysis.CSharp.NetAnalyzers.dll | +| 189 | /analyzer:[...]/8.0.101/Sdks/Microsoft.NET.Sdk/targets/../analyzers/Microsoft.CodeAnalysis.NetAnalyzers.dll | +| 190 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/Microsoft.Interop.ComInterfaceGenerator.dll | +| 191 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/Microsoft.Interop.JavaScript.JSImportGenerator.dll | +| 192 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/Microsoft.Interop.LibraryImportGenerator.dll | +| 193 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/Microsoft.Interop.SourceGeneration.dll | +| 194 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/System.Text.Json.SourceGeneration.dll | +| 195 | /analyzer:[...]/8.0.1/analyzers/dotnet/cs/System.Text.RegularExpressions.Generator.dll | +| 196 | Program.cs | +| 197 | obj/Debug/net8.0/test.GlobalUsings.g.cs | +| 198 | obj/Debug/net8.0/.NETCoreApp,Version=v8.0.AssemblyAttributes.cs | +| 199 | obj/Debug/net8.0/test.AssemblyInfo.cs | +| 200 | /warnaserror+:NU1605,SYSLIB0011 | From 16e19a6b04930aeb33c830efe342476aa4ea59fc Mon Sep 17 00:00:00 2001 From: Cornelius Riemenschneider Date: Wed, 7 Aug 2024 18:43:41 +0200 Subject: [PATCH 3/3] Port missing test. --- .../all-platforms/conditional_compilation/test.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/csharp/ql/integration-tests/all-platforms/conditional_compilation/test.py b/csharp/ql/integration-tests/all-platforms/conditional_compilation/test.py index 73ab1ec712f..bf69f536b65 100644 --- a/csharp/ql/integration-tests/all-platforms/conditional_compilation/test.py +++ b/csharp/ql/integration-tests/all-platforms/conditional_compilation/test.py @@ -1,6 +1,8 @@ -from create_database_utils import * import os -os.environ["CODEQL_EXTRACTOR_CSHARP_OPTION_TRAP_COMPRESSION"] = "none" -run_codeql_database_create(['dotnet build /p:DefineConstants=A', 'dotnet build /p:DefineConstants=B'], lang="csharp") +def test(codeql, csharp): + os.environ["CODEQL_EXTRACTOR_CSHARP_OPTION_TRAP_COMPRESSION"] = "none" + codeql.database.create( + command=["dotnet build /p:DefineConstants=A", "dotnet build /p:DefineConstants=B"] + )