Enabled Razor.Evolution tests on linux
This commit is contained in:
parent
243446d225
commit
7725c20c47
|
|
@ -10,6 +10,8 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
{
|
{
|
||||||
internal class DefaultRazorDesignTimeCSharpLoweringPhase : RazorCSharpLoweringPhaseBase
|
internal class DefaultRazorDesignTimeCSharpLoweringPhase : RazorCSharpLoweringPhaseBase
|
||||||
{
|
{
|
||||||
|
internal static readonly object NewLineString = "NewLineString";
|
||||||
|
|
||||||
protected override void ExecuteCore(RazorCodeDocument codeDocument)
|
protected override void ExecuteCore(RazorCodeDocument codeDocument)
|
||||||
{
|
{
|
||||||
var irDocument = codeDocument.GetIRDocument();
|
var irDocument = codeDocument.GetIRDocument();
|
||||||
|
|
@ -18,9 +20,17 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
var syntaxTree = codeDocument.GetSyntaxTree();
|
var syntaxTree = codeDocument.GetSyntaxTree();
|
||||||
ThrowForMissingDependency(syntaxTree);
|
ThrowForMissingDependency(syntaxTree);
|
||||||
|
|
||||||
|
var codeWriter = new CSharpCodeWriter();
|
||||||
|
var newLineString = codeDocument.Items[NewLineString];
|
||||||
|
if (newLineString != null)
|
||||||
|
{
|
||||||
|
// Set new line character to a specific string regardless of platform, for testing purposes.
|
||||||
|
codeWriter.NewLine = (string)newLineString;
|
||||||
|
}
|
||||||
|
|
||||||
var renderingContext = new CSharpRenderingContext()
|
var renderingContext = new CSharpRenderingContext()
|
||||||
{
|
{
|
||||||
Writer = new CSharpCodeWriter(),
|
Writer = codeWriter,
|
||||||
SourceDocument = codeDocument.Source,
|
SourceDocument = codeDocument.Source,
|
||||||
Options = syntaxTree.Options,
|
Options = syntaxTree.Options,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1407,10 +1407,15 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
|
||||||
throw new XunitException($"The resource {sourceFilename} was not found.");
|
throw new XunitException($"The resource {sourceFilename} was not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var codeDocument = RazorCodeDocument.Create(TestRazorSourceDocument.CreateResource(sourceFilename));
|
var codeDocument = RazorCodeDocument.Create(
|
||||||
|
TestRazorSourceDocument.CreateResource(sourceFilename, encoding: null, normalizeNewLines: true));
|
||||||
|
|
||||||
// This will ensure that we're not putting any randomly generated data in a baseline.
|
// This will ensure that we're not putting any randomly generated data in a baseline.
|
||||||
codeDocument.Items[DefaultRazorRuntimeCSharpLoweringPhase.SuppressUniqueIds] = "test";
|
codeDocument.Items[DefaultRazorRuntimeCSharpLoweringPhase.SuppressUniqueIds] = "test";
|
||||||
|
|
||||||
|
// This is to make tests work cross platform.
|
||||||
|
codeDocument.Items[DefaultRazorDesignTimeCSharpLoweringPhase.NewLineString] = "\r\n";
|
||||||
|
|
||||||
return codeDocument;
|
return codeDocument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -97,10 +97,12 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
imports.Add(TestRazorSourceDocument.CreateResource(importsFilename));
|
imports.Add(
|
||||||
|
TestRazorSourceDocument.CreateResource(importsFilename, encoding: null, normalizeNewLines: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
var codeDocument = RazorCodeDocument.Create(TestRazorSourceDocument.CreateResource(sourceFilename), imports);
|
var codeDocument = RazorCodeDocument.Create(
|
||||||
|
TestRazorSourceDocument.CreateResource(sourceFilename, encoding: null, normalizeNewLines: true), imports);
|
||||||
|
|
||||||
// This will ensure that we're not putting any randomly generated data in a baseline.
|
// This will ensure that we're not putting any randomly generated data in a baseline.
|
||||||
codeDocument.Items[DefaultRazorRuntimeCSharpLoweringPhase.SuppressUniqueIds] = "test";
|
codeDocument.Items[DefaultRazorRuntimeCSharpLoweringPhase.SuppressUniqueIds] = "test";
|
||||||
|
|
@ -109,11 +111,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
|
||||||
|
|
||||||
protected void AssertIRMatchesBaseline(DocumentIRNode document)
|
protected void AssertIRMatchesBaseline(DocumentIRNode document)
|
||||||
{
|
{
|
||||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Filename == null)
|
if (Filename == null)
|
||||||
{
|
{
|
||||||
var message = $"{nameof(AssertIRMatchesBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
var message = $"{nameof(AssertIRMatchesBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
||||||
|
|
@ -141,11 +138,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
|
||||||
|
|
||||||
protected void AssertCSharpDocumentMatchesBaseline(RazorCSharpDocument document)
|
protected void AssertCSharpDocumentMatchesBaseline(RazorCSharpDocument document)
|
||||||
{
|
{
|
||||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Filename == null)
|
if (Filename == null)
|
||||||
{
|
{
|
||||||
var message = $"{nameof(AssertCSharpDocumentMatchesBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
var message = $"{nameof(AssertCSharpDocumentMatchesBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
||||||
|
|
@ -177,11 +169,6 @@ namespace Microsoft.AspNetCore.Razor.Evolution.IntegrationTests
|
||||||
|
|
||||||
protected void AssertDesignTimeDocumentMatchBaseline(RazorCodeDocument document)
|
protected void AssertDesignTimeDocumentMatchBaseline(RazorCodeDocument document)
|
||||||
{
|
{
|
||||||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Filename == null)
|
if (Filename == null)
|
||||||
{
|
{
|
||||||
var message = $"{nameof(AssertDesignTimeDocumentMatchBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
var message = $"{nameof(AssertDesignTimeDocumentMatchBaseline)} should only be called from an integration test ({nameof(Filename)} is null).";
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.AspNetCore.Razor.Evolution.Legacy;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Razor.Evolution
|
namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
{
|
{
|
||||||
|
|
@ -14,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RazorSourceDocument CreateResource(string path, Encoding encoding = null)
|
public static RazorSourceDocument CreateResource(string path, Encoding encoding = null, bool normalizeNewLines = false)
|
||||||
{
|
{
|
||||||
var file = TestFile.Create(path);
|
var file = TestFile.Create(path);
|
||||||
|
|
||||||
|
|
@ -22,17 +24,26 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
using (var reader = new StreamReader(input))
|
using (var reader = new StreamReader(input))
|
||||||
{
|
{
|
||||||
var content = reader.ReadToEnd();
|
var content = reader.ReadToEnd();
|
||||||
|
if (normalizeNewLines)
|
||||||
|
{
|
||||||
|
content = NormalizeNewLines(content);
|
||||||
|
}
|
||||||
|
|
||||||
return new TestRazorSourceDocument(content, encoding ?? Encoding.UTF8, path);
|
return new TestRazorSourceDocument(content, encoding ?? Encoding.UTF8, path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MemoryStream CreateStreamContent(string content = "Hello, World!", Encoding encoding = null)
|
public static MemoryStream CreateStreamContent(string content = "Hello, World!", Encoding encoding = null, bool normalizeNewLines = false)
|
||||||
{
|
{
|
||||||
var stream = new MemoryStream();
|
var stream = new MemoryStream();
|
||||||
encoding = encoding ?? Encoding.UTF8;
|
encoding = encoding ?? Encoding.UTF8;
|
||||||
using (var writer = new StreamWriter(stream, encoding, bufferSize: 1024, leaveOpen: true))
|
using (var writer = new StreamWriter(stream, encoding, bufferSize: 1024, leaveOpen: true))
|
||||||
{
|
{
|
||||||
|
if (normalizeNewLines)
|
||||||
|
{
|
||||||
|
content = NormalizeNewLines(content);
|
||||||
|
}
|
||||||
|
|
||||||
writer.Write(content);
|
writer.Write(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,9 +52,19 @@ namespace Microsoft.AspNetCore.Razor.Evolution
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RazorSourceDocument Create(string content = "Hello, world!", Encoding encoding = null)
|
public static RazorSourceDocument Create(string content = "Hello, world!", Encoding encoding = null, bool normalizeNewLines = false)
|
||||||
{
|
{
|
||||||
|
if (normalizeNewLines)
|
||||||
|
{
|
||||||
|
content = NormalizeNewLines(content);
|
||||||
|
}
|
||||||
|
|
||||||
return new TestRazorSourceDocument(content, encoding ?? Encoding.UTF8, "test.cshtml");
|
return new TestRazorSourceDocument(content, encoding ?? Encoding.UTF8, "test.cshtml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string NormalizeNewLines(string content)
|
||||||
|
{
|
||||||
|
return Regex.Replace(content, "(?<!\r)\n", "\r\n", RegexOptions.None, TimeSpan.FromSeconds(10));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue