Skip to content

Commit

Permalink
Prepare 1.7.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyHendriks committed Aug 1, 2021
1 parent f4a963b commit 65940a1
Show file tree
Hide file tree
Showing 37 changed files with 214,534 additions and 104 deletions.
11 changes: 9 additions & 2 deletions Docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

Changes are relative to v1.0.0

## Changes for upcoming release
## Changes for v1.7.0

Adds support for Visual Studio 2022.
### New Features

- Add support for Visual Studio 2022.
- Add support for environmental variables (inspired by issue #37). Environmental variables to be set for the Catch2 executable process can now be configured with the `<Environment>` option (see [Settings documentation](Settings.md#environment) for details).

### Bug fixes

- Issue #46: A problem deleting temporary files, caused the test adapter to fail.

## Changes for v1.6.0

Expand Down
18 changes: 17 additions & 1 deletion Docs/Settings.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Settings for Test Adapter for Catch2

> The information on this page is based on **Test Adapter for Catch2** v1.6.0.
> The information on this page is based on **Test Adapter for Catch2** v1.7.0.
In order for the **Test Adapter for Catch2** to do its job, it requires certain settings to be set explicitly by the user. This is done via a _.runsettings_ file. The settings for the **Test Adapter for Catch2** are collected inside the `<Catch2Adapter>` node that can be added to the `<RunSettings>` node of the _.runsettings_ file. Below is the list of settings that are available for the **Test Adapter for Catch2**. The ones with an asterisk are required to be set by the user and have defaults that will cause the **Test Adapter for Catch2** to not discovery tests.

Expand All @@ -9,6 +9,7 @@ In order for the **Test Adapter for Catch2** to do its job, it requires certain
- [`<DebugBreak>`](#debugbreak)
- [`<DiscoverCommandLine>`](#discovercommandline)
- [`<DiscoverTimeout>`](#discovertimeout)
- [`<Environment>`](#environment)
- [`<ExecutionMode>`](#executionmode)
- [`<ExecutionModeForceSingleTagRgx>`](#executionmodeforcesingletagrgx)
- [`<FilenameFilter>`](#filenamefilter)*
Expand Down Expand Up @@ -126,6 +127,21 @@ With the `<DiscoverTimeout>` option you can apply a timeout in milliseconds when

When the timeout value is too small it is possible that test discovery fails. If that happens a warning is displayed in the Test Explorer output to make this clear. There have been situations where discovery intermittently failed (especially when the computer was very busy with other stuff).

## Environment

With the `<Environment>` option you can configure environmental variables to be set for the Catch2 executable process. Set the key-value pairs as children of the `<Environment>` parameter, where name of the xml-element is the `key`-part and the content of that element is the `value`-part of the key-value pair. Alternatively the `value`-attribute can be used to set the value. See below for an example that will result in the environmental variables "`MyCustomEnvSetting=Welcome`" and "`MyOtherCustomEnvSetting=debug<0>`" to be set for the Catch2 executable process.

```xml
<Environment>
<MyCustomEnvSetting>Welcome</MyCustomEnvSetting>
<MyOtherCustomEnvSetting value="debug&lt;0&gt;"/>
</Environment>
```

Note, in case a duplicate environmental variable key exists, the value will be overwritten with the one that is configured via the `<Environment>` parameter for the Catch2 executable process.

> Introduced in v1.7.0
## ExecutionMode

Default: Single
Expand Down
2 changes: 2 additions & 0 deletions Docs/Walkthrough-vs2017.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ You can load multiple _.runsettings_ files and switch between them. The one with

![Select Run Settings File](Images/walkthrough-vs2017/Walkthrough-04.png)

For an overview of the **Test Adapter for Catch2** specific settings that can be used in a `.runsettings`-file, see the [Settings documentation](Settings.md).

## Trigger test discovery

### First build
Expand Down
2 changes: 2 additions & 0 deletions Docs/Walkthrough-vs2019.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ You can load multiple _.runsettings_ files and switch between them. The one with

![Select Run Settings File](Images/walkthrough-vs2019/Walkthrough-04.png)

For an overview of the **Test Adapter for Catch2** specific settings that can be used in a `.runsettings`-file, see the [Settings documentation](Settings.md).

## Trigger test discovery

### First build
Expand Down
1 change: 1 addition & 0 deletions Libraries/Catch2Interface/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static class Constants
public const string NodeName_DebugBreak = "DebugBreak";
public const string NodeName_DiscoverCommanline = "DiscoverCommandLine";
public const string NodeName_DiscoverTimeout = "DiscoverTimeout";
public const string NodeName_Environment = "Environment";
public const string NodeName_ExecutionMode = "ExecutionMode";
public const string NodeName_ExecutionModeForceSingleTagRgx = "ExecutionModeForceSingleTagRgx";
public const string NodeName_FilenameFilter = "FilenameFilter";
Expand Down
87 changes: 47 additions & 40 deletions Libraries/Catch2Interface/Discoverer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,58 +152,65 @@ private void ExtractTestCases(string source)
private string GetTestCaseInfo(string source)
{
// Retrieve test cases
var process = new Process();
process.StartInfo.FileName = source;
process.StartInfo.Arguments = _settings.DiscoverCommandLine;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.Start();

var output = process.StandardOutput.ReadToEndAsync();
var erroroutput = process.StandardError.ReadToEndAsync();

if(_settings.DiscoverTimeout > 0)
using (var process = new Process())
{
process.WaitForExit(_settings.DiscoverTimeout);
}
else
{
process.WaitForExit();
}
process.StartInfo.FileName = source;
process.StartInfo.Arguments = _settings.DiscoverCommandLine;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;

if( !process.HasExited )
{
process.Kill();
LogNormal($" Warning: Discovery timeout for {source}{Environment.NewLine}");
if(output.Result.Length == 0)
_settings.AddEnviromentVariables(process.StartInfo.EnvironmentVariables);

process.Start();

var output = process.StandardOutput.ReadToEndAsync();
var erroroutput = process.StandardError.ReadToEndAsync();

if(_settings.DiscoverTimeout > 0)
{
LogVerbose($" Killed process. There was no output.{Environment.NewLine}");
process.WaitForExit(_settings.DiscoverTimeout);
}
else
{
LogVerbose($" Killed process. Threw away following output:{Environment.NewLine}{output.Result}");
}
return string.Empty;
}
else
{
if(!string.IsNullOrEmpty(erroroutput.Result))
{
LogNormal($" Error Occurred (exit code {process.ExitCode}):{Environment.NewLine}{erroroutput.Result}");
LogDebug($" output:{Environment.NewLine}{output.Result}");
return string.Empty;
process.WaitForExit();
}

if (!string.IsNullOrEmpty(output.Result))
if( !process.HasExited )
{
return output.Result;
process.Kill();
process.WaitForExit();

LogNormal($" Warning: Discovery timeout for {source}{Environment.NewLine}");
if(output.Result.Length == 0)
{
LogVerbose($" Killed process. There was no output.{Environment.NewLine}");
}
else
{
LogVerbose($" Killed process. Threw away following output:{Environment.NewLine}{output.Result}");
}
return string.Empty;
}
else
{
LogDebug($" No output{Environment.NewLine}");
return string.Empty;
if (!string.IsNullOrEmpty(erroroutput.Result))
{
LogNormal($" Error Occurred (exit code {process.ExitCode}):{Environment.NewLine}{erroroutput.Result}");
LogDebug($" output:{Environment.NewLine}{output.Result}");
return string.Empty;
}

if (!string.IsNullOrEmpty(output.Result))
{
return output.Result;
}
else
{
LogDebug($" No output{Environment.NewLine}");
return string.Empty;
}
}
}
}
Expand Down
44 changes: 33 additions & 11 deletions Libraries/Catch2Interface/Executor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Timers;

namespace Catch2Interface
{
Expand Down Expand Up @@ -147,6 +146,8 @@ public TestResult Run(string testname, string source)
process.StartInfo.UseShellExecute = false;
process.StartInfo.WorkingDirectory = WorkingDirectory(source);

_settings.AddEnviromentVariables(process.StartInfo.EnvironmentVariables);

LogDebug($"Source for test case: {source}{Environment.NewLine}");
LogDebug($"Commandline arguments used to run tests case: {process.StartInfo.Arguments}{Environment.NewLine}");
LogDebug($"Run test case: {testname}{Environment.NewLine}");
Expand All @@ -162,40 +163,44 @@ public TestResult Run(string testname, string source)
process.WaitForExit();
}

_process = null;

if (!process.HasExited)
{
process.Kill();
_process = null;
process.WaitForExit();
process.Close();

string report = ReadReport(reportfilename);
LogVerbose($"Killed process. Threw away following output:{Environment.NewLine}{report}{Environment.NewLine}");

Log = _logbuilder.ToString();

// Cleanup temporary files (don't delete files when loglevel is debug)
if (_settings.LoggingLevel != LoggingLevels.Debug)
{
File.Delete(reportfilename);
TryDeleteFile(reportfilename);
}

Log = _logbuilder.ToString();

return new TestResult( new TimeSpan(0, 0, 0, 0, _settings.TestCaseTimeout)
, "Testcase timed out."
, report );
}
else
{
_process = null;
process.Close();

string report = ReadReport(reportfilename);
LogDebug(report);
Log = _logbuilder.ToString();

// Cleanup temporary files (don't delete files when loglevel is debug)
if (_settings.LoggingLevel != LoggingLevels.Debug)
{
File.Delete(reportfilename);
TryDeleteFile(reportfilename);
}

Log = _logbuilder.ToString();

// Process testrun output
return new TestResult(report, testname, _settings, false);
}
Expand All @@ -222,6 +227,8 @@ public XmlOutput Run(TestCaseGroup group)
process.StartInfo.UseShellExecute = false;
process.StartInfo.WorkingDirectory = WorkingDirectory(group.Source);

_settings.AddEnviromentVariables(process.StartInfo.EnvironmentVariables);

LogDebug($"Source for test case: {group.Source}{Environment.NewLine}");
LogDebug($"Commandline arguments used to run tests case: {process.StartInfo.Arguments}{Environment.NewLine}");

Expand All @@ -238,15 +245,18 @@ public XmlOutput Run(TestCaseGroup group)
process.WaitForExit();
}

_process = null;

if (!process.HasExited)
{
process.Kill();
process.WaitForExit();
LogVerbose($"Killed process.{Environment.NewLine}");
Log = _logbuilder.ToString();
timeout = true;
}

_process = null;
process.Close();

// Read and process generated report
string report = ReadReport(reportfilename); // Also does cleanup of reportfile
Expand All @@ -256,8 +266,8 @@ public XmlOutput Run(TestCaseGroup group)
// Cleanup temporary files (don't delete files when loglevel is debug)
if (_settings.LoggingLevel != LoggingLevels.Debug)
{
File.Delete(caselistfilename);
File.Delete(reportfilename);
TryDeleteFile(caselistfilename);
TryDeleteFile(reportfilename);
}

return new XmlOutput(report, timeout, _settings);
Expand Down Expand Up @@ -358,6 +368,18 @@ private string ReadReport(string reportfilename)
}
}

private void TryDeleteFile(string filename)
{
try
{
File.Delete(filename);
}
catch
{
LogNormal($"Unable to delete file: {filename}");
}
}

#endregion // Private Methods

#region Private Logging Methods
Expand Down
48 changes: 48 additions & 0 deletions Libraries/Catch2Interface/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
** Basic Info **/

using System.Collections;
using System.Collections.Specialized;
using System.Text.RegularExpressions;
using System.Xml;

Expand Down Expand Up @@ -128,6 +130,7 @@ public class Settings
public bool Disabled { get; set; } = Constants.S_DefaultDisabled;
public string DiscoverCommandLine { get; set; } = Constants.S_DefaultDiscoverCommandline;
public int DiscoverTimeout { get; set; } = Constants.S_DefaultDiscoverTimeout;
public StringDictionary Environment { get; set; }
public ExecutionModes ExecutionMode { get; set; } = Constants.S_DefaultExecutionMode;
public Regex ExecutionModeForceSingleTagRgx { get; set; } = new Regex(Constants.S_DefaultExecutionModeForceSingleTagRgx, RegexOptions.Singleline);
public string FilenameFilter { get; set; } = Constants.S_DefaultFilenameFilter;
Expand Down Expand Up @@ -205,6 +208,32 @@ public static Settings Extract(XmlNode node)
}
}

// Environment
var envmnt = node.SelectSingleNode(Constants.NodeName_Environment);
if (envmnt != null && envmnt.HasChildNodes )
{
settings.Environment = new StringDictionary();
foreach(XmlNode child in envmnt.ChildNodes)
{
if( child.NodeType == XmlNodeType.Element)
{
string name = child.Name;
if( child.Attributes["value"] != null)
{
settings.Environment.Add(name, child.Attributes["value"].Value);
}
else if (child.HasChildNodes && child.FirstChild.NodeType == XmlNodeType.Text)
{
settings.Environment.Add(name, child.FirstChild.Value);
}
else
{
settings.Environment.Add(name, "");
}
}
}
}

// ExecutionMode
var exmode = node.SelectSingleNode(Constants.NodeName_ExecutionMode)?.FirstChild;
if (exmode != null
Expand Down Expand Up @@ -339,6 +368,25 @@ public string ProcessStacktraceDescription(string description)
return mod_description;
}

public void AddEnviromentVariables(StringDictionary dictionary)
{
if (Environment != null && dictionary != null)
{
foreach (DictionaryEntry element in Environment)
{
var key = element.Key as string;
if(dictionary.ContainsKey(key))
{
dictionary[key] = element.Value as string;
}
else
{
dictionary.Add(key, element.Value as string);
}
}
}
}

#endregion // Public Methods

#region Static Private
Expand Down
Loading

0 comments on commit 65940a1

Please sign in to comment.