JD2022-TU1/main/build/sharpmake/Tools/UnitTestsReport.cs

46 lines
No EOL
2 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Sharpmake;
namespace JustDance.Tools
{
/// <summary>
/// Generates a text file that contains the list of each dll which contains unit tests.
/// </summary>
public static class UnitTestsReport
{
/// <summary>
/// Generates a text file that contains the list of each dll which contains unit tests.
/// </summary>
public static void Generate(Solution solution)
{
foreach (var configuration in solution.Configurations.Where(x => x.Target.GetPlatform() == Platform.win64))
{
var lines = new List<string>();
foreach (var projectInfo in configuration.IncludedProjectInfos)
{
var project = projectInfo.Project as CSharpProject;
if (project != null && ContainsUnitTests(project))
{
var projectConf = projectInfo.Configuration;
var extension = projectConf.Output == Project.Configuration.OutputType.DotNetClassLibrary ? "dll" : "exe";
var assemblyName = project.AssemblyName + "." + extension;
var outputPath = Path.Combine(projectConf.TargetPath, assemblyName);
lines.Add(outputPath);
}
}
var outputFilename = Path.Combine(BaseProject.TempPath, solution.Name + "_" + configuration.Target.GetFragment<Optimization>() + "_unittestsreport.txt");
File.WriteAllLines(outputFilename, lines);
}
}
private static bool ContainsUnitTests(CSharpProject project)
{
return project.ResolvedSourceFiles.Any(file => file.EndsWith("test.cs", StringComparison.OrdinalIgnoreCase) ||
file.EndsWith("tests.cs", StringComparison.OrdinalIgnoreCase));
}
}
}