-
Notifications
You must be signed in to change notification settings - Fork 391
/
Copy pathTestsWithTestApps.cs
74 lines (60 loc) · 2.39 KB
/
TestsWithTestApps.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System.IO;
using System.Linq;
using Xunit;
using Xunit.Abstractions;
namespace System.CommandLine.Suggest.Tests;
[Collection("TestsWithTestApps")]
public class TestsWithTestApps : IDisposable
{
protected readonly ITestOutputHelper Output;
protected readonly FileInfo EndToEndTestApp;
protected readonly FileInfo WaitAndFailTestApp;
protected readonly FileInfo DotnetSuggest;
protected readonly (string, string)[] EnvironmentVariables;
private readonly DirectoryInfo _dotnetHostDir = DotnetMuxer.Path.Directory;
private static string _testRoot;
protected TestsWithTestApps(ITestOutputHelper output)
{
Output = output;
// delete sentinel files for TestApps in order to trigger registration when it's run
var sentinelsDir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), "system-commandline-sentinel-files"));
if (sentinelsDir.Exists)
{
var sentinels = sentinelsDir
.EnumerateFiles()
.Where(f => f.Name.Contains("EndToEndTestApp") || f.Name.Contains("WaitAndFailTestApp"));
foreach (var sentinel in sentinels)
{
sentinel.Delete();
}
}
var currentDirectory = Path.Combine(
Directory.GetCurrentDirectory(),
"TestAssets");
EndToEndTestApp = new DirectoryInfo(currentDirectory)
.GetFiles("EndToEndTestApp".ExecutableName())
.SingleOrDefault();
WaitAndFailTestApp = new DirectoryInfo(currentDirectory)
.GetFiles("WaitAndFailTestApp".ExecutableName())
.SingleOrDefault();
DotnetSuggest = new DirectoryInfo(currentDirectory)
.GetFiles("dotnet-suggest".ExecutableName())
.SingleOrDefault();
PrepareTestHomeDirectoryToAvoidPolluteBuildMachineHome();
EnvironmentVariables = new[] {
("DOTNET_ROOT", _dotnetHostDir.FullName),
("INTERNAL_TEST_DOTNET_SUGGEST_HOME", _testRoot)};
}
public void Dispose()
{
if (_testRoot != null && Directory.Exists(_testRoot))
{
Directory.Delete(_testRoot, recursive: true);
}
}
private static void PrepareTestHomeDirectoryToAvoidPolluteBuildMachineHome()
{
_testRoot = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(_testRoot);
}
}