private void BatchRunConverter(ToolFormat tool, string inputFilter) { var sb = new StringBuilder(); string toolName = Enum.GetName(typeof(ToolFormat), tool); string testDirectory = SarifConverterTests.TestDirectory + "\\" + toolName; string[] testFiles = Directory.GetFiles(testDirectory, inputFilter); foreach (string file in testFiles) { RunConverter(sb, tool, file); } if (sb.Length == 0) { // Test passes return; } string rebaselineMessage = "If the actual output is expected, generate new baselines for {0} by executing `UpdateBaselines.ps1 {0}` from a CBT command prompt, or `UpdateBaselines.ps1` to update baselines for all tools."; sb.AppendLine(String.Format(CultureInfo.CurrentCulture, rebaselineMessage, toolName)); Assert.Fail(sb.ToString()); }
private void BatchRunConverter(ToolFormat tool, string inputFilter) { var sb = new StringBuilder(); string toolName = Enum.GetName(typeof(ToolFormat), tool); string testDirectory = SarifConverterTests.TestDirectory + "\\" + toolName; string[] testFiles = Directory.GetFiles(testDirectory, inputFilter); foreach (string file in testFiles) { RunConverter(sb, tool, file); } sb.Length.Should().Be(0, FormatFailureReason(sb, toolName)); }
private void RunConverter(StringBuilder sb, ToolFormat tool, string inputFileName) { string expectedFileName = inputFileName + ".sarif"; string generatedFileName = inputFileName + ".actual.sarif"; try { this.converter.ConvertToStandardFormat(tool, inputFileName, generatedFileName, ToolFormatConversionOptions.OverwriteExistingOutputFile | ToolFormatConversionOptions.PrettyPrint); } catch (Exception ex) { sb.AppendLine(String.Format(CultureInfo.InvariantCulture, "The converter {0} threw an exception for input \"{1}\".", tool, inputFileName)); sb.AppendLine(ex.ToString()); return; } string expectedSarif = File.ReadAllText(expectedFileName); string actualSarif = File.ReadAllText(generatedFileName); if (expectedSarif == actualSarif) { JsonSerializerSettings settings = new JsonSerializerSettings() { ContractResolver = SarifContractResolver.Instance, Formatting = Formatting.Indented }; // Make sure we can successfully deserialize what was just generated SarifLog log = JsonConvert.DeserializeObject <SarifLog>(actualSarif, settings); actualSarif = JsonConvert.SerializeObject(log, settings); if (expectedSarif == actualSarif) { return; } else { File.WriteAllText(generatedFileName, actualSarif); } } string errorMessage = "The output of the {0} converter did not match for input {1}."; sb.AppendLine(String.Format(CultureInfo.CurrentCulture, errorMessage, tool, inputFileName)); sb.AppendLine("Check differences with:"); sb.AppendLine(GenerateDiffCommand(expectedFileName, generatedFileName)); }
private void BatchRunConverter(ToolFormat tool) { BatchRunConverter(tool, "*.xml"); }