public void ConvertCommand_SemmleQlExample()
        {
            // Try converting a tiny sample SemmleQl file
            string sampleFilePath = "SemmleQlSample.csv";
            string outputFilePath = Path.ChangeExtension(sampleFilePath, ".sarif");

            File.WriteAllText(sampleFilePath, Extractor.GetResourceText($"ConvertCommand.{sampleFilePath}"));

            var options = new ConvertOptions
            {
                ToolFormat     = ToolFormat.SemmleQL,
                InputFilePath  = sampleFilePath,
                OutputFilePath = outputFilePath,
                Force          = true
            };

            // Verify command returned success
            int returnCode = new ConvertCommand().Run(options);

            returnCode.Should().Be(0);

            // Verify SARIF output log exists
            File.Exists(outputFilePath).Should().BeTrue();

            // Verify log loads, has correct Result count, and spot check a Result
            SarifLog log = SarifLog.Load(outputFilePath);

            log.Runs[0].Results.Count.Should().Be(8);
            log.Runs[0].Results[7].Locations[0].PhysicalLocation.Region.StartLine.Should().Be(40);
            log.Runs[0].Results[7].Locations[0].PhysicalLocation.Region.StartColumn.Should().Be(43);
        }
Example #2
0
 /// <summary>The entry point for the SARIF multi utility.</summary>
 /// <param name="args">Arguments passed in from the tool's command line.</param>
 /// <returns>0 on success; nonzero on failure.</returns>
 public static int Main(string[] args)
 {
     return(Parser.Default.ParseArguments <
                ValidateOptions,
                ConvertOptions,
                RewriteOptions,
                TransformOptions,
                MergeOptions,
                RebaseUriOptions,
                AbsoluteUriOptions,
                PageOptions,
                QueryOptions,
                ResultMatchingOptions,
                ResultMatchSetOptions>(args)
            .MapResult(
                (ValidateOptions validateOptions) => new ValidateCommand().Run(validateOptions),
                (ConvertOptions convertOptions) => ConvertCommand.Run(convertOptions),
                (RewriteOptions rewriteOptions) => new RewriteCommand().Run(rewriteOptions),
                (TransformOptions transformOptions) => new TransformCommand().Run(transformOptions),
                (MergeOptions mergeOptions) => new MergeCommand().Run(mergeOptions),
                (RebaseUriOptions rebaseOptions) => new RebaseUriCommand().Run(rebaseOptions),
                (AbsoluteUriOptions absoluteUriOptions) => new AbsoluteUriCommand().Run(absoluteUriOptions),
                (PageOptions pageOptions) => new PageCommand().Run(pageOptions),
                (QueryOptions queryOptions) => new QueryCommand().Run(queryOptions),
                (ResultMatchingOptions baselineOptions) => new ResultMatchingCommand().Run(baselineOptions),
                (ResultMatchSetOptions options) => new ResultMatchSetCommand().Run(options),
                errs => 1));
 }
Example #3
0
 /// <summary>The entry point for the SARIF multi utility.</summary>
 /// <param name="args">Arguments passed in from the tool's command line.</param>
 /// <returns>0 on success; nonzero on failure.</returns>
 public static int Main(string[] args)
 {
     return(Parser.Default.ParseArguments <
                ConvertOptions,
                RewriteOptions,
                MergeOptions>(args)
            .MapResult(
                (ConvertOptions convertOptions) => ConvertCommand.Run(convertOptions),
                (RewriteOptions rewriteOptions) => RewriteCommand.Run(rewriteOptions),
                (MergeOptions mergeOptions) => MergeCommand.Run(mergeOptions),
                errs => 1));
 }
