public static void CompileFiles(string outDir, string pathToFiles, string[] extraDefines, List <string> extraTranslations) { try { if (pathToFiles == null) { throw new Exception("/source parameter not passed"); } var filenames = pathToFiles.Split(','); var _source = filenames.Select(o => FileExtensions.ReadFile(Path.GetFullPath(o))).ToArray(); if (_source == null) { Environment.ExitCode = 1; //throw new ArgumentNullException("\nSource Files Cannot be read"); return; } if (!_source.Any() || _source.Any(l => l == "-1")) { Environment.ExitCode = 1; Console.WriteLine("\nSource File(s) Cannot be read"); return; } string applicationExe; string dlangNativeExe; dlangNativeExe = outputFilename + "_d.exe"; if (outputFilename == null) { outputFilename = Path.GetFileNameWithoutExtension(filenames[0]); dlangNativeExe = outDir + "/" + outputFilename + "_d.exe"; } applicationExe = outputFilename + ".exe"; applicationExe.DeleteFile(); Program.Go(outDir, extraTranslations, outDir + "/" + outputFilename + ".exe", _source, applicationExe); if (outputtype == "exe") { if (Verbose) { Console.WriteLine("Generating native exe: " + dlangNativeExe); } dlangNativeExe.DeleteFile(); var bclDir = pathToDcorlib; if (String.IsNullOrEmpty(bclDir)) { bclDir = Directory.GetParent( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location + "..\\..\\..\\..\\..\\")) + "\\SharpNative\\DCorlib"; } var bclFiles = Directory.GetFiles(bclDir, "*.d", SearchOption.AllDirectories) .OrderBy(o => o) .ToList(); var start = DateTime.Now; var compilerOptions = CreateOptions(); NativeCompilationUtils.SetCompilerOptions(compilerOptions); var outputFiles = Directory.GetFiles(outDir, "*.d", SearchOption.AllDirectories); NativeCompilationUtils.CompileAppToNativeExe( (outputFiles).Where(j => j.EndsWith(".d")).Union(bclFiles).ToArray(), dlangNativeExe); if (Verbose) { Console.WriteLine("\nCompiling to binary took " + (DateTime.Now - start).TotalMilliseconds + " ms\n"); } if (!String.IsNullOrEmpty(RunWithArgs)) { if (Verbose) { Console.WriteLine("Running app " + dlangNativeExe + " with arguments: " + RunWithArgs); } var output = dlangNativeExe.ExecuteCommand(RunWithArgs); Console.WriteLine(output); } } if (outputtype == "library") { } Environment.ExitCode = 0; } catch (AggregateException agex) { Environment.ExitCode = 1; Exception ex = agex; while (ex is AggregateException) { ex = ex.InnerException; } Console.WriteLine("\nException:"); Console.WriteLine(ex.Message); } catch (Exception ex) { Environment.ExitCode = 1; Console.WriteLine("\nException:"); Console.WriteLine(ex.Message); } }
public static void RunTests(string outDir, string pathToFiles, string[] extraDefines, List <string> extraTranslations) { var options = CreateOptions(); try { if (pathToFiles == null) { throw new Exception("/source parameter not passed"); } var filenames = Directory.GetFiles(Path.GetFullPath(pathToFiles), "*.cs"); Console.WriteLine("\r\r" + ("Running all tests in : " + pathToFiles) + "\r\r"); Func <string, string> strip = i => Regex.Replace(i ?? "", "[\r\n \t]+", " ").Trim(); int count = 0; int passCount = 0; NativeCompilationUtils.SetCompilerOptions(options); var bclDir = pathToDcorlib; if (String.IsNullOrEmpty(bclDir)) { bclDir = Directory.GetParent( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location + "..\\..\\..\\..\\..\\")) + "\\SharpNative\\DCorlib"; } var bclFiles = Directory.GetFiles(bclDir, "*.d", SearchOption.AllDirectories) .OrderBy(o => o) .ToList(); var failedTestNames = new List <string>(); foreach (var filename in filenames) { var _source = FileExtensions.ReadFile(Path.GetFullPath(filename)); if (_source == null) { Environment.ExitCode = 1; //throw new ArgumentNullException("\nSource Files Cannot be read"); return; } if (_source == "-1") { Environment.ExitCode = 1; Console.WriteLine("\nSource File Cannot be read"); return; } var shortName = Path.GetFileName(filename); Console.WriteLine("-------------------------Running Test: " + shortName + "-------------------------"); string applicationExe; string dlangNativeExe; if (String.IsNullOrEmpty(outDir)) { outDir = TempDir; } dlangNativeExe = outputFilename + "_d.exe"; applicationExe = outputFilename + ".exe"; if (outputFilename == null) { outputFilename = Path.GetFileNameWithoutExtension(filename); dlangNativeExe = outDir + "/" + outputFilename + "_d.exe"; applicationExe = outDir + "/" + outputFilename + ".exe"; } applicationExe.DeleteFile(); Program.Go(outDir, extraTranslations, applicationExe, new string[] { FileExtensions.ReadFile(filename) }, outputFilename + ".exe"); if (Verbose) { Console.WriteLine("Generating native exe: " + dlangNativeExe); } dlangNativeExe.DeleteFile(); var start = DateTime.Now; var outputFiles = Directory.GetFiles(outDir, "*.d", SearchOption.AllDirectories); NativeCompilationUtils.CompileAppToNativeExe( (outputFiles).Where(j => j.EndsWith(".d")).Union(bclFiles).ToArray(), dlangNativeExe); Console.WriteLine("\nCompiling to binary took " + (DateTime.Now - start).TotalMilliseconds + " ms\n"); var CSharpOutput = applicationExe.ExecuteCommand(RunWithArgs); var CppOutput = dlangNativeExe.ExecuteCommand(RunWithArgs); Console.WriteLine(CSharpOutput); Console.WriteLine(CppOutput); count++; if (count % 20 == 0) { GC.Collect(); } if (strip(CSharpOutput) == strip(CppOutput)) { passCount++; Console.WriteLine("-------------------------Test {0} Passed:-------------------------\n", shortName); } else { Console.WriteLine(String.Format("Test {0} Failed:\n", shortName)); failedTestNames.Add(Path.GetFileNameWithoutExtension(shortName)); } } Console.WriteLine( String.Format("Summary \nTotal:{0} \nPass Rate:{1} \nPassed: {2} \nFailed: {3} {4}\n", filenames.Count(), (passCount * 100) / ((float)filenames.Count()), passCount, filenames.Count() - passCount, (filenames.Count() - passCount == 0) ? "" : failedTestNames.Aggregate((k, j) => k + " , " + j))); PrepareTempDir(); Environment.ExitCode = 0; } catch (AggregateException agex) { Environment.ExitCode = 1; Exception ex = agex; while (ex is AggregateException) { ex = ex.InnerException; } Console.WriteLine("\nException:"); Console.WriteLine(ex.Message); } catch (Exception ex) { Environment.ExitCode = 1; Console.WriteLine("\nException:"); Console.WriteLine(ex.Message); } }