Skip to content

Commit c1ee51a

Browse files
Evangelinknohwnd
andauthored
Cherry-pick "Remove chutzpah (#4249)" (#4282)
Co-authored-by: Jakub Jareš <me@jakubjares.com>
1 parent e0cf151 commit c1ee51a

File tree

8 files changed

+113
-21
lines changed

8 files changed

+113
-21
lines changed

scripts/build/TestPlatform.Dependencies.props

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
<NUnit3AdapterVersion>3.11.0</NUnit3AdapterVersion>
2828
<NUnitConsoleRunnerVersion>3.8.0</NUnitConsoleRunnerVersion>
2929

30-
<ChutzpahAdapterVersion>4.4.13</ChutzpahAdapterVersion>
3130
<FluentAssertionsVersion>6.7.0</FluentAssertionsVersion>
3231

3332
<!-- Versions that are used when building projects from TestAssets.sln for compatibility tests. See Invoke-TestAssetsBuild in scripts/build.ps1.

test/Microsoft.TestPlatform.AcceptanceTests/DifferentTestFrameworkSimpleTests.cs

+8-3
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ public class DifferentTestFrameworkSimpleTests : AcceptanceTestBase
1616
{
1717
[TestMethod]
1818
[NetFullTargetFrameworkDataSource(inIsolation: true, inProcess: true)]
19-
public void ChutzpahRunAllTestExecution(RunnerInfo runnerInfo)
19+
public void NonDllRunAllTestExecution(RunnerInfo runnerInfo)
2020
{
21+
// This used to test Chutzpah, to prove that we can run tests that are not shipped in dlls.
22+
// But that framework is not fixing vulnerable dependencies for a long time, so we use our custom, test adapter
23+
// that simply returns 1 discovered test on discovery, and 1 passed test on execution.
24+
// We do not really test that we can run JavaScript tests, but we test that we can trigger tests that are not shipped
25+
// in a dll, and pick up the provided test adapter.
2126
SetTestEnvironment(_testEnvironment, runnerInfo);
2227
string fileName = "test.js";
2328
var testJSFileAbsolutePath = Path.Combine(_testEnvironment.TestAssetsPath, fileName);
2429
string tempPath = Path.Combine(TempDirectory.Path, fileName);
2530
File.Copy(testJSFileAbsolutePath, tempPath);
26-
var arguments = PrepareArguments(tempPath, GetTestAdapterPath(UnitTestFramework.Chutzpah), string.Empty, FrameworkArgValue, runnerInfo.InIsolationValue, resultsDirectory: TempDirectory.Path);
31+
var arguments = PrepareArguments(tempPath, GetTestAdapterPath(UnitTestFramework.NonDll), string.Empty, FrameworkArgValue, runnerInfo.InIsolationValue, resultsDirectory: TempDirectory.Path);
2732
InvokeVsTest(arguments);
28-
ValidateSummaryStatus(1, 1, 0);
33+
ValidateSummaryStatus(1, 0, 0);
2934
}
3035

3136
[TestMethod]

test/Microsoft.TestPlatform.AcceptanceTests/Microsoft.TestPlatform.AcceptanceTests.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
<ProjectReference Include="$(TestPlatformRoot)test\Microsoft.TestPlatform.TestUtilities\Microsoft.TestPlatform.TestUtilities.csproj" />
3232
</ItemGroup>
3333
<ItemGroup>
34-
<PackageReference Include="Chutzpah" Version="$(ChutzpahAdapterVersion)" />
3534
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionsVersion)" />
3635
<PackageReference Include="Microsoft.TestPlatform.TestAsset.NativeCPP" Version="2.0.0" />
3736
<PackageReference Include="Microsoft.TestPlatform.QTools.Assets" Version="2.0.0" />

test/Microsoft.TestPlatform.AcceptanceTests/TranslationLayerTests/DifferentTestFrameworkSimpleTests.cs

+7-10
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,18 @@ public void RunTestsWithXunitAdapter(RunnerInfo runnerInfo)
116116
[TestMethod]
117117
[TestCategory("Windows-Review")]
118118
[NetFullTargetFrameworkDataSource]
119-
public void RunTestsWithChutzpahAdapter(RunnerInfo runnerInfo)
119+
public void RunTestsWithNonDllAdapter(RunnerInfo runnerInfo)
120120
{
121+
// This used to be test for Chutzpah, but it has long running problem with updating dependencies,
122+
// so we test against our own test framework, to ensure that we can run test files that are not using
123+
// *.dll as extension.
121124
SetTestEnvironment(_testEnvironment, runnerInfo);
122125
Setup();
123126

124127
var jsSource = Path.Combine(_testEnvironment.TestAssetsPath, "test.js");
125-
126-
// Chuzpah adapter creates _Chutzpah temp files, to give data back from the runner.
127-
// But when cleaning up it deletes all the _Chutzpah files, not just the one it owns,
128-
// so when we run in parallel, the slower process will never find it's own file, because it was already deleted:
129-
// https://github.com/mmanela/chutzpah/issues/812
130128
var jsInTemp = TempDirectory.CopyFile(jsSource);
131129

132-
var testAdapterPath = Directory.EnumerateFiles(GetTestAdapterPath(UnitTestFramework.Chutzpah), "*.TestAdapter.dll").ToList();
130+
var testAdapterPath = Directory.EnumerateFiles(GetTestAdapterPath(UnitTestFramework.NonDll), "*.TestAdapter.dll").ToList();
133131
_vstestConsoleWrapper.InitializeExtensions(new List<string>() { testAdapterPath.First() });
134132

135133
_vstestConsoleWrapper.RunTests(
@@ -140,9 +138,8 @@ public void RunTestsWithChutzpahAdapter(RunnerInfo runnerInfo)
140138
var testCase = _runEventHandler.TestResults.Where(tr => tr.TestCase.DisplayName.Equals("TestMethod1"));
141139

142140
// Assert
143-
Assert.AreEqual(2, _runEventHandler.TestResults.Count);
141+
Assert.AreEqual(1, _runEventHandler.TestResults.Count);
144142
Assert.AreEqual(1, _runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Passed));
145-
Assert.AreEqual(1, _runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed));
146-
Assert.AreEqual(1, testCase.First().TestCase.LineNumber);
143+
Assert.AreEqual(0, _runEventHandler.TestResults.Count(t => t.Outcome == TestOutcome.Failed));
147144
}
148145
}

