-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathTest.cs
77 lines (66 loc) · 2.39 KB
/
Test.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
75
76
77
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace Turkey
{
public class TestDescriptor
{
public string Name { get; set; }
public bool Enabled { get; set; }
public bool RequiresSdk { get; set; }
public string Version { get; set; }
public bool VersionSpecific { get; set; }
public string Type { get; set; }
public bool Cleanup { get; set; }
public double TimeoutMultiplier { get; set; } = 1.0;
internal List<string> IgnoredRIDs = new();
internal List<string> SkipWhen = new();
}
// TODO is this a strongly-typed enum in C#?
public enum TestResult {
Passed, Failed, Skipped,
}
public abstract class Test
{
public DirectoryInfo Directory { get; }
public SystemUnderTest SystemUnderTest { get; }
public string NuGetConfig { get; }
public TestDescriptor Descriptor { get; }
public bool Skip { get; }
public Test(DirectoryInfo testDirectory, SystemUnderTest system, string nuGetConfig, TestDescriptor descriptor, bool enabled)
{
this.Directory = testDirectory;
this.SystemUnderTest = system;
this.NuGetConfig = nuGetConfig;
this.Descriptor = descriptor;
this.Skip = !enabled;
}
public async Task<TestResult> RunAsync(Action<string> logger, CancellationToken cancelltionToken)
{
if (Skip)
{
return TestResult.Skipped;
}
var path = Path.Combine(Directory.FullName, "nuget.config");
if (!string.IsNullOrEmpty(NuGetConfig))
{
if (File.Exists(path))
{
Console.WriteLine($"WARNING: overwriting {path}");
}
await File.WriteAllTextAsync(path, NuGetConfig).ConfigureAwait(false);
}
var testResult = await InternalRunAsync(logger, cancelltionToken).ConfigureAwait(false);
if (!string.IsNullOrEmpty(NuGetConfig))
{
File.Delete(path);
}
return testResult;
}
protected abstract Task<TestResult> InternalRunAsync(Action<string> logger, CancellationToken cancellationToken);
}
}