Example #4
0
 /// <summary>The entry point for the SARIF multi utility.</summary>
 /// <param name="args">Arguments passed in from the tool's command line.</param>
 /// <returns>0 on success; nonzero on failure.</returns>
 public static int Main(string[] args)
 {
     return(Parser.Default.ParseArguments <
                ConvertOptions,
                RewriteOptions,
                MergeOptions,
                RebaseUriOptions,
                AbsoluteUriOptions,
                BaselineOptions>(args)
            .MapResult(
                (ConvertOptions convertOptions) => ConvertCommand.Run(convertOptions),
                (RewriteOptions rewriteOptions) => RewriteCommand.Run(rewriteOptions),
                (MergeOptions mergeOptions) => MergeCommand.Run(mergeOptions),
                (RebaseUriOptions rebaseOptions) => RebaseUriCommand.Run(rebaseOptions),
                (AbsoluteUriOptions absoluteUriOptions) => AbsoluteUriCommand.Run(absoluteUriOptions),
                (BaselineOptions baselineOptions) => BaselineCommand.Run(baselineOptions),
                errs => 1));
 }
Example #5
0
        public void Run_WhenOutputFileExistsAndForceNotSpecified_Fails()
        {
            const string InputFilePath  = @"C:\input\ToolOutput.xml";
            const string OutputFilePath = @"C:\output\ToolOutput.xml.sarif";

            var mockFileSystem = new Mock <IFileSystem>();

            mockFileSystem.Setup(x => x.DirectoryExists(OutputFilePath)).Returns(false);
            mockFileSystem.Setup(x => x.FileExists(OutputFilePath)).Returns(true);
            IFileSystem fileSystem = mockFileSystem.Object;

            var options = new ConvertOptions
            {
                ToolFormat     = ToolFormat.FxCop,
                InputFilePath  = InputFilePath,
                OutputFilePath = OutputFilePath
            };

            int returnCode = new ConvertCommand().Run(options, fileSystem);

            returnCode.Should().Be(1);
        }
Example #6
0
 /// <summary>The entry point for the SARIF multi utility.</summary>
 /// <param name="args">Arguments passed in from the tool's command line.</param>
 /// <returns>0 on success; nonzero on failure.</returns>
 public static int Main(string[] args)
 {
     return(Parser.Default.ParseArguments <
                ValidateOptions,
                ConvertOptions,
                RewriteOptions,
                TransformOptions,
                MergeOptions,
                RebaseUriOptions,
                AbsoluteUriOptions,
                ResultMatchingOptions>(args)
            .MapResult(
                (ValidateOptions validateOptions) => new ValidateCommand(new FileSystem()).Run(validateOptions),
                (ConvertOptions convertOptions) => ConvertCommand.Run(convertOptions),
                (RewriteOptions rewriteOptions) => RewriteCommand.Run(rewriteOptions),
                (TransformOptions transformOptions) => TransformCommand.Run(transformOptions),
                (MergeOptions mergeOptions) => MergeCommand.Run(mergeOptions),
                (RebaseUriOptions rebaseOptions) => RebaseUriCommand.Run(rebaseOptions),
                (AbsoluteUriOptions absoluteUriOptions) => AbsoluteUriCommand.Run(absoluteUriOptions),
                (ResultMatchingOptions baselineOptions) => ResultMatchingCommand.Run(baselineOptions),
                errs => 1));
 }
        public void Run_WhenOutputFormatOptionsAreInconsistent_Fails()
        {
            // Run on the same sample file that succeeded in the test ConvertCommand_SemmleQlExample.
            // This time we expect it to fail because of the inconsistent output format options.
            string sampleFilePath = "SemmleQlSample.csv";
            string outputFilePath = Path.ChangeExtension(sampleFilePath, ".sarif");

            File.WriteAllText(sampleFilePath, Extractor.GetResourceText($"ConvertCommand.{sampleFilePath}"));

            var options = new ConvertOptions
            {
                ToolFormat     = ToolFormat.SemmleQL,
                InputFilePath  = sampleFilePath,
                OutputFilePath = outputFilePath,
                Force          = true,
                PrettyPrint    = true,
                Minify         = true
            };

            int returnCode = new ConvertCommand().Run(options);

            returnCode.Should().Be(1);
        }