test/Microsoft.TestPlatform.TestUtilities/IntegrationTestBase.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ public class IntegrationTestBase
4848
private readonly string _testAdapterRelativePath = @"mstest.testadapter\{0}\build\_common".Replace('\\', Path.DirectorySeparatorChar);
4949
private readonly string _nUnitTestAdapterRelativePath = @"nunit3testadapter\{0}\build".Replace('\\', Path.DirectorySeparatorChar);
5050
private readonly string _xUnitTestAdapterRelativePath = @"xunit.runner.visualstudio\{0}\build\_common".Replace('\\', Path.DirectorySeparatorChar);
51-
private readonly string _chutzpahTestAdapterRelativePath = @"chutzpah\{0}\tools".Replace('\\', Path.DirectorySeparatorChar);
5251

5352
public enum UnitTestFramework
5453
{
55-
NUnit, XUnit, MSTest, CPP, Chutzpah
54+
NUnit, XUnit, MSTest, CPP, NonDll
5655
}
5756

5857
public IntegrationTestBase()
@@ -574,6 +573,12 @@ protected string GetProjectAssetFullPath(string projectName, string assetName)
574573

575574
protected string GetTestAdapterPath(UnitTestFramework testFramework = UnitTestFramework.MSTest)
576575
{
576+
if (testFramework == UnitTestFramework.NonDll)
577+
{
578+
var dllPath = _testEnvironment.GetTestAsset("NonDll.TestAdapter.dll", "netstandard2.0");
579+
return Path.GetDirectoryName(dllPath)!;
580+
}
581+
577582
string adapterRelativePath = string.Empty;
578583

579584
if (testFramework == UnitTestFramework.MSTest)
@@ -588,10 +593,6 @@ protected string GetTestAdapterPath(UnitTestFramework testFramework = UnitTestFr
588593
{
589594
adapterRelativePath = string.Format(CultureInfo.InvariantCulture, _xUnitTestAdapterRelativePath, IntegrationTestEnvironment.DependencyVersions["XUnitAdapterVersion"]);
590595
}
591-
else if (testFramework == UnitTestFramework.Chutzpah)
592-
{
593-
adapterRelativePath = string.Format(CultureInfo.InvariantCulture, _chutzpahTestAdapterRelativePath, IntegrationTestEnvironment.DependencyVersions["ChutzpahAdapterVersion"]);
594-
}
595596

596597
return _testEnvironment.GetNugetPackage(adapterRelativePath);
597598
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project Sdk="Microsoft.NET.Sdk">
3+
<!-- Imports Common TestAssets props. -->
4+
<Import Project="..\..\..\scripts\build\TestAssets.props" />
5+
6+
<PropertyGroup>
7+
<TargetFrameworks>netstandard2.0</TargetFrameworks>
8+
<LangVersion>latest</LangVersion>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\..\..\src\Microsoft.TestPlatform.ObjectModel\Microsoft.TestPlatform.ObjectModel.csproj" />
13+
</ItemGroup>
14+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
7+
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
8+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
9+
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
10+
11+
namespace NonDll.TestAdapter;
12+
[FileExtension(".js")]
13+
[DefaultExecutorUri(Uri)]
14+
[ExtensionUri(Uri)]
15+
public class TestAdapter : ITestExecutor, ITestDiscoverer
16+
{
17+
public const string Uri = "executor://nondll.testadapter";
18+
19+
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext,
20+
IMessageLogger logger, ITestCaseDiscoverySink discoverySink)
21+
{
22+
var count = 1;
23+
foreach (var source in sources)
24+
{
25+
TestCase testCase = new()
26+
{
27+
Source = source,
28+
CodeFilePath = source,
29+
DisplayName = $"Test{count++}",
30+
ExecutorUri = new Uri(Uri),
31+
};
32+
discoverySink.SendTestCase(testCase);
33+
}
34+
}
35+
36+
public void Cancel()
37+
{
38+
}
39+
40+
public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
41+
{
42+
foreach (var test in tests)
43+
{
44+
TestResult testResult = new(test)
45+
{
46+
Outcome = TestOutcome.Passed,
47+
};
48+
frameworkHandle.RecordResult(testResult);
49+
}
50+
}
51+
52+
public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
53+
{
54+
var count = 1;
55+
foreach (var source in sources)
56+
{
57+
TestCase testCase = new()
58+
{
59+
Source = source,
60+
CodeFilePath = source,
61+
DisplayName = $"Test{count++}",
62+
ExecutorUri = new Uri(Uri),
63+
};
64+
TestResult testResult = new(testCase)
65+
{
66+
Outcome = TestOutcome.Passed,
67+
};
68+
frameworkHandle.RecordResult(testResult);
69+
}
70+
}
71+
}

test/TestAssets/TestAssets.sln

+6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SerializeTestRunTestProject
130130
EndProject
131131
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiHostTestExecutionProject", "MultiHostTestExecutionProject\MultiHostTestExecutionProject.csproj", "{CE6673DA-B50F-46DF-99A3-8A7C54DE9B61}"
132132
EndProject
133+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NonDll.TestAdapter", "NonDll.TestAdapter\NonDll.TestAdapter.csproj", "{429552A4-4C18-4355-94C5-80DC88C48405}"
134+
EndProject
133135
Global
134136
GlobalSection(SolutionConfigurationPlatforms) = preSolution
135137
Debug|Any CPU = Debug|Any CPU
@@ -372,6 +374,10 @@ Global
372374
{CE6673DA-B50F-46DF-99A3-8A7C54DE9B61}.Debug|Any CPU.Build.0 = Debug|Any CPU
373375
{CE6673DA-B50F-46DF-99A3-8A7C54DE9B61}.Release|Any CPU.ActiveCfg = Release|Any CPU
374376
{CE6673DA-B50F-46DF-99A3-8A7C54DE9B61}.Release|Any CPU.Build.0 = Release|Any CPU
377+
{429552A4-4C18-4355-94C5-80DC88C48405}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
378+
{429552A4-4C18-4355-94C5-80DC88C48405}.Debug|Any CPU.Build.0 = Debug|Any CPU
379+
{429552A4-4C18-4355-94C5-80DC88C48405}.Release|Any CPU.ActiveCfg = Release|Any CPU
380+
{429552A4-4C18-4355-94C5-80DC88C48405}.Release|Any CPU.Build.0 = Release|Any CPU
375381
EndGlobalSection
376382
GlobalSection(SolutionProperties) = preSolution
377383
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)