Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get v2 -> v1 transform working with files array #1211

Merged
12 commits merged into from
Jan 14, 2019
27 changes: 19 additions & 8 deletions src/Sarif.TestUtilities/FileDiffingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Reflection;
using System.Text;
using FluentAssertions;
using Microsoft.CodeAnalysis.Sarif.Readers;
using Microsoft.CodeAnalysis.Sarif.VersionOne;
using Microsoft.CodeAnalysis.Sarif.Writers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand All @@ -30,10 +32,12 @@ public static string GetProductTestDataDirectory(string subdirectory = "")
}

private readonly ITestOutputHelper _outputHelper;
private readonly bool _testProducesSarifCurrentVersion;

public FileDiffingTests(ITestOutputHelper outputHelper)
public FileDiffingTests(ITestOutputHelper outputHelper, bool testProducesSarifCurrentVersion = true)
{
_outputHelper = outputHelper;
_testProducesSarifCurrentVersion = testProducesSarifCurrentVersion;

if (Directory.Exists(OutputFolderPath))
{
Expand Down Expand Up @@ -70,20 +74,27 @@ protected virtual void RunTest(string resourceName)
var sb = new StringBuilder();

string expectedSarifText = GetResourceText("ExpectedOutputs." + resourceName);
PrereleaseCompatibilityTransformer.UpdateToCurrentVersion(expectedSarifText, forceUpdate: false, Formatting.Indented, out expectedSarifText);

if (!AreEquivalentSarifLogs<SarifLog>(actualSarifText, expectedSarifText))
bool passed;
if (_testProducesSarifCurrentVersion)
{
PrereleaseCompatibilityTransformer.UpdateToCurrentVersion(expectedSarifText, forceUpdate: false, Formatting.Indented, out expectedSarifText);
passed = AreEquivalentSarifLogs<SarifLog>(actualSarifText, expectedSarifText);
}
else
{
passed = AreEquivalentSarifLogs<SarifLogVersionOne>(actualSarifText, expectedSarifText, SarifContractResolverVersionOne.Instance);
}

if (!passed)
{
string errorMessage = string.Format(@"there should be no unexpected diffs detected comparing actual results to '{0}'.", resourceName);
sb.AppendLine(errorMessage);

if (!Utilities.RunningInAppVeyor)
{
string expectedFilePath = null;
string actualFilePath = null;

expectedFilePath = GetOutputFilePath("ExpectedOutputs", resourceName);
actualFilePath = GetOutputFilePath("ActualOutputs", resourceName);
string expectedFilePath = GetOutputFilePath("ExpectedOutputs", resourceName);
string actualFilePath = GetOutputFilePath("ActualOutputs", resourceName);

string expectedRootDirectory = Path.GetDirectoryName(expectedFilePath);
string actualRootDirectory = Path.GetDirectoryName(actualFilePath);
Expand Down
96 changes: 48 additions & 48 deletions src/Sarif.UnitTests/Sarif.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,30 @@
<ItemGroup>
<None Remove="TestData\PrereleaseCompatibilityTransformer\ExpectedOutputs\NestedFiles.sarif" />
<None Remove="TestData\PrereleaseCompatibilityTransformer\Inputs\NestedFiles.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\Minimum.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\MinimumWithTwoRuns.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\NotificationExceptionWithStack.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\OneRunWithBasicInvocation.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\OneRunWithFiles.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\OneRunWithInvocationAndNotifications.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\OneRunWithLogicalLocations.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\OneRunWithRules.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\Regions.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\RestoreFromPropertyBag.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\ResultLocations.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v1\TwoResultsWithFixes.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\Minimum.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\MinimumWithTwoRuns.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\NotificationExceptionWithStack.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\OneRunWithBasicInvocation.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\OneRunWithFiles.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\OneRunWithInvocationAndNotifications.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\OneRunWithLogicalLocations.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\OneRunWithRules.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\Regions.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\RestoreFromPropertyBag.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\ResultLocations.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\v2\TwoResultsWithFixes.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\Minimum.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\MinimumWithTwoRuns.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\NotificationExceptionWithStack.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\OneRunWithBasicInvocation.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\OneRunWithFiles.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\OneRunWithInvocationAndNotifications.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\OneRunWithLogicalLocations.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\OneRunWithRules.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\Regions.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\RestoreFromPropertyBag.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\ResultLocations.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\TwoResultsWithFixes.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\Minimum.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\MinimumWithTwoRuns.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\NotificationExceptionWithStack.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\OneRunWithBasicInvocation.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\OneRunWithFiles.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\OneRunWithInvocationAndNotifications.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\OneRunWithLogicalLocations.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\OneRunWithRules.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\Regions.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\RestoreFromPropertyBag.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\ResultLocations.sarif" />
<None Remove="TestData\SarifCurrentToVersionOneVisitor\Inputs\TwoResultsWithFixes.sarif" />
<None Remove="TestData\SarifVersionOneToCurrentVisitor\v1\BasicResult.sarif" />
<None Remove="TestData\SarifVersionOneToCurrentVisitor\v1\CodeFlows.sarif" />
<None Remove="TestData\SarifVersionOneToCurrentVisitor\v1\Minimum.sarif" />
Expand Down Expand Up @@ -90,30 +90,30 @@
<ItemGroup>
<EmbeddedResource Include="TestData\PrereleaseCompatibilityTransformer\ExpectedOutputs\NestedFiles.sarif" />
<EmbeddedResource Include="TestData\PrereleaseCompatibilityTransformer\Inputs\NestedFiles.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\Minimum.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\MinimumWithTwoRuns.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\NotificationExceptionWithStack.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\OneRunWithBasicInvocation.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\OneRunWithFiles.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\OneRunWithInvocationAndNotifications.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\OneRunWithLogicalLocations.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\OneRunWithRules.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\Regions.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\RestoreFromPropertyBag.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\ResultLocations.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v1\TwoResultsWithFixes.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\Minimum.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\MinimumWithTwoRuns.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\NotificationExceptionWithStack.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\OneRunWithBasicInvocation.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\OneRunWithFiles.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\OneRunWithInvocationAndNotifications.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\OneRunWithLogicalLocations.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\OneRunWithRules.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\Regions.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\RestoreFromPropertyBag.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\ResultLocations.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\v2\TwoResultsWithFixes.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\Minimum.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\MinimumWithTwoRuns.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\NotificationExceptionWithStack.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\OneRunWithBasicInvocation.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\OneRunWithFiles.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\OneRunWithInvocationAndNotifications.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\OneRunWithLogicalLocations.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\OneRunWithRules.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\Regions.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\RestoreFromPropertyBag.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\ResultLocations.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\ExpectedOutputs\TwoResultsWithFixes.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\Minimum.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\MinimumWithTwoRuns.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\NotificationExceptionWithStack.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\OneRunWithBasicInvocation.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\OneRunWithFiles.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\OneRunWithInvocationAndNotifications.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\OneRunWithLogicalLocations.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\OneRunWithRules.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\Regions.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\RestoreFromPropertyBag.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\ResultLocations.sarif" />
<EmbeddedResource Include="TestData\SarifCurrentToVersionOneVisitor\Inputs\TwoResultsWithFixes.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\v1\BasicResult.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\v1\CodeFlows.sarif" />
<EmbeddedResource Include="TestData\SarifVersionOneToCurrentVisitor\v1\Minimum.sarif" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
}
},
"files": {
"collections.rsp": {
"uri": "collections.rsp"
}
"collections.rsp": {}
},
"results": []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,25 @@
}
},
"file:///home/buildAgent/bin/app.zip#/docs/intro.docx": {
"uri": "file:///docs/intro.docx",
"uri": "/docs/intro.docx",
"parentKey": "file:///home/buildAgent/bin/app.zip",
"offset": 17522,
"length": 4050,
"mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
},
"file:///home/buildAgent/bin/app.zip#/data.zip": {
"uri": "/data.zip",
"parentKey": "file:///home/buildAgent/bin/app.zip",
"offset": 901299,
"length": 170633,
"mimeType": "application/zip"
},
"file:///home/buildAgent/bin/app.zip#/data.zip/state-data/wa.dat": {
"uri": "/state-data/wa.dat",
"parentKey": "file:///home/buildAgent/bin/app.zip#/data.zip",
"offset": 475,
"length": 8214,
"mimeType": "application/octet-stream"
}
},
"results": []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
"invocation": {},
"files": {
"file:///src/base/driver.cs": {
"uri": "file:///src/base/driver.cs",
"contents": "YQBiAGMAZAANAAoAZQBmAGcADQAKAGgAaQBqAGsADQAKAGwAbQBuAA=="
},
"file:///src/ui/client.cs": {
"uri": "file:///src/ui/client.cs",
"mimeType": "text/x-csharp",
"contents": "VGhlIHF1aWNrIGJyb3duIGZveA0KanVtcHMgb3ZlciB0aGUgbGFhenkgZG9n"
},
"file:///src/ui/unicodeText.cs": {
"uri": "file:///src/ui/unicodeText.cs",
"mimeType": "text/x-csharp",
"contents": "VGhlIHF1aWNrIGJyb3duIGZveA0KanVtcHMgb3ZlciB0aGUgbGFhenkgZG9n"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
"length": 4050,
"mimeType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"contents": {}
},
"file:///home/buildAgent/bin/app.zip#/data.zip": {
"uri": "/data.zip",
"parentKey": "file:///home/buildAgent/bin/app.zip",
"offset": 901299,
"length": 170633,
"mimeType": "application/zip"
},
"file:///home/buildAgent/bin/app.zip#/data.zip/state-data/wa.dat": {
"uri": "/state-data/wa.dat",
"parentKey": "file:///home/buildAgent/bin/app.zip#/data.zip",
"offset": 475,
"length": 8214,
"mimeType": "application/octet-stream"
}
},
"results": []
Expand Down
Loading