[WorkItem(50)] // Regression test for Bug 50:MSBuild projects with missing ProjectGuids cause the build to fail public void WriteProjectInfoFile_MissingProjectGuid() { // Arrange string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext); WriteProjectInfoFile task = new WriteProjectInfoFile { FullProjectPath = "c:\\fullPath\\project.proj", IsTest = true, OutputFolder = testFolder, ProjectName = "ProjectWithoutProjectGuid", ProjectLanguage = "C#" }; // No analysis results are supplied // Act DummyBuildEngine engine = new DummyBuildEngine(); task.BuildEngine = engine; bool success = task.Execute(); // Assert Assert.IsTrue(success, "Not expecting the task to fail as this would fail the build"); engine.AssertNoErrors(); Assert.AreEqual(1, engine.Warnings.Count, "Expecting a build warning as the ProjectGuid is missing"); BuildWarningEventArgs firstWarning = engine.Warnings[0]; Assert.IsNotNull(firstWarning.Message, "Warning message should not be null"); string projectInfoFilePath = Path.Combine(testFolder, ExpectedProjectInfoFileName); Assert.IsFalse(File.Exists(projectInfoFilePath), "Not expecting the project info file to have been created"); }
private static void ExecuteAndCheckSuccess(Task task) { var dummyEngine = new DummyBuildEngine(); task.BuildEngine = dummyEngine; var taskSucess = task.Execute(); Assert.IsTrue(taskSucess, "Expecting the task to succeed"); dummyEngine.AssertNoErrors(); dummyEngine.AssertNoWarnings(); }
private void ExecuteAndCheckSuccess(string primaryRuleset, params string[] rulesetsToInclude) { this.TestContext.AddResultFile(primaryRuleset); DummyBuildEngine dummyEngine = new DummyBuildEngine(); MergeRuleSets task = CreateTask(dummyEngine, primaryRuleset, rulesetsToInclude); bool taskSucess = task.Execute(); Assert.IsTrue(taskSucess, "Expecting the task to succeed"); dummyEngine.AssertNoErrors(); dummyEngine.AssertNoWarnings(); }
[TestCategory("IsTest")] // Regression test for bug http://jira.codehaus.org/browse/SONARMSBRU-11 public void IsTestFile_RetryIfConfigLocked() { // Arrange // We'll lock the file and sleep for long enough for the retry period to occur, but // not so long that the task times out int lockPeriodInMilliseconds = 1000; Assert.IsTrue(lockPeriodInMilliseconds < IsTestFileByName.MaxConfigRetryPeriodInMilliseconds, "Test setup error: the test is sleeping for too long"); string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext); string configFile = EnsureAnalysisConfig(testFolder, ".XX."); DummyBuildEngine dummyEngine = new DummyBuildEngine(); IsTestFileByName task = new IsTestFileByName(); task.BuildEngine = dummyEngine; task.FullFilePath = "XXX.proj"; task.AnalysisConfigDir = testFolder; bool result; Stopwatch testDuration = Stopwatch.StartNew(); using (FileStream lockingStream = File.OpenWrite(configFile)) { System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.Sleep(lockPeriodInMilliseconds); // unlock the file after a short delay lockingStream.Close(); }); result = task.Execute(); } testDuration.Stop(); Assert.IsTrue(testDuration.ElapsedMilliseconds > 1000, "Test error: expecting the test to have taken at least {0} milliseconds to run. Actual: {1}", lockPeriodInMilliseconds, testDuration.ElapsedMilliseconds); Assert.IsTrue(result, "Expecting the task to succeed"); Assert.IsTrue(task.IsTest, "Expecting the file to be recognised as a test"); dummyEngine.AssertMessageExists(IsTestFileByName.MaxConfigRetryPeriodInMilliseconds.ToString(), IsTestFileByName.DelayBetweenRetriesInMilliseconds.ToString()); dummyEngine.AssertNoErrors(); dummyEngine.AssertNoWarnings(); }
private static bool ExecuteAndCheckSuccess(string analysisDir, string fullFileName) { DummyBuildEngine dummyEngine = new DummyBuildEngine(); IsTestFileByName task = new IsTestFileByName(); task.BuildEngine = dummyEngine; task.FullFilePath = fullFileName; task.AnalysisConfigDir = analysisDir; bool taskSucess = task.Execute(); Assert.IsTrue(taskSucess, "Expecting the task to succeed"); dummyEngine.AssertNoErrors(); dummyEngine.AssertNoWarnings(); return(task.IsTest); }
private string ExecuteAndCheckSuccess(string projectDirectory, string primaryRuleset, params string[] rulesetsToInclude) { string mergedRulesetFileName = primaryRuleset + ".merged.txt"; DummyBuildEngine dummyEngine = new DummyBuildEngine(); MergeRuleSets task = CreateTask(dummyEngine, projectDirectory, primaryRuleset, mergedRulesetFileName, rulesetsToInclude); bool taskSucess = task.Execute(); Assert.IsTrue(taskSucess, "Expecting the task to succeed"); dummyEngine.AssertNoErrors(); dummyEngine.AssertNoWarnings(); Assert.IsTrue(File.Exists(mergedRulesetFileName), "Expecting the merged ruleset to have been created: {0}", mergedRulesetFileName); this.TestContext.AddResultFile(primaryRuleset); this.TestContext.AddResultFile(mergedRulesetFileName); return(mergedRulesetFileName); }
[WorkItem(50)] // Regression test for Bug 50:MSBuild projects with missing ProjectGuids cause the build to fail public void WriteProjectInfoFile_MissingProjectGuid() { // Arrange string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext); WriteProjectInfoFile task = new WriteProjectInfoFile(); task.FullProjectPath = "c:\\fullPath\\project.proj"; task.IsTest = true; task.OutputFolder = testFolder; task.ProjectName = "ProjectWithoutProjectGuid"; task.ProjectLanguage = "C#"; // No analysis results are supplied // Act DummyBuildEngine engine = new DummyBuildEngine(); task.BuildEngine = engine; bool success = task.Execute(); // Assert Assert.IsTrue(success, "Not expecting the task to fail as this would fail the build"); engine.AssertNoErrors(); Assert.AreEqual(1, engine.Warnings.Count, "Expecting a build warning as the ProjectGuid is missing"); BuildWarningEventArgs firstWarning = engine.Warnings[0]; Assert.IsNotNull(firstWarning.Message, "Warning message should not be null"); string projectInfoFilePath = Path.Combine(testFolder, ExpectedProjectInfoFileName); Assert.IsFalse(File.Exists(projectInfoFilePath), "Not expecting the project info file to have been created"); }
private static bool ExecuteAndCheckSuccess(string analysisDir, string fullFileName) { DummyBuildEngine dummyEngine = new DummyBuildEngine(); IsTestFileByName task = new IsTestFileByName(); task.BuildEngine = dummyEngine; task.FullFilePath = fullFileName; task.AnalysisConfigDir = analysisDir; bool taskSucess = task.Execute(); Assert.IsTrue(taskSucess, "Expecting the task to succeed"); dummyEngine.AssertNoErrors(); dummyEngine.AssertNoWarnings(); return task.IsTest; }
public void AttachBW_NotAttached_ExeReturnsSuccess_TaskSucceeds() { // Arrange string binFolder = TestUtils.CreateTestSpecificFolder(this.TestContext); string configFolder = TestUtils.CreateTestSpecificFolder(this.TestContext, "config"); string outputFolder = Path.Combine(binFolder, "output"); // expected location: does not exist DummyBuildEngine dummyEngine = new DummyBuildEngine(); TaskExecutionContext taskContext = new TaskExecutionContext(binFolder, configFolder, outputFolder, 0 /* returns success code */ ); AttachBuildWrapper testSubject = CreateTestSubject(dummyEngine, binFolder, configFolder); // Act bool result = testSubject.Execute(); // Assert Assert.IsTrue(result, "Expecting task to succeed"); Assert.IsTrue(Directory.Exists(outputFolder), "Expecting the output folder to have been created"); dummyEngine.AssertNoErrors(); dummyEngine.AssertNoWarnings(); dummyEngine.AssertSingleMessageExists(SonarQube.MSBuild.Tasks.Resources.BuildWrapper_AttachedSuccessfully); // Check the parameters passed to the exe string logPath = AssertLogFileExists(taskContext); DummyExeHelper.AssertExpectedLogContents(logPath, "--msbuild-task", Process.GetCurrentProcess().Id.ToString(), outputFolder); }
private static void ExecuteAndCheckSuccess(Task task) { DummyBuildEngine dummyEngine = new DummyBuildEngine(); task.BuildEngine = dummyEngine; bool taskSucess = task.Execute(); Assert.IsTrue(taskSucess, "Expecting the task to succeed"); dummyEngine.AssertNoErrors(); dummyEngine.AssertNoWarnings(); }
public void IsTestFile_RetryIfConfigLocked() { // Arrange // We'll lock the file and sleep for long enough for the retry period to occur, but // not so long that the task times out int lockPeriodInMilliseconds = 1000; Assert.IsTrue(lockPeriodInMilliseconds < IsTestFileByName.MaxConfigRetryPeriodInMilliseconds, "Test setup error: the test is sleeping for too long"); string testFolder = TestUtils.CreateTestSpecificFolder(this.TestContext); string configFile = EnsureAnalysisConfig(testFolder, ".XX."); DummyBuildEngine dummyEngine = new DummyBuildEngine(); IsTestFileByName task = new IsTestFileByName(); task.BuildEngine = dummyEngine; task.FullFilePath = "XXX.proj"; task.AnalysisConfigDir = testFolder; bool result; Stopwatch testDuration = Stopwatch.StartNew(); using (FileStream lockingStream = File.OpenWrite(configFile)) { System.Threading.Tasks.Task.Factory.StartNew(() => { System.Threading.Thread.Sleep(lockPeriodInMilliseconds); // unlock the file after a short delay lockingStream.Close(); }); result = task.Execute(); } testDuration.Stop(); Assert.IsTrue(testDuration.ElapsedMilliseconds > 1000, "Test error: expecting the test to have taken at least {0} milliseconds to run. Actual: {1}", lockPeriodInMilliseconds, testDuration.ElapsedMilliseconds); Assert.IsTrue(result, "Expecting the task to succeed"); Assert.IsTrue(task.IsTest, "Expecting the file to be recognised as a test"); dummyEngine.AssertSingleMessageExists(IsTestFileByName.MaxConfigRetryPeriodInMilliseconds.ToString(), IsTestFileByName.DelayBetweenRetriesInMilliseconds.ToString()); dummyEngine.AssertNoErrors(); dummyEngine.AssertNoWarnings(); }
private string ExecuteAndCheckSuccess(string projectDirectory, string primaryRuleset, params string[] rulesetsToInclude) { string mergedRulesetFileName = primaryRuleset + ".merged.txt"; DummyBuildEngine dummyEngine = new DummyBuildEngine(); MergeRuleSets task = CreateTask(dummyEngine, projectDirectory, primaryRuleset, mergedRulesetFileName, rulesetsToInclude); bool taskSucess = task.Execute(); Assert.IsTrue(taskSucess, "Expecting the task to succeed"); dummyEngine.AssertNoErrors(); dummyEngine.AssertNoWarnings(); Assert.IsTrue(File.Exists(mergedRulesetFileName), "Expecting the merged ruleset to have been created: {0}", mergedRulesetFileName); this.TestContext.AddResultFile(primaryRuleset); this.TestContext.AddResultFile(mergedRulesetFileName); return mergedRulesetFileName; }