Skip to content

Commit

Permalink
Fix tests that are broken in appveyor (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelcfanning authored Nov 14, 2018
1 parent e35710f commit 9d2f619
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
3 changes: 3 additions & 0 deletions src/Sarif.TestUtilities/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand All @@ -17,6 +18,8 @@ namespace Microsoft.CodeAnalysis.Sarif
{
public static class Utilities
{
public static bool RunningInAppVeyor { get { return Environment.CommandLine.IndexOf("/logger:appveyor", StringComparison.OrdinalIgnoreCase) != -1; } }

public static MemoryStream CreateStreamFromString(string data)
{
return new MemoryStream(Encoding.UTF8.GetBytes(data));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,40 @@ private void VerifyVersionOneToCurrentTransformationFromResource(string v1InputR

StringBuilder sb = new StringBuilder();

string expectedFilePath = GetOutputFilePath("expected", v2ExpectedResourceName);
string actualFilePath = GetOutputFilePath("actual", v2ExpectedResourceName);
string expectedFilePath = null;
string actualFilePath = null;

string expectedRootDirectory = Path.GetDirectoryName(expectedFilePath);
string actualRootDirectory = Path.GetDirectoryName(actualFilePath);
if (!Utilities.RunningInAppVeyor)
{
expectedFilePath = GetOutputFilePath("expected", v2ExpectedResourceName);
actualFilePath = GetOutputFilePath("actual", v2ExpectedResourceName);
}

if (!AreEquivalentSarifLogs<SarifLog>(v2ActualLogText, v2ExpectedLogText))
if (!AreEquivalentSarifLogs<SarifLog>(v2ActualLogText, v2ExpectedLogText))
{
Directory.CreateDirectory(expectedRootDirectory);
Directory.CreateDirectory(actualRootDirectory);
string errorMessage = string.Format(@"V2 conversion from V1 produced unexpected diffs for test: '{0}'.", v1InputResourceName);
sb.AppendLine(errorMessage);

File.WriteAllText(expectedFilePath, v2ExpectedLogText);
File.WriteAllText(actualFilePath, v2ActualLogText);
if (!Utilities.RunningInAppVeyor)
{
string expectedRootDirectory = Path.GetDirectoryName(expectedFilePath);
string actualRootDirectory = Path.GetDirectoryName(actualFilePath);

Directory.CreateDirectory(expectedRootDirectory);
Directory.CreateDirectory(actualRootDirectory);

string errorMessage = string.Format(@"V2 conversion from V1 produced unexpected diffs for test: '{0}'.", v1InputResourceName);
sb.AppendLine("Check individual differences with:");
sb.AppendLine(GenerateDiffCommand(expectedFilePath, actualFilePath) + Environment.NewLine);
File.WriteAllText(expectedFilePath, v2ExpectedLogText);
File.WriteAllText(actualFilePath, v2ActualLogText);

sb.AppendLine("To compare all difference for this test suite:");
sb.AppendLine(GenerateDiffCommand(Path.GetDirectoryName(expectedFilePath), Path.GetDirectoryName(actualFilePath)) + Environment.NewLine);
sb.AppendLine("Check individual differences with:");
sb.AppendLine(GenerateDiffCommand(expectedFilePath, actualFilePath) + Environment.NewLine);

sb.AppendLine("To compare all difference for this test suite:");
sb.AppendLine(GenerateDiffCommand(Path.GetDirectoryName(expectedFilePath), Path.GetDirectoryName(actualFilePath)) + Environment.NewLine);
}
}

if (s_Rebaseline)
if (s_Rebaseline && !Utilities.RunningInAppVeyor)
{
// We rewrite to test output directory. This allows subsequent tests to
// pass without requiring a rebuild that recopies SARIF test files
Expand All @@ -91,11 +101,9 @@ private void VerifyVersionOneToCurrentTransformationFromResource(string v1InputR

// We also rewrite the checked in test baselines
File.WriteAllText(expectedFilePath, v2ActualLogText);

}

s_Rebaseline.Should().BeFalse();

ValidateResults(sb.ToString());
}

Expand Down

0 comments on commit 9d2f619

Please sign in to comment.