Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GoogleTestAdapter/Core.Tests/GoogleTestExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void AssertDurationsFileIsCreated(bool parallelExecution)

var collectingReporter = new FakeFrameworkReporter();
var testExecutor = new GoogleTestExecutor(TestEnvironment.Logger, TestEnvironment.Options);
testExecutor.RunTests(TestDataCreator.AllTestCasesExceptLoadTests, TestDataCreator.AllTestCasesExceptLoadTests, collectingReporter, null, false, TestResources.SampleTestsSolutionDir, processExecutor);
testExecutor.RunTests(TestDataCreator.AllTestCasesExceptLoadTests, collectingReporter, null, false, TestResources.SampleTestsSolutionDir, processExecutor);

sampleTestsDurationsFile.AsFileInfo()
.Should()
Expand Down
88 changes: 50 additions & 38 deletions GoogleTestAdapter/Core.Tests/Runners/CommandLineGeneratorTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ public void RunTests_CancelingAndKillingProcessesDuringTestExecution_StopsTestEx
private void DoRunCancelingTests(bool killProcesses, int lower, int upper)
{
MockOptions.Setup(o => o.KillProcessesOnCancel).Returns(killProcesses);
List<TestCase> allTestCases = TestDataCreator.AllTestCasesExceptLoadTests;
List<TestCase> testCasesToRun = TestDataCreator.GetTestCases("Crashing.LongRunning", "LongRunningTests.Test2");

var stopwatch = new Stopwatch();
var runner = new SequentialTestRunner("", MockFrameworkReporter.Object, TestEnvironment.Logger, TestEnvironment.Options, new SchedulingAnalyzer(TestEnvironment.Logger));
var executor = new ProcessExecutor(null, MockLogger.Object);
var thread = new Thread(() => runner.RunTests(allTestCases, testCasesToRun, "", "", "", false, null, executor));
var thread = new Thread(() => runner.RunTests(testCasesToRun, "", "", "", false, null, executor));

stopwatch.Start();
thread.Start();
Expand Down
2 changes: 2 additions & 0 deletions GoogleTestAdapter/Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
<Compile Include="Helpers\ProcessLauncher.cs" />
<Compile Include="Helpers\TestProcessLauncher.cs" />
<Compile Include="Helpers\RegexTraitParser.cs" />
<Compile Include="Model\TestCaseMetaDataProperty.cs" />
<Compile Include="Model\TestProperty.cs" />
<Compile Include="Scheduling\SchedulingAnalyzer.cs" />
<Compile Include="Settings\IGoogleTestAdapterSettingsContainer.cs" />
<Compile Include="Settings\RunSettings.cs" />
Expand Down
4 changes: 2 additions & 2 deletions GoogleTestAdapter/Core/GoogleTestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public GoogleTestExecutor(ILogger logger, SettingsWrapper settings)
}


public void RunTests(IEnumerable<TestCase> allTestCasesInExecutables, IEnumerable<TestCase> testCasesToRun, ITestFrameworkReporter reporter, IDebuggedProcessLauncher launcher, bool isBeingDebugged, string solutionDirectory, IProcessExecutor executor)
public void RunTests(IEnumerable<TestCase> testCasesToRun, ITestFrameworkReporter reporter, IDebuggedProcessLauncher launcher, bool isBeingDebugged, string solutionDirectory, IProcessExecutor executor)
{
TestCase[] testCasesToRunAsArray = testCasesToRun as TestCase[] ?? testCasesToRun.ToArray();
_logger.LogInfo("Running " + testCasesToRunAsArray.Length + " tests...");
Expand All @@ -42,7 +42,7 @@ public void RunTests(IEnumerable<TestCase> allTestCasesInExecutables, IEnumerabl
ComputeTestRunner(reporter, isBeingDebugged, solutionDirectory);
}

_runner.RunTests(allTestCasesInExecutables, testCasesToRunAsArray, solutionDirectory, null, null, isBeingDebugged, launcher, executor);
_runner.RunTests(testCasesToRunAsArray, solutionDirectory, null, null, isBeingDebugged, launcher, executor);

if (_settings.ParallelTestExecution)
_schedulingAnalyzer.PrintStatisticsToDebugOutput();
Expand Down
1 change: 1 addition & 0 deletions GoogleTestAdapter/Core/Model/TestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class TestCase
public int LineNumber { get; }

public List<Trait> Traits { get; } = new List<Trait>();
public List<TestProperty> Properties { get; } = new List<TestProperty>();

public TestCase(string fullyQualifiedName, string source, string displayName, string codeFilePath, int lineNumber)
{
Expand Down
28 changes: 28 additions & 0 deletions GoogleTestAdapter/Core/Model/TestCaseMetaDataProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Linq;

namespace GoogleTestAdapter.Model
{
public class TestCaseMetaDataProperty : TestProperty
{
public static readonly string Id = $"{typeof(TestCaseMetaDataProperty).FullName}";
public const string Label = "Test case meta data";

public int NrOfTestCasesInSuite { get; }
public int NrOfTestCasesInExecutable { get; }

public TestCaseMetaDataProperty(int nrOfTestCasesInSuite, int nrOfTestCasesInExecutable)
: this($"{nrOfTestCasesInSuite}:{nrOfTestCasesInExecutable}")
{
}

public TestCaseMetaDataProperty(string serialization) : base(serialization)
{
int[] values = serialization.Split(':').Select(int.Parse).ToArray();
if (values.Length != 2)
throw new ArgumentException(serialization, nameof(serialization));
NrOfTestCasesInSuite = values[0];
NrOfTestCasesInExecutable = values[1];
}
}
}
35 changes: 35 additions & 0 deletions GoogleTestAdapter/Core/Model/TestProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace GoogleTestAdapter.Model
{
public abstract class TestProperty
{
public string Serialization { get; }

protected TestProperty(string serialization)
{
Serialization = serialization;
}

public override string ToString()
{
return $"{GetType()}: {Serialization}";
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
return false;
if (ReferenceEquals(this, obj))
return true;
if (obj.GetType() != GetType())
return false;

var other = (TestProperty) obj;
return string.Equals(Serialization, other.Serialization);
}

public override int GetHashCode()
{
return Serialization != null ? Serialization.GetHashCode() : 0;
}
}
}
41 changes: 24 additions & 17 deletions GoogleTestAdapter/Core/Runners/CommandLineGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class CommandLineGenerator
{
public class Args
{
public List<TestCase> TestCases { get; }
public IList<TestCase> TestCases { get; }
public string CommandLine { get; }

internal Args(List<TestCase> testCases, string commandLine)
internal Args(IList<TestCase> testCases, string commandLine)
{
TestCases = testCases ?? new List<TestCase>();
CommandLine = commandLine ?? "";
Expand All @@ -26,23 +26,20 @@ internal Args(List<TestCase> testCases, string commandLine)
public const int MaxCommandLength = 8191;

private readonly int _lengthOfExecutableString;
private readonly IEnumerable<TestCase> _allTestCases;
private readonly IEnumerable<TestCase> _testCasesToRun;
private readonly IList<TestCase> _testCasesToRun;
private readonly string _resultXmlFile;
private readonly SettingsWrapper _settings;
private readonly string _userParameters;

public CommandLineGenerator(
IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun,
public CommandLineGenerator(IEnumerable<TestCase> testCasesToRun,
int lengthOfExecutableString, string userParameters, string resultXmlFile,
SettingsWrapper settings)
{
if (userParameters == null)
throw new ArgumentNullException(nameof(userParameters));

_lengthOfExecutableString = lengthOfExecutableString;
_allTestCases = allTestCases;
_testCasesToRun = testCasesToRun;
_testCasesToRun = testCasesToRun.ToList();
_resultXmlFile = resultXmlFile;
_settings = settings;
_userParameters = userParameters;
Expand All @@ -68,7 +65,7 @@ private IEnumerable<Args> GetFinalCommandLines(string baseCommandLine)
string userParam = GetAdditionalUserParameter();
if (AllTestCasesOfExecutableAreRun())
{
commandLines.Add(new Args(_testCasesToRun.ToList(), baseCommandLine + userParam));
commandLines.Add(new Args(_testCasesToRun, baseCommandLine + userParam));
return commandLines;
}

Expand All @@ -81,7 +78,7 @@ private IEnumerable<Args> GetFinalCommandLines(string baseCommandLine)
List<TestCase> testCasesRunBySuite = _testCasesToRun.Where(tc => !testCasesNotRunBySuite.Contains(tc)).ToList();
if (testCasesNotRunBySuite.Count == 0)
{
commandLines.Add(new Args(_testCasesToRun.ToList(), baseCommandLineWithFilter + userParam));
commandLines.Add(new Args(_testCasesToRun, baseCommandLineWithFilter + userParam));
return commandLines;
}

Expand Down Expand Up @@ -199,9 +196,16 @@ private string GetFilterForSuitesRunningAllTests(List<string> suitesRunningAllTe

private bool AllTestCasesOfExecutableAreRun()
{
var allTestCasesAsSet = new HashSet<TestCase>(_allTestCases);
var testCasesToRunAsSet = new HashSet<TestCase>(_testCasesToRun);
return allTestCasesAsSet.SetEquals(testCasesToRunAsSet);
if (!_testCasesToRun.Any())
return true;

TestCaseMetaDataProperty metaData = _testCasesToRun.First().Properties
.OfType<TestCaseMetaDataProperty>()
.SingleOrDefault();
if (metaData == null)
throw new Exception($"Test does not have meta data: {_testCasesToRun.First()}");

return _testCasesToRun.Count == metaData.NrOfTestCasesInExecutable;
}

private List<TestCase> GetTestCasesNotRunBySuite(List<string> suitesRunningAllTests)
Expand All @@ -226,11 +230,14 @@ private List<string> GetSuitesRunningAllTests()
foreach (string suite in GetAllSuitesOfTestCasesToRun())
{
List<TestCase> allMatchingTestCasesToBeRun = GetAllMatchingTestCases(_testCasesToRun, suite);
List<TestCase> allMatchingTestCases = GetAllMatchingTestCases(_allTestCases, suite);
if (allMatchingTestCasesToBeRun.Count == allMatchingTestCases.Count)
{
TestCaseMetaDataProperty metaData = allMatchingTestCasesToBeRun.First().Properties
.OfType<TestCaseMetaDataProperty>()
.SingleOrDefault();
if (metaData == null)
throw new Exception($"Test does not have meta data: {allMatchingTestCasesToBeRun.First()}");

if (allMatchingTestCasesToBeRun.Count == metaData.NrOfTestCasesInSuite)
suitesRunningAllTests.Add(suite);
}
}
return suitesRunningAllTests;
}
Expand Down
2 changes: 1 addition & 1 deletion GoogleTestAdapter/Core/Runners/ITestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace GoogleTestAdapter.Runners
public interface ITestRunner
{
// TODO remove isBeingDebugged parameter (use debuggedLauncher != null)
void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, string baseDir, string workingDir,
void RunTests(IEnumerable<TestCase> testCasesToRun, string baseDir, string workingDir,
string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor);

void Cancel();
Expand Down
8 changes: 4 additions & 4 deletions GoogleTestAdapter/Core/Runners/ParallelTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public ParallelTestRunner(ITestFrameworkReporter reporter, ILogger logger, Setti
}


public void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, string baseDir,
public void RunTests(IEnumerable<TestCase> testCasesToRun, string baseDir,
string workingDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
{
List<Thread> threads;
Expand All @@ -40,7 +40,7 @@ public void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> t
DebugUtils.AssertIsNull(userParameters, nameof(userParameters));

threads = new List<Thread>();
RunTests(allTestCases, testCasesToRun, baseDir, threads, isBeingDebugged, debuggedLauncher, executor);
RunTests(testCasesToRun, baseDir, threads, isBeingDebugged, debuggedLauncher, executor);
}

foreach (Thread thread in threads)
Expand All @@ -61,7 +61,7 @@ public void Cancel()
}


private void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, string baseDir, List<Thread> threads, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
private void RunTests(IEnumerable<TestCase> testCasesToRun, string baseDir, List<Thread> threads, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
{
TestCase[] testCasesToRunAsArray = testCasesToRun as TestCase[] ?? testCasesToRun.ToArray();

Expand All @@ -78,7 +78,7 @@ private void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase>
_testRunners.Add(runner);

var thread = new Thread(
() => runner.RunTests(allTestCases, testcases, baseDir, null, null, isBeingDebugged, debuggedLauncher, executor)){ Name = $"GTA Testrunner {threadId}" };
() => runner.RunTests(testcases, baseDir, null, null, isBeingDebugged, debuggedLauncher, executor)){ Name = $"GTA Testrunner {threadId}" };
threads.Add(thread);

thread.Start();
Expand Down
4 changes: 2 additions & 2 deletions GoogleTestAdapter/Core/Runners/PreparingTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PreparingTestRunner(string solutionDirectory, ITestFrameworkReporter repo
}


public void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, string baseDir,
public void RunTests(IEnumerable<TestCase> testCasesToRun, string baseDir,
string workingDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
{
DebugUtils.AssertIsNull(userParameters, nameof(userParameters));
Expand All @@ -59,7 +59,7 @@ public void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> t
batch = batch == "" ? "" : _solutionDirectory + batch;
SafeRunBatch(TestSetup, _solutionDirectory, batch, isBeingDebugged);

_innerTestRunner.RunTests(allTestCases, testCasesToRun, baseDir, workingDir, userParameters, isBeingDebugged, debuggedLauncher, executor);
_innerTestRunner.RunTests(testCasesToRun, baseDir, workingDir, userParameters, isBeingDebugged, debuggedLauncher, executor);

batch = _settings.GetBatchForTestTeardown(_solutionDirectory, testDirectory, _threadId);
batch = batch == "" ? "" : _solutionDirectory + batch;
Expand Down
9 changes: 3 additions & 6 deletions GoogleTestAdapter/Core/Runners/SequentialTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ public SequentialTestRunner(string threadName, ITestFrameworkReporter reporter,
}


public void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, string baseDir,
public void RunTests(IEnumerable<TestCase> testCasesToRun, string baseDir,
string workingDir, string userParameters, bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
{
DebugUtils.AssertIsNotNull(userParameters, nameof(userParameters));
DebugUtils.AssertIsNotNull(workingDir, nameof(workingDir));

IDictionary<string, List<TestCase>> groupedTestCases = testCasesToRun.GroupByExecutable();
TestCase[] allTestCasesAsArray = allTestCases as TestCase[] ?? allTestCases.ToArray();
foreach (string executable in groupedTestCases.Keys)
{
string finalParameters = SettingsWrapper.ReplacePlaceholders(userParameters, executable);
Expand All @@ -55,9 +54,7 @@ public void RunTests(IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> t
RunTestsFromExecutable(
executable,
finalWorkingDir,
allTestCasesAsArray.Where(tc => tc.Source == executable),
groupedTestCases[executable],
baseDir,
finalParameters,
isBeingDebugged,
debuggedLauncher,
Expand All @@ -80,13 +77,13 @@ public void Cancel()

// ReSharper disable once UnusedParameter.Local
private void RunTestsFromExecutable(string executable, string workingDir,
IEnumerable<TestCase> allTestCases, IEnumerable<TestCase> testCasesToRun, string baseDir, string userParameters,
IEnumerable<TestCase> testCasesToRun, string userParameters,
bool isBeingDebugged, IDebuggedProcessLauncher debuggedLauncher, IProcessExecutor executor)
{
string resultXmlFile = Path.GetTempFileName();
var serializer = new TestDurationSerializer();

var generator = new CommandLineGenerator(allTestCases, testCasesToRun, executable.Length, userParameters, resultXmlFile, _settings);
var generator = new CommandLineGenerator(testCasesToRun, executable.Length, userParameters, resultXmlFile, _settings);
foreach (CommandLineGenerator.Args arguments in generator.GetCommandLines())
{
if (_canceled)
Expand Down
Loading