private static void Run(bool hasStdOut, bool hasStdErr, string pathToProgram, params object[] parameters) { List <string> actualOut = new List <string>(); List <string> actualErr = new List <string>(); Action <string> outProcessor = (outLine) => { actualOut.Add(outLine); }; Action <string> errProcessor = (errLine) => { actualErr.Add(errLine); }; int actualExitCode; using (var cp = new Parent.CapturedProcess(pathToProgram, parameters, outProcessor, errProcessor)) { actualExitCode = cp.Run(); } Assert.AreEqual(0, actualExitCode); if (hasStdOut) { Assert.AreEqual(1, actualOut.Count); Assert.AreEqual(stdOut, actualOut[0]); } else { Assert.AreEqual(0, actualOut.Count); } if (hasStdErr) { Assert.AreEqual(1, actualErr.Count); Assert.AreEqual(stdErr, actualErr[0]); } else { Assert.AreEqual(0, actualErr.Count); } }
private static void Run(bool hasStdOut, bool hasStdErr, string pathToProgram, params object[] parameters) { List<string> actualOut = new List<string>(); List<string> actualErr = new List<string>(); Action<string> outProcessor = (outLine) => { actualOut.Add(outLine); }; Action<string> errProcessor = (errLine) => { actualErr.Add(errLine); }; int actualExitCode; using (var cp = new Parent.CapturedProcess(pathToProgram, parameters, outProcessor, errProcessor)) { actualExitCode = cp.Run(); } Assert.AreEqual(0, actualExitCode); if (hasStdOut) { Assert.AreEqual(1, actualOut.Count); Assert.AreEqual(stdOut, actualOut[0]); } else { Assert.AreEqual(0, actualOut.Count); } if (hasStdErr) { Assert.AreEqual(1, actualErr.Count); Assert.AreEqual(stdErr, actualErr[0]); } else { Assert.AreEqual(0, actualErr.Count); } }
/// <summary> /// Performs the compilation and copying. /// </summary> /// /// <returns> /// <see langword="true"/> if the processing succeeded; <see langword="false"/> otherwise. /// </returns> public override bool Execute() { // TODO: We may eventually want to check first if the output JAR is up-to-date against the inputs // TODO: We might need to delete the contents of the obj folder first int exitCode; var outputFolder = Path.GetDirectoryName(OutputAssembly); using (var process = new CapturedProcess( Java.GenerateFullPathToCompiler(), null, (line) => Log.LogMessage(MessageImportance.Normal, line), (line) => Log.LogMessage(MessageImportance.High, line))) { process.ArgumentString = GenerateCompilerCommandLine(outputFolder, References, Sources, EmitDebugInformation, DisabledWarnings); Log.LogCommandLine(MessageImportance.Normal, process.ArgumentString); exitCode = process.Run(); } if (exitCode != 0) { Log.LogError("Process exited with code {0}", exitCode); } else { #region Copy resource files to outputFolder if (Resources != null) { foreach (ITaskItem item in Resources) { var inputFile = item.ItemSpec; var outputFile = Path.Combine(outputFolder, item.ItemSpec); Log.LogMessage(MessageImportance.Low, "Copying {0} to {1}...", inputFile, outputFile); var outputDir = Path.GetDirectoryName(outputFile); Directory.CreateDirectory(outputDir); File.Copy(inputFile, outputFile, true); } } #endregion } return !Log.HasLoggedErrors; }