/// <summary> /// Runs cygpath with the specified arguments and returns the result /// as a <see cref="string" />. /// </summary> /// <param name="args">The arguments to pass to cygpath.</param> /// <returns> /// The result of running cygpath with the specified arguments. /// </returns> private string RunCygpathString(Argument[] args) { MemoryStream ms = new MemoryStream(); ExecTask execTask = GetTask(ms); execTask.Arguments.AddRange(args); try { execTask.Execute(); ms.Position = 0; StreamReader sr = new StreamReader(ms); string output = sr.ReadLine(); sr.Close(); return(output); } catch (Exception ex) { ms.Position = 0; StreamReader sr = new StreamReader(ms); string output = sr.ReadToEnd(); sr.Close(); if (output.Length != 0) { throw new BuildException(output, ex); } else { throw; } } }
public void Execute_EchoTask_ShouldSucceed() { var echoTask = new ExecTask { ToolPath = "cmd.exe", Arguments = string.Format("/c echo {0}", "Hello, Rosalia!") }; echoTask.Execute().AssertSuccess(); }
public void Execute_EchoTask_ShouldLogMessage() { var echoTask = new ExecTask { ToolPath = "cmd.exe", Arguments = string.Format("/c echo {0}", "Hello, Rosalia!") }; echoTask.Execute() .AssertSuccess() .Log.AssertHasMessage(MessageLevel.Info, "Hello, Rosalia!"); }
/// <summary> /// Executes the task. /// </summary> protected override void ExecuteTask() { if (!this.DoxygenBinary.Exists) { this.Log(Level.Error, "Doxygen cannot be found."); return; } String baseFolder = this.CreateBaseDir(); DocSet docSet = this.CreateDocSet(); IEnumerable <Framework> frameworks = this.CreateFrameworks(docSet); foreach (var f in frameworks) { if (f.source != DocumentOrigin.Doxygen) { continue; } String configuration; if (docSet != null) { configuration = Path.Combine(baseFolder, docSet.Name, f.name, "doxygen.cfg"); } else { configuration = Path.Combine(baseFolder, f.name, "doxygen.cfg"); } if (File.Exists(configuration)) { continue; } this.Log(Level.Info, "Generating Doxygen files for '{0}'...", f.name); ExportConfiguration(configuration); ExecTask execTask = new ExecTask(); execTask.Project = this.Project; execTask.FailOnError = true; execTask.FileName = this.DoxygenBinary.ToString(); execTask.CommandLineArguments = Path.GetFileName(configuration); execTask.WorkingDirectory = new DirectoryInfo(Path.GetDirectoryName(configuration)); execTask.Execute(); GenerateDescriptor(baseFolder, f); } }
public void TestDefaultExitCode() { this.PrepareTestEnvironment(); ExecTask task = this.CreateTaskWithProject(); if (PlatformHelper.IsUnix) { task.FileName = "bash"; task.Arguments.Add(new Argument("-c")); } else { task.FileName = @"cmd.exe"; task.Arguments.Add(new Argument("/c")); } task.Arguments.Add(new Argument("exit")); task.Arguments.Add(new Argument(0.ToString(CultureInfo.InvariantCulture))); task.Execute(); }
public void TestExpectedExitCode() { this.PrepareTestEnvironment(); List <int> exitCodes = new List <int>(); exitCodes.Add(byte.MaxValue); exitCodes.Add(byte.MinValue); exitCodes.Add(sbyte.MaxValue); // Bash supports only exit codes from 0 to 255 if (PlatformHelper.IsWindows) { exitCodes.Add(sbyte.MinValue); exitCodes.Add(short.MaxValue); exitCodes.Add(short.MinValue); exitCodes.Add(ushort.MaxValue); exitCodes.Add(ushort.MinValue); exitCodes.Add(int.MaxValue); exitCodes.Add(int.MinValue); } foreach (int exitCode in exitCodes) { ExecTask task = this.CreateTaskWithProject(); if (PlatformHelper.IsUnix) { task.FileName = "bash"; task.Arguments.Add(new Argument("-c")); task.Arguments.Add(new Argument("\"exit " + exitCode.ToString(CultureInfo.InvariantCulture) + "\"")); } else { task.FileName = @"cmd.exe"; task.Arguments.Add(new Argument("/c")); task.Arguments.Add(new Argument("exit")); task.Arguments.Add(new Argument(exitCode.ToString(CultureInfo.InvariantCulture))); } task.ExpectedExitCode = exitCode; task.Execute(); } }
/// <summary> /// Runs pkg-config with the specified arguments and returns a /// <see cref="bool" /> based on the exit code. /// </summary> /// <param name="args">The arguments to pass to pkg-config.</param> /// <returns> /// <see langword="true" /> if pkg-config exited with exit code 0; /// otherwise, <see langword="false" /> /// </returns> private bool RunPkgConfigBool(Argument[] args) { MemoryStream ms = new MemoryStream(); ExecTask execTask = GetTask(ms); execTask.Arguments.AddRange(args); try { execTask.Execute(); return(true); } catch (Exception) { if (execTask.ExitCode == ExternalProgramBase.UnknownExitCode) { // process could not be started or did not exit in time throw; } return(false); } }
public void TestUnexpectedExitCode() { this.PrepareTestEnvironment(); // Dictonary with test data. Key: produced exit code, value: expected exit code Dictionary <int, int> exitCodes = new Dictionary <int, int>(); exitCodes.Add(byte.MaxValue, byte.MinValue); // Bash supports only exit codes from 0 to 255 if (PlatformHelper.IsWindows) { exitCodes.Add(sbyte.MaxValue, sbyte.MinValue); exitCodes.Add(short.MaxValue, short.MinValue); exitCodes.Add(ushort.MaxValue, ushort.MinValue); exitCodes.Add(int.MaxValue, int.MinValue); } foreach (KeyValuePair <int, int> exitCode in exitCodes) { ExecTask task = this.CreateTaskWithProject(); if (PlatformHelper.IsUnix) { task.FileName = "bash"; task.Arguments.Add(new Argument("-c")); task.Arguments.Add(new Argument("\"exit " + exitCode.Key.ToString(CultureInfo.InvariantCulture) + "\"")); } else { task.FileName = @"cmd.exe"; task.Arguments.Add(new Argument("/c")); task.Arguments.Add(new Argument("exit")); task.Arguments.Add(new Argument(exitCode.Key.ToString(CultureInfo.InvariantCulture))); } task.ExpectedExitCode = exitCode.Value; BuildException currentBuildException = null; try { task.Execute(); } catch (BuildException ex) { currentBuildException = ex; } Assert.IsNotNull(currentBuildException); } foreach (KeyValuePair <int, int> exitCode in exitCodes) { ExecTask task = this.CreateTaskWithProject(); if (PlatformHelper.IsUnix) { task.FileName = "bash"; task.Arguments.Add(new Argument("-c")); } else { task.FileName = @"cmd.exe"; task.Arguments.Add(new Argument("/c")); } task.Arguments.Add(new Argument("exit")); task.Arguments.Add(new Argument(exitCode.Value.ToString(CultureInfo.InvariantCulture))); task.ExpectedExitCode = exitCode.Key; BuildException currentBuildException = null; try { task.Execute(); } catch (BuildException ex) { currentBuildException = ex; } Assert.IsNotNull(currentBuildException); } }