Пример #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...");
        }
Пример #2
0
        [WorkItem(145)] // Regression test for bug #145: Poor UX if the code coverage report could not be converted to XML
        public void Conv_FailsIfFileConverterReturnsAnErrorCode()
        {
            // 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, @"exit -1");

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

            // Assert
            success.Should().BeFalse("Expecting the process to fail");
            logger.AssertErrorsLogged();
            logger.AssertSingleErrorExists(inputFilePath); // error message should refer to the input file

            File.Exists(outputFilePath).Should().BeFalse("Not expecting the output file to exist");
        }
Пример #3
0
        public void Conv_HasThreeArguments()
        {
            // 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,
                              @"
set argC=0
for %%x in (%*) do Set /A argC+=1

echo Converter called with %argC% args
echo success > """ + outputFilePath + @"""");

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

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

            logger.AssertMessageLogged("Converter called with 3 args");
        }
Пример #4
0
        [WorkItem(72)] // Regression test for bug #72: fail the conversion if the output file is not created
        public void Conv_FailsIfFileNotFound()
        {
            // Arrange
            var logger  = new TestLogger();
            var testDir = TestUtils.CreateTestSpecificFolder(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, @"REM Do nothing - don't create a file");

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

            // Assert
            Assert.IsFalse(success, "Expecting the process to fail");
            logger.AssertErrorsLogged();
            logger.AssertSingleErrorExists(outputFilePath); // error message should refer to the output file

            Assert.IsFalse(File.Exists(outputFilePath), "Not expecting the output file to exist");
        }