예제 #1
0
        //[Fact]
        //public void PageCommand_Huge()
        //{
        //    HugeFileCompare(@"<huge file path>", 1000000, 100);
        //}

        // Use for manual verification of files over 2GB and other real life examples which can't be checked in.
        private static void HugeFileCompare(string sourceFilePath, int index, int count)
        {
            string expectPath           = Path.ChangeExtension(sourceFilePath, ".Paged.Expect.sarif");
            string actualPath           = Path.ChangeExtension(sourceFilePath, ".Paged.Actual.sarif");
            string actualUnindentedPath = Path.ChangeExtension(sourceFilePath, ".Paged.Actual.Unformatted.sarif");

            // Page with the Command
            PageCommand command = new PageCommand();

            command.RunWithoutCatch(new PageOptions()
            {
                InputFilePath = sourceFilePath, OutputFilePath = actualUnindentedPath, Index = index, Count = count
            });

            // Indent the Paged output
            Indent(actualUnindentedPath, actualPath);

            // Page with JsonTextReader/Writer
            PageManual(sourceFilePath, expectPath, index, count);

            // Compare files
            string actualText   = File.ReadAllText(actualPath);
            string expectedText = File.ReadAllText(expectPath);
            string diffCommand  = $"windiff \"{Path.GetFullPath(expectPath)}\" \"{Path.GetFullPath(actualPath)}\"";

            Assert.True(actualText == expectedText, $"Sarif Page result ({index}, {count}) didn't match.\r\nSee: {diffCommand}");
            //Assert.Equal(expectedText, actualText);
        }
예제 #2
0
        public void PageCommand_Basics()
        {
            string sampleFilePath  = "elfie-arriba.sarif";
            string pagedSamplePath = "elfie-arriba.paged.sarif";

            File.WriteAllText(sampleFilePath, Extractor.GetResourceText(@"PageCommand.elfie-arriba.sarif"));

            // Normal file, valid subsets
            RunAndCompare(new PageOptions()
            {
                Index = 1, Count = 2, InputFilePath = sampleFilePath, OutputFilePath = pagedSamplePath
            });
            RunAndCompare(new PageOptions()
            {
                Index = 0, Count = 5, InputFilePath = sampleFilePath, OutputFilePath = pagedSamplePath
            });
            RunAndCompare(new PageOptions()
            {
                Index = 3, Count = 0, InputFilePath = sampleFilePath, OutputFilePath = pagedSamplePath
            });
            RunAndCompare(new PageOptions()
            {
                Index = 3, Count = 2, InputFilePath = sampleFilePath, OutputFilePath = pagedSamplePath
            });

            string      minifiedPath = "elfie-arriba.min.sarif";
            IFileSystem fileSystem   = new FileSystem();
            SarifLog    log          = PageCommand.ReadSarifFile <SarifLog>(fileSystem, sampleFilePath);

            PageCommand.WriteSarifFile(fileSystem, log, minifiedPath, Formatting.None);

            // Minified file, valid subsets
            RunAndCompare(new PageOptions()
            {
                Index = 1, Count = 2, InputFilePath = minifiedPath, OutputFilePath = pagedSamplePath
            });
            RunAndCompare(new PageOptions()
            {
                Index = 0, Count = 5, InputFilePath = minifiedPath, OutputFilePath = pagedSamplePath
            });
            RunAndCompare(new PageOptions()
            {
                Index = 3, Count = 0, InputFilePath = minifiedPath, OutputFilePath = pagedSamplePath
            });
            RunAndCompare(new PageOptions()
            {
                Index = 3, Count = 2, InputFilePath = minifiedPath, OutputFilePath = pagedSamplePath
            });
        }
예제 #3
0
        public void PageCommand_StaticOptionValidation()
        {
            var failedTestCases = new List <string>();

            foreach (StaticValidationTestCase testCase in s_validationTestCases)
            {
                var mockFileSystem = new Mock <IFileSystem>();
                mockFileSystem.Setup(x => x.FileExists(InputFilePath)).Returns(testCase.InputFileExists);
                mockFileSystem.Setup(x => x.FileExists(OutputFilePath)).Returns(testCase.OutputFileExists);
                IFileSystem fileSystem = mockFileSystem.Object;

                var command = new PageCommand();
                if (command.ValidateOptions(testCase.Options, fileSystem) != testCase.ExpectedReturnValue)
                {
                    failedTestCases.Add(testCase.Title);
                }
            }

            failedTestCases.Should().BeEmpty();
        }
예제 #4
0
        private static void RunAndCompare(PageOptions options)
        {
            IFileSystem fileSystem = new FileSystem();
            string      actualPath = Path.ChangeExtension(options.OutputFilePath, "act.json");
            string      expectPath = Path.ChangeExtension(options.OutputFilePath, "exp.json");

            File.Delete(Path.ChangeExtension(options.InputFilePath, ".map.json"));
            File.Delete(options.OutputFilePath);

            // Reset default target size ratio so that a map is built for file
            if (options.TargetMapSizeRatio == 0.01)
            {
                options.TargetMapSizeRatio = 0.10;
            }

            // Run the normal Page command
            PageCommand command = new PageCommand(fileSystem);

            command.RunWithoutCatch(options);

            // Rewrite indented
            SarifLog actual = PageCommand.ReadSarifFile <SarifLog>(fileSystem, options.OutputFilePath);

            PageCommand.WriteSarifFile(fileSystem, actual, actualPath, Formatting.Indented);

            // Run "Page via OM"
            SarifLog expected = command.PageViaOm(options);

            PageCommand.WriteSarifFile(fileSystem, expected, expectPath, Formatting.Indented);

            string actualText   = File.ReadAllText(actualPath);
            string expectedText = File.ReadAllText(expectPath);
            string diffCommand  = $"windiff \"{Path.GetFullPath(expectPath)}\" \"{Path.GetFullPath(actualPath)}\"";

            Assert.True(actualText == expectedText, $"Sarif Page result ({options.Index}, {options.Count}) didn't match.\r\nSee: {diffCommand}");
            //Assert.Equal(expectedText, actualText);
        }