{
SharedState = sharedState;
- string exeDotNetPath = SharedFramework.CalculateUniqueTestDirectory(sharedState.BaseDir);
- ExecutableDotNetBuilder = new DotNetBuilder(exeDotNetPath, sharedState.BuiltDotNet.BinPath, "exe");
+ string exeDotNetPath = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(sharedState.BaseDir, "exe"));
+ ExecutableDotNetBuilder = new DotNetBuilder(exeDotNetPath, sharedState.BuiltDotNet.BinPath, null);
ExecutableDotNet = ExecutableDotNetBuilder
.AddMicrosoftNETCoreAppFrameworkMockHostPolicy("9999.0.0")
.Build();
{
private static readonly Mutex id_mutex = new Mutex();
- // MultilevelDirectory is %TEST_ARTIFACTS%\dotnetMultilevelSharedFxLookup\id.
- // We must locate the first non existing id.
- public static string CalculateUniqueTestDirectory(string baseDir)
+ // Locate the first non-existent directory of the form <basePath>-<count>
+ public static string CalculateUniqueTestDirectory(string basePath)
{
id_mutex.WaitOne();
do
{
- dir = Path.Combine(baseDir, count.ToString());
+ dir = $"{basePath}-{count}";
count++;
} while (Directory.Exists(dir));
LoadAssets();
}
- public TestApp(TestApp source)
+ private TestApp(TestApp source)
: base(source)
{
AssemblyName = source.AssemblyName;
public static TestApp CreateEmpty(string name)
{
- string location = GetNewTestArtifactPath(name);
- return new TestApp(location);
+ var (location, parentPath) = GetNewTestArtifactPath(name);
+ return new TestApp(location)
+ {
+ DirectoryToDelete = parentPath
+ };
}
public TestApp Copy()
public string Location { get; }
public string Name { get; }
+ protected string DirectoryToDelete { get; init; }
+
private readonly List<TestArtifact> _copies = new List<TestArtifact>();
- public TestArtifact(string location, string? name = null)
+ public TestArtifact(string location)
{
Location = location;
- Name = name ?? Path.GetFileName(Location);
+ Name = Path.GetFileName(Location);
+ DirectoryToDelete = Location;
}
protected TestArtifact(TestArtifact source)
{
Name = source.Name;
- Location = GetNewTestArtifactPath(Name);
+ (Location, DirectoryToDelete) = GetNewTestArtifactPath(source.Name);
CopyRecursive(source.Location, Location, overwrite: true);
public virtual void Dispose()
{
- if (!PreserveTestRuns() && Directory.Exists(Location))
+ if (!PreserveTestRuns() && Directory.Exists(DirectoryToDelete))
{
try
{
- Directory.Delete(Location, true);
+ Directory.Delete(DirectoryToDelete, true);
+ Debug.Assert(!Directory.Exists(DirectoryToDelete));
// Delete lock file last
- Debug.Assert(!Directory.Exists(Location));
- var lockPath = Directory.GetParent(Location) + ".lock";
- File.Delete(lockPath);
+ File.Delete($"{DirectoryToDelete}.lock");
} catch (Exception e)
{
Console.WriteLine("delete failed" + e);
_copies.Clear();
}
- protected static string GetNewTestArtifactPath(string artifactName)
+ protected static (string, string) GetNewTestArtifactPath(string artifactName)
{
Exception? lastException = null;
for (int i = 0; i < 10; i++)
continue;
}
Directory.CreateDirectory(artifactPath);
- return artifactPath;
+ return (artifactPath, parentPath);
}
Debug.Assert(lastException != null);
throw lastException;