using System; using System.Collections.Generic; using System.IO; using System.Linq; using Sharpmake; namespace JustDance.Tools { /// /// Generates a text file that contains the list of each dll which contains unit tests. /// public static class UnitTestsReport { /// /// Generates a text file that contains the list of each dll which contains unit tests. /// public static void Generate(Solution solution) { foreach (var configuration in solution.Configurations.Where(x => x.Target.GetPlatform() == Platform.win64)) { var lines = new List(); 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() + "_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)); } } }