blob: 309e90389d6adb98d34ab7b8beaf5c7b405e3dc6 (
plain)
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
|
// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
namespace WixBuildTools.TestSupport
{
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
public class TestData
{
public static string Get(params string[] paths)
{
var localPath = Path.GetDirectoryName(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath);
return Path.Combine(localPath, Path.Combine(paths));
}
public static string GetUnitTestLogsFolder([CallerFilePath] string path = "", [CallerMemberName] string method = "")
{
var startingPath = Path.GetDirectoryName(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath);
var buildPath = startingPath;
while (!String.IsNullOrEmpty(buildPath))
{
var folderName = Path.GetFileName(buildPath);
if (String.Equals("build", folderName, StringComparison.OrdinalIgnoreCase))
{
break;
}
buildPath = Path.GetDirectoryName(buildPath);
}
if (String.IsNullOrEmpty(buildPath))
{
throw new InvalidOperationException($"Could not find the 'build' folder in the test path: {startingPath}. Cannot get test logs folder without being able to find the build folder.");
}
var testLogsFolder = Path.Combine(buildPath, "logs", "UnitTests", $"{Path.GetFileNameWithoutExtension(path)}_{method}");
Directory.CreateDirectory(testLogsFolder);
return testLogsFolder;
}
}
}
|