Example #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);
        }
Example #2
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);
        }