public void ToolExeIsFoundOnToolPath() { string shellName = NativeMethodsShared.IsWindows ? "cmd.exe" : "sh"; string copyName = NativeMethodsShared.IsWindows ? "xcopy.exe" : "cp"; using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.FullToolName = shellName; #if FEATURE_SPECIAL_FOLDERS string systemPath = Environment.GetFolderPath(Environment.SpecialFolder.System); #else string systemPath = FileUtilities.GetFolderPath(FileUtilities.SpecialFolder.System); #endif t.ToolPath = systemPath; t.Execute(); Assert.Equal(Path.Combine(systemPath, shellName), t.PathToToolUsed); engine.AssertLogContains(shellName); engine.Log = String.Empty; t.ToolExe = copyName; t.Execute(); Assert.Equal(Path.Combine(systemPath, copyName), t.PathToToolUsed); engine.AssertLogContains(copyName); engine.AssertLogDoesntContain(shellName); } }
public void ToolTaskCanChangeCanonicalErrorFormat() { string tempFile = FileUtilities.GetTemporaryFile(); File.WriteAllText(tempFile, @" Main.cs(17,20): warning CS0168: The variable 'foo' is declared but never used. BADTHINGHAPPENED: This is my custom error format that's not in canonical error format. "); using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; // The command we're giving is the command to spew the contents of the temp // file we created above. t.MockCommandLineCommands = "/C type \"" + tempFile + "\""; t.Execute(); // The above command logged a canonical warning, as well as a custom error. engine.AssertLogContains("CS0168"); engine.AssertLogContains("The variable 'foo' is declared but never used"); engine.AssertLogContains("BADTHINGHAPPENED"); engine.AssertLogContains("This is my custom error format"); Assert.Equal(1, engine.Warnings); // "Expected one warning in log." Assert.Equal(1, engine.Errors); // "Expected one error in log." } File.Delete(tempFile); }
public void ToolPathIsFoundWhenDirectoryExistsWithNameOfTool() { string toolName = NativeMethodsShared.IsWindows ? "cmd" : "sh"; string savedCurrentDirectory = Directory.GetCurrentDirectory(); try { using (var env = TestEnvironment.Create()) { string tempDirectory = env.CreateFolder().FolderPath; env.SetCurrentDirectory(tempDirectory); env.SetEnvironmentVariable("PATH", $"{tempDirectory}{Path.PathSeparator}{Environment.GetEnvironmentVariable("PATH")}"); Directory.SetCurrentDirectory(tempDirectory); string directoryNamedSameAsTool = Directory.CreateDirectory(Path.Combine(tempDirectory, toolName)).FullName; MyTool task = new MyTool { BuildEngine = new MockEngine(), FullToolName = toolName, }; bool result = task.Execute(); Assert.NotEqual(directoryNamedSameAsTool, task.PathToToolUsed); Assert.True(result); } } finally { Directory.SetCurrentDirectory(savedCurrentDirectory); } }
public void ToolPathIsFoundWhenDirectoryExistsWithNameOfTool() { string toolName = NativeMethodsShared.IsWindows ? "cmd" : "sh"; string savedCurrentDirectory = Directory.GetCurrentDirectory(); string tempDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"))).FullName; try { using (new Helpers.TemporaryEnvironment("PATH", $"{tempDirectory}{Path.PathSeparator}{Environment.GetEnvironmentVariable("PATH")}")) { Directory.SetCurrentDirectory(tempDirectory); string directoryNamedSameAsTool = Directory.CreateDirectory(Path.Combine(tempDirectory, toolName)).FullName; MyTool task = new MyTool { BuildEngine = new MockEngine(), FullToolName = toolName, }; bool result = task.Execute(); Assert.NotEqual(directoryNamedSameAsTool, task.PathToToolUsed); Assert.True(result); } } finally { Directory.SetCurrentDirectory(savedCurrentDirectory); FileUtilities.DeleteDirectoryNoThrow(tempDirectory, recursive: true); } }
public void DoNotFormatTaskCommandOrMessage() { MyTool t = new MyTool(); MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.MockCommandLineCommands = "/C echo hello world {"; // Unmatched curly would crash if they did t.Execute(); engine.AssertLogContains("echo hello world {"); Assert.Equal(0, engine.Errors); }
public void EnvironmentVariablesToToolTaskEqualsSign() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); task.EnvironmentVariables = new string[] { "a=b=c" }; bool result = task.Execute(); Assert.Equal(true, result); Assert.Equal("b=c", task.StartInfo.EnvironmentVariables["a"]); }
public void EnvironmentVariablesToToolTaskInvalid3() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); task.EnvironmentVariables = new string[] { "=a;b=c" }; bool result = task.Execute(); Assert.Equal(false, result); Assert.Equal(false, task.ExecuteCalled); }
public void EnvironmentVariablesToToolTaskInvalid3() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); task.EnvironmentVariables = new string[] { "=a;b=c" }; bool result = task.Execute(); result.ShouldBe(false); task.ExecuteCalled.ShouldBe(false); }
public void EnvironmentVariablesToToolTaskNotSet() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); task.EnvironmentVariables = null; bool result = task.Execute(); Assert.Equal(true, result); Assert.Equal(true, task.ExecuteCalled); Assert.Equal(true, task.StartInfo.EnvironmentVariables["username"].Length > 0); }
public void ToolExeIsFoundOnToolPath() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.FullToolName = "cmd.exe"; string systemPath = Environment.GetFolderPath(Environment.SpecialFolder.System); t.ToolPath = systemPath; t.Execute(); Assert.Equal(Path.Combine(systemPath, "cmd.exe"), t.PathToToolUsed); engine.AssertLogContains("cmd.exe"); engine.Log = String.Empty; t.ToolExe = "xcopy.exe"; t.Execute(); Assert.Equal(Path.Combine(systemPath, "xcopy.exe"), t.PathToToolUsed); engine.AssertLogContains("xcopy.exe"); engine.AssertLogDoesntContain("cmd.exe"); } }
public void VisualBasicLikeEscapedQuotesInCommandAreNotMadeForwardSlashes() { MyTool t = new MyTool(); MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.MockCommandLineCommands = NativeMethodsShared.IsWindows ? "/C echo \"hello \\\"world\\\"\"" : "-c echo \"hello \\\"world\\\"\""; t.Execute(); engine.AssertLogContains("echo \"hello \\\"world\\\"\""); Assert.Equal(0, engine.Errors); }
public void DoNotFormatTaskCommandOrMessage() { MyTool t = new MyTool(); MockEngine engine = new MockEngine(); t.BuildEngine = engine; // Unmatched curly would crash if they did t.MockCommandLineCommands = NativeMethodsShared.IsWindows ? "/C echo hello world {" : @"-c """"""echo hello world {"""""""; t.Execute(); engine.AssertLogContains("echo hello world {"); engine.Errors.ShouldBe(0); }
public void Regress_Mutation_MissingExecutableIsLogged() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.ToolPath = NativeMethodsShared.IsWindows ? @"C:\MyAlternatePath" : "/MyAlternatePath"; t.Execute().ShouldBeFalse(); // There should be an error about invalid task location. engine.AssertLogContains("MSB6004"); } }
public void Regress_Mutation_UserSuppliedToolPathIsLogged() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.ToolPath = @"C:\MyAlternatePath"; t.Execute(); // The alternate path should be mentioned in the log. engine.AssertLogContains("MyAlternatePath"); } }
public void Regress_Mutation_MissingExecutableIsLogged() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.ToolPath = @"C:\MyAlternatePath"; Assert.False(t.Execute()); // There should be an error about invalid task location. engine.AssertLogContains("MSB6004"); } }
public void TaskNotFoundOnPath() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.FullToolName = "doesnotexist.exe"; Assert.False(t.Execute()); Assert.Equal(-1, t.ExitCode); Assert.Equal(1, engine.Errors); // Does not throw an exception } }
public void TaskFoundOnPath() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.FullToolName = "cmd.exe"; Assert.True(t.Execute()); Assert.Equal(0, t.ExitCode); Assert.Equal(0, engine.Errors); engine.AssertLogContains(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe")); } }
public void TaskNotFoundOnPath() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.FullToolName = "doesnotexist.exe"; t.Execute().ShouldBeFalse(); t.ExitCode.ShouldBe(-1); engine.Errors.ShouldBe(1); // Does not throw an exception } }
public void EnvironmentVariablesToToolTaskEqualsSign() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); task.EnvironmentVariables = new string[] { "a=b=c" }; bool result = task.Execute(); Assert.Equal(true, result); #if FEATURE_PROCESSSTARTINFO_ENVIRONMENT Assert.Equal("b=c", task.StartInfo.Environment["a"]); #else Assert.Equal("b=c", task.StartInfo.EnvironmentVariables["a"]); #endif }
public void DoNotErrorWhenTextSentToStandardError() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.MockCommandLineCommands = "/C Echo 'Who made you king anyways' 1>&2"; Assert.True(t.Execute()); engine.AssertLogDoesntContain("MSB"); engine.AssertLogContains("Who made you king anyways"); Assert.Equal(0, t.ExitCode); Assert.Equal(0, engine.Errors); } }
public void ErrorWhenTextSentToStandardError() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.LogStandardErrorAsError = true; t.MockCommandLineCommands = "/C Echo 'Who made you king anyways' 1>&2"; Assert.IsFalse(t.Execute()); engine.AssertLogDoesntContain("MSB3073"); engine.AssertLogContains("Who made you king anyways"); Assert.AreEqual(-1, t.ExitCode); Assert.AreEqual(1, engine.Errors); } }
public void DoNotErrorWhenTextSentToStandardError() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.MockCommandLineCommands = NativeMethodsShared.IsWindows ? "/C Echo 'Who made you king anyways' 1>&2" : @"-c """"""echo Who made you king anyways 1>&2"""""""; t.Execute().ShouldBeTrue(); engine.AssertLogDoesntContain("MSB"); engine.AssertLogContains("Who made you king anyways"); t.ExitCode.ShouldBe(0); engine.Errors.ShouldBe(0); } }
public void EnvironmentVariablesToToolTaskNotSet() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); task.EnvironmentVariables = null; bool result = task.Execute(); Assert.Equal(true, result); Assert.Equal(true, task.ExecuteCalled); Assert.Equal( true, #if FEATURE_PROCESSSTARTINFO_ENVIRONMENT task.StartInfo.Environment["PATH"].Length > 0); #else task.StartInfo.EnvironmentVariables["PATH"].Length > 0); #endif }
public void HandleExecutionErrorsWhenToolDoesntLogError() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.MockCommandLineCommands = "/C garbagegarbagegarbagegarbage.exe"; Assert.False(t.Execute()); Assert.Equal(1, t.ExitCode); // cmd.exe error code is 1 // We just tried to run "cmd.exe /C garbagegarbagegarbagegarbage.exe". This should fail, // but since "cmd.exe" doesn't log its errors in canonical format, no errors got // logged by the tool itself. Therefore, ToolTask's default implementation of // HandleTaskExecutionErrors should have logged error MSB6006. engine.AssertLogContains("MSB6006"); } }
public void HandleExecutionErrorsWhenToolLogsError() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.MockCommandLineCommands = "/C echo Main.cs(17,20): error CS0168: The variable 'foo' is declared but never used"; Assert.False(t.Execute()); // The above command logged a canonical error message. Therefore ToolTask should // not log its own error beyond that. engine.AssertLogDoesntContain("MSB6006"); engine.AssertLogContains("CS0168"); engine.AssertLogContains("The variable 'foo' is declared but never used"); Assert.Equal(-1, t.ExitCode); Assert.Equal(1, engine.Errors); } }
public void DoNotErrorWhenTextSentToStandardOutput() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.LogStandardErrorAsError = true; t.MockCommandLineCommands = NativeMethodsShared.IsWindows ? "/C Echo 'Who made you king anyways'" : @"-c """"""echo Who made you king anyways"""""""; Assert.True(t.Execute()); engine.AssertLogDoesntContain("MSB"); engine.AssertLogContains("Who made you king anyways"); Assert.Equal(0, t.ExitCode); Assert.Equal(0, engine.Errors); } }
public void EnvironmentVariablesToToolTask() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); string userVarName = NativeMethodsShared.IsWindows ? "username" : "user"; task.EnvironmentVariables = new string[] { "a=b", "c=d", userVarName + "=x" /* built-in */, "path=" /* blank value */ }; bool result = task.Execute(); Assert.Equal(true, result); Assert.Equal(true, task.ExecuteCalled); ProcessStartInfo startInfo = task.StartInfo; #if FEATURE_PROCESSSTARTINFO_ENVIRONMENT Assert.Equal("b", startInfo.Environment["a"]); Assert.Equal("d", startInfo.Environment["c"]); Assert.Equal("x", startInfo.Environment[userVarName]); Assert.Equal(String.Empty, startInfo.Environment["path"]); #else Assert.Equal("b", startInfo.EnvironmentVariables["a"]); Assert.Equal("d", startInfo.EnvironmentVariables["c"]); Assert.Equal("x", startInfo.EnvironmentVariables[userVarName]); Assert.Equal(String.Empty, startInfo.EnvironmentVariables["path"]); #endif if (NativeMethodsShared.IsWindows) { Assert.Equal( #if FEATURE_SPECIAL_FOLDERS Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), #else FileUtilities.GetFolderPath(FileUtilities.SpecialFolder.ProgramFiles), #endif #if FEATURE_PROCESSSTARTINFO_ENVIRONMENT startInfo.Environment["programfiles"], #else startInfo.EnvironmentVariables["programfiles"], #endif true); } }
public void EnvironmentVariablesToToolTask() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); task.EnvironmentVariables = new string[] { "a=b", "c=d", "username=x" /* built-in */, "path=" /* blank value */ }; bool result = task.Execute(); Assert.Equal(true, result); Assert.Equal(true, task.ExecuteCalled); ProcessStartInfo startInfo = task.StartInfo; Assert.Equal("b", startInfo.EnvironmentVariables["a"]); Assert.Equal("d", startInfo.EnvironmentVariables["c"]); Assert.Equal("x", startInfo.EnvironmentVariables["username"]); Assert.Equal(String.Empty, startInfo.EnvironmentVariables["path"]); Assert.True(String.Equals(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), startInfo.EnvironmentVariables["programfiles"], StringComparison.OrdinalIgnoreCase)); }
public void Regress_Mutation_WarnIfCommandLineTooLong() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; // "cmd.exe" croaks big-time when given a very long command-line. It pops up a message box on // Windows XP. We can't have that! So use "attrib.exe" for this exercise instead. t.FullToolName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "attrib.exe"); t.MockCommandLineCommands = new String('x', 32001); // It's only a warning, we still succeed Assert.True(t.Execute()); Assert.Equal(0, t.ExitCode); // There should be a warning about the command-line being too long. engine.AssertLogContains("MSB6002"); } }
public void GetProcessStartInfoCanOverrideEnvironmentVariables() { MyTool task = new MyTool(); #if FEATURE_PROCESSSTARTINFO_ENVIRONMENT task.DoProcessStartInfoMutation = (p) => p.Environment.Remove("a"); #else task.DoProcessStartInfoMutation = (p) => p.EnvironmentVariables.Remove("a"); #endif task.BuildEngine = new MockEngine(); task.EnvironmentVariables = new string[] { "a=b" }; bool result = task.Execute(); Assert.Equal(true, result); #if FEATURE_PROCESSSTARTINFO_ENVIRONMENT Assert.Equal(false, task.StartInfo.Environment.ContainsKey("a")); #else Assert.Equal(false, task.StartInfo.EnvironmentVariables.ContainsKey("a")); #endif }
public void ToolTaskCanChangeCanonicalErrorFormat() { string tempFile = FileUtilities.GetTemporaryFile(); File.WriteAllText(tempFile, @" Main.cs(17,20): warning CS0168: The variable 'foo' is declared but never used. BADTHINGHAPPENED: This is my custom error format that's not in canonical error format. "); using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; // The command we're giving is the command to spew the contents of the temp // file we created above. t.MockCommandLineCommands = "/C type \"" + tempFile + "\""; t.Execute(); // The above command logged a canonical warning, as well as a custom error. engine.AssertLogContains("CS0168"); engine.AssertLogContains("The variable 'foo' is declared but never used"); engine.AssertLogContains("BADTHINGHAPPENED"); engine.AssertLogContains("This is my custom error format"); Assert.AreEqual(1, engine.Warnings, "Expected one warning in log."); Assert.AreEqual(1, engine.Errors, "Expected one error in log."); } File.Delete(tempFile); }
public void Regress_Mutation_WarnIfCommandLineTooLong() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; // "cmd.exe" croaks big-time when given a very long command-line. It pops up a message box on // Windows XP. We can't have that! So use "attrib.exe" for this exercise instead. t.FullToolName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "attrib.exe"); t.MockCommandLineCommands = new String('x', 32001); // It's only a warning, we still succeed Assert.IsTrue(t.Execute()); Assert.AreEqual(0, t.ExitCode); // There should be a warning about the command-line being too long. engine.AssertLogContains("MSB6002"); } }
public void TaskNotFoundOnPath() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.FullToolName = "doesnotexist.exe"; Assert.IsFalse(t.Execute()); Assert.AreEqual(-1, t.ExitCode); Assert.AreEqual(1, engine.Errors); // Does not throw an exception } }
public void EnvironmentVariablesToToolTaskInvalid3() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); task.EnvironmentVariables = new string[] { "=a;b=c" }; bool result = task.Execute(); Assert.AreEqual(false, result); Assert.AreEqual(false, task.ExecuteCalled); }
public void HandleExecutionErrorsWhenToolDoesntLogError() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.MockCommandLineCommands = "/C garbagegarbagegarbagegarbage.exe"; Assert.IsFalse(t.Execute()); Assert.AreEqual(1, t.ExitCode); // cmd.exe error code is 1 // We just tried to run "cmd.exe /C garbagegarbagegarbagegarbage.exe". This should fail, // but since "cmd.exe" doesn't log its errors in canonical format, no errors got // logged by the tool itself. Therefore, ToolTask's default implementation of // HandleTaskExecutionErrors should have logged error MSB6006. engine.AssertLogContains("MSB6006"); } }
public void ToolExeIsFoundOnToolPath() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.FullToolName = "cmd.exe"; string systemPath = Environment.GetFolderPath(Environment.SpecialFolder.System); t.ToolPath = systemPath; t.Execute(); Assert.AreEqual(Path.Combine(systemPath, "cmd.exe"), t.PathToToolUsed); engine.AssertLogContains("cmd.exe"); engine.Log = String.Empty; t.ToolExe = "xcopy.exe"; t.Execute(); Assert.AreEqual(Path.Combine(systemPath, "xcopy.exe"), t.PathToToolUsed); engine.AssertLogContains("xcopy.exe"); engine.AssertLogDoesntContain("cmd.exe"); } }
public void EnvironmentVariablesToToolTaskNotSet() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); task.EnvironmentVariables = null; bool result = task.Execute(); Assert.AreEqual(true, result); Assert.AreEqual(true, task.ExecuteCalled); Assert.AreEqual(true, task.StartInfo.EnvironmentVariables["username"].Length > 0); }
public void HandleExecutionErrorsWhenToolLogsError() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.MockCommandLineCommands = "/C echo Main.cs(17,20): error CS0168: The variable 'foo' is declared but never used"; Assert.IsFalse(t.Execute()); // The above command logged a canonical error message. Therefore ToolTask should // not log its own error beyond that. engine.AssertLogDoesntContain("MSB6006"); engine.AssertLogContains("CS0168"); engine.AssertLogContains("The variable 'foo' is declared but never used"); Assert.AreEqual(-1, t.ExitCode); Assert.AreEqual(1, engine.Errors); } }
public void OverrideStdOutImportanceToHigh() { string tempFile = FileUtilities.GetTemporaryFile(); File.WriteAllText(tempFile, @"hello world"); using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); engine.MinimumMessageImportance = MessageImportance.High; t.BuildEngine = engine; t.FullToolName = "find.exe"; t.MockCommandLineCommands = "\"hello\" \"" + tempFile + "\""; t.StandardOutputImportance = "High"; Assert.IsTrue(t.Execute()); Assert.AreEqual(0, t.ExitCode); Assert.AreEqual(0, engine.Errors); engine.AssertLogContains("hello world"); } File.Delete(tempFile); }
public void TaskFoundOnPath() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.FullToolName = "cmd.exe"; Assert.IsTrue(t.Execute()); Assert.AreEqual(0, t.ExitCode); Assert.AreEqual(0, engine.Errors); engine.AssertLogContains(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "cmd.exe")); } }
public void EnvironmentVariablesToToolTaskEqualsSign() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); task.EnvironmentVariables = new string[] { "a=b=c" }; bool result = task.Execute(); Assert.AreEqual(true, result); Assert.AreEqual("b=c", task.StartInfo.EnvironmentVariables["a"]); }
public void Regress_Mutation_MissingExecutableIsLogged() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.ToolPath = @"C:\MyAlternatePath"; Assert.IsFalse(t.Execute()); // There should be an error about invalid task location. engine.AssertLogContains("MSB6004"); } }
public void EnvironmentVariablesToToolTask() { MyTool task = new MyTool(); task.BuildEngine = new MockEngine(); task.EnvironmentVariables = new string[] { "a=b", "c=d", "username=x" /* built-in */, "path=" /* blank value */}; bool result = task.Execute(); Assert.AreEqual(true, result); Assert.AreEqual(true, task.ExecuteCalled); ProcessStartInfo startInfo = task.StartInfo; Assert.AreEqual("b", startInfo.EnvironmentVariables["a"]); Assert.AreEqual("d", startInfo.EnvironmentVariables["c"]); Assert.AreEqual("x", startInfo.EnvironmentVariables["username"]); Assert.AreEqual(String.Empty, startInfo.EnvironmentVariables["path"]); Assert.IsTrue(String.Equals(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), startInfo.EnvironmentVariables["programfiles"], StringComparison.OrdinalIgnoreCase)); }
public void DoNotFormatTaskCommandOrMessage() { MyTool t = new MyTool(); MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.MockCommandLineCommands = "/C echo hello world {"; // Unmatched curly would crash if they did t.Execute(); engine.AssertLogContains("echo hello world {"); Assert.AreEqual(0, engine.Errors); }
public void DoNotErrorWhenTextSentToStandardOutput() { using (MyTool t = new MyTool()) { MockEngine engine = new MockEngine(); t.BuildEngine = engine; t.LogStandardErrorAsError = true; t.MockCommandLineCommands = "/C Echo 'Who made you king anyways'"; Assert.True(t.Execute()); engine.AssertLogDoesntContain("MSB"); engine.AssertLogContains("Who made you king anyways"); Assert.Equal(0, t.ExitCode); Assert.Equal(0, engine.Errors); } }