Ejemplo n.º 1
0
        [WorkItem(72)] // Regression test for bug #72: CodeCoverage conversion - conversion errors should be detected and reported
        public void Conv_OutputIsCaptured()
        {
            // Arrange
            var logger  = new TestLogger();
            var testDir = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext);

            var outputFilePath = Path.Combine(testDir, "output.txt");

            var inputFilePath = Path.Combine(testDir, "input.txt");

            File.WriteAllText(inputFilePath, "dummy input file");

            var converterFilePath = Path.Combine(testDir, "converter.bat");

            File.WriteAllText(converterFilePath,
                              @"
echo Normal output...
echo Error output...>&2
echo Create a new file using the output parameter
echo foo > """ + outputFilePath + @"""");

            // Act
            var success = BinaryToXmlCoverageReportConverter.ConvertBinaryToXml(converterFilePath, inputFilePath, outputFilePath, logger);

            // Assert
            success.Should().BeTrue("Expecting the process to succeed");

            File.Exists(outputFilePath).Should().BeTrue("Expecting the output file to exist");
            TestContext.AddResultFile(outputFilePath);

            logger.AssertMessageLogged("Normal output...");
            logger.AssertErrorLogged("Error output...");
        }
        [WorkItem(72)] // Regression test for bug #72: CodeCoverage conversion - conversion errors should be detected and reported
        public void Conv_OutputIsCaptured()
        {
            // Arrange
            TestLogger logger  = new TestLogger();
            string     testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            string outputFilePath = Path.Combine(testDir, "output.txt");

            string inputFilePath = Path.Combine(testDir, "input.txt");

            File.WriteAllText(inputFilePath, "dummy input file");

            string converterFilePath = Path.Combine(testDir, "converter.bat");

            File.WriteAllText(converterFilePath,
                              @"
echo Normal output...
echo Error output...>&2
echo Create a new file using the output parameter
echo foo > """ + outputFilePath + @"""");

            // Act
            bool success = CoverageReportConverter.ConvertBinaryToXml(converterFilePath, inputFilePath, outputFilePath, logger);

            // Assert
            Assert.IsTrue(success, "Expecting the process to succeed");

            Assert.IsTrue(File.Exists(outputFilePath), "Expecting the output file to exist");
            this.TestContext.AddResultFile(outputFilePath);

            logger.AssertMessageLogged("Normal output...");
            logger.AssertErrorLogged("Error output...");
        }
        public void Exe_PreProc_UrlIsRequired()
        {
            // Arrange
            BootstrapperTestUtils.EnsureDefaultPropertiesFileDoesNotExist();
            string rootDir = TestUtils.CreateTestSpecificFolder(this.TestContext);

            using (InitializeNonTeamBuildEnvironment(rootDir))
            {
                string binDir = CalculateBinDir(rootDir);

                MockBuildAgentUpdater mockUpdater = new MockBuildAgentUpdater();

                // Act
                TestLogger logger = CheckExecutionFails(mockUpdater, "begin");

                // Assert
                mockUpdater.AssertUpdateNotAttempted();
                mockUpdater.AssertVersionNotChecked();

                AssertDirectoryDoesNotExist(binDir);

                logger.AssertErrorLogged(SonarQube.Bootstrapper.Resources.ERROR_Args_UrlRequired);
                logger.AssertErrorsLogged(1);
            }
        }
Ejemplo n.º 4
0
        public void ParseInvalidJson()
        {
            var logger = new TestLogger();

            Environment.SetEnvironmentVariable("SONARQUBE_SCANNER_PARAMS", "trash");
            var result = EnvScannerPropertiesProvider.TryCreateProvider(logger, out IAnalysisPropertyProvider provider);

            Assert.IsFalse(result);
            logger.AssertErrorLogged("Failed to parse properties from the environment variable 'SONARQUBE_SCANNER_PARAMS'");
        }
        public void ParseInvalidJson()
        {
            var logger = new TestLogger();

            // Make sure the test isn't affected by the hosting environment and
            // does not affect the hosting environment
            // The SonarCloud VSTS extension sets additional properties in an environment variable that
            // would affect the test.
            using (var scope = new EnvironmentVariableScope())
            {
                scope.SetVariable("SONARQUBE_SCANNER_PARAMS", "trash");
                var result = EnvScannerPropertiesProvider.TryCreateProvider(logger, out var provider);
                result.Should().BeFalse();
                logger.AssertErrorLogged("Failed to parse properties from the environment variable 'SONARQUBE_SCANNER_PARAMS'");
            }
        }
        private static void VerifyProcessRunOutcome(MockProcessRunner mockRunner, TestLogger testLogger, string expectedWorkingDir, bool actualOutcome, bool expectedOutcome)
        {
            actualOutcome.Should().Be(expectedOutcome);

            mockRunner.SuppliedArguments.WorkingDirectory.Should().Be(expectedWorkingDir);

            if (actualOutcome)
            {
                // Errors can still be logged when the process completes successfully, so
                // we don't check the error log in this case
                testLogger.AssertInfoMessageExists(Resources.MSG_TFSProcessorCompleted);
            }
            else
            {
                testLogger.AssertErrorsLogged();
                testLogger.AssertErrorLogged(Resources.ERR_TFSProcessorExecutionFailed);
            }
        }
        public void ProcRunner_ExecutionSucceeded()
        {
            // Arrange
            var exeName = TestUtils.WriteBatchFileForTest(TestContext,
                                                          @"@echo Hello world
xxx yyy
@echo Testing 1,2,3...>&2
");

            var logger = new TestLogger();
            var args   = new ProcessRunnerArguments(exeName, true);
            var runner = new ProcessRunner(logger);

            // Act
            var success = runner.Execute(args);

            // Assert
            Assert.IsTrue(success, "Expecting the process to have succeeded");
            Assert.AreEqual(0, runner.ExitCode, "Unexpected exit code");

            logger.AssertMessageLogged("Hello world");    // Check output message are passed to the logger
            logger.AssertErrorLogged("Testing 1,2,3..."); // Check error messages are passed to the logger
        }
        public void ProcRunner_ExecutionSucceeded()
        {
            // Arrange
            string exeName = WriteBatchFileForTest(
                @"@echo Hello world
xxx yyy
@echo Testing 1,2,3...
");

            TestLogger    logger = new TestLogger();
            ProcessRunner runner = new ProcessRunner();

            // Act
            bool success = runner.Execute(exeName, null, null, 1000, logger);

            // Assert
            Assert.IsTrue(success, "Expecting the process to have succeeded");
            Assert.AreEqual(0, runner.ExitCode, "Unexpected exit code");

            logger.AssertMessageLogged("Hello world");                                               // Check output message are passed to the logger
            logger.AssertMessageLogged("Testing 1,2,3...");
            logger.AssertErrorLogged("'xxx' is not recognized as an internal or external command,"); // Check error messages are passed to the logger
        }