parent
32f6f4df00
commit
662dc087bd
|
|
@ -10,6 +10,8 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
{
|
{
|
||||||
public class CSharpCodeBuilder : CodeBuilder
|
public class CSharpCodeBuilder : CodeBuilder
|
||||||
{
|
{
|
||||||
|
private const int DisableAsyncWarning = 1998;
|
||||||
|
|
||||||
public CSharpCodeBuilder(CodeGeneratorContext context)
|
public CSharpCodeBuilder(CodeGeneratorContext context)
|
||||||
: base(context)
|
: base(context)
|
||||||
{
|
{
|
||||||
|
|
@ -57,8 +59,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
// Add space inbetween constructor and method body
|
// Add space inbetween constructor and method body
|
||||||
writer.WriteLine();
|
writer.WriteLine();
|
||||||
|
|
||||||
// 1998 is to not warn about empty async methods.
|
using (writer.BuildDisableWarningScope(DisableAsyncWarning))
|
||||||
using (writer.BuildDisableWarningScope(1998))
|
|
||||||
{
|
{
|
||||||
using (writer.BuildMethodDeclaration("public override async", "Task", Host.GeneratedClassContext.ExecuteMethodName))
|
using (writer.BuildMethodDeclaration("public override async", "Task", Host.GeneratedClassContext.ExecuteMethodName))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
internal const string InheritsHelper = "__inheritsHelper";
|
internal const string InheritsHelper = "__inheritsHelper";
|
||||||
internal const string DesignTimeHelperMethodName = "__RazorDesignTimeHelpers__";
|
internal const string DesignTimeHelperMethodName = "__RazorDesignTimeHelpers__";
|
||||||
|
|
||||||
|
private const int DisableVariableNamingWarnings = 219;
|
||||||
|
|
||||||
public CSharpDesignTimeHelpersVisitor(CSharpCodeWriter writer, CodeGeneratorContext context)
|
public CSharpDesignTimeHelpersVisitor(CSharpCodeWriter writer, CodeGeneratorContext context)
|
||||||
: base(writer, context) { }
|
: base(writer, context) { }
|
||||||
|
|
||||||
|
|
@ -17,7 +19,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
|
||||||
{
|
{
|
||||||
using (Writer.BuildMethodDeclaration("private", "void", "@" + DesignTimeHelperMethodName))
|
using (Writer.BuildMethodDeclaration("private", "void", "@" + DesignTimeHelperMethodName))
|
||||||
{
|
{
|
||||||
using (Writer.BuildDisableWarningScope(219))
|
using (Writer.BuildDisableWarningScope(DisableVariableNamingWarnings))
|
||||||
{
|
{
|
||||||
Accept(tree.Chunks);
|
Accept(tree.Chunks);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System.Web.WebPages.TestUtils;
|
||||||
using Microsoft.AspNet.Razor.Generator;
|
using Microsoft.AspNet.Razor.Generator;
|
||||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
|
||||||
using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
|
|
||||||
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
|
||||||
|
using Microsoft.AspNet.Razor.Test.Utils;
|
||||||
using Microsoft.TestCommon;
|
using Microsoft.TestCommon;
|
||||||
using Moq;
|
using Moq;
|
||||||
|
|
||||||
|
|
@ -25,37 +25,13 @@ namespace Microsoft.AspNet.Razor.Test.Generator.CodeTree
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var result = codeBuilder.Build();
|
var result = codeBuilder.Build();
|
||||||
|
|
||||||
|
BaselineWriter.WriteBaseline(@"test\Microsoft.AspNet.Razor.Test\TestFiles\CodeGenerator\CS\Output\CSharpCodeBuilder.cs", result.Code);
|
||||||
|
|
||||||
|
var expectedOutput = TestFile.Create("CodeGenerator.CS.Output.CSharpCodeBuilder.cs").ReadAllText();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(@"namespace TestNamespace
|
Assert.Equal(expectedOutput, result.Code);
|
||||||
{
|
|
||||||
#line 1 """"
|
|
||||||
using FakeNamespace1
|
|
||||||
|
|
||||||
#line default
|
|
||||||
#line hidden
|
|
||||||
;
|
|
||||||
#line 1 """"
|
|
||||||
using FakeNamespace2.SubNamespace
|
|
||||||
|
|
||||||
#line default
|
|
||||||
#line hidden
|
|
||||||
;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
public class TestClass
|
|
||||||
{
|
|
||||||
#line hidden
|
|
||||||
public TestClass()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma warning disable 1998
|
|
||||||
public override async Task ExecuteAsync()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#pragma warning restore 1998
|
|
||||||
}
|
|
||||||
}", result.Code.TrimEnd());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Web.WebPages.TestUtils;
|
using System.Web.WebPages.TestUtils;
|
||||||
using Microsoft.AspNet.Razor.Generator;
|
using Microsoft.AspNet.Razor.Generator;
|
||||||
using Microsoft.AspNet.Razor.Generator.Compiler;
|
using Microsoft.AspNet.Razor.Generator.Compiler;
|
||||||
|
|
@ -145,7 +142,7 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only called if GENERATE_BASELINES is set, otherwise compiled out.
|
// Only called if GENERATE_BASELINES is set, otherwise compiled out.
|
||||||
WriteBaseline(String.Format(@"test\Microsoft.AspNet.Razor.Test\TestFiles\CodeGenerator\{0}\Output\{1}.{2}", LanguageName, baselineName, BaselineExtension), results.GeneratedCode);
|
BaselineWriter.WriteBaseline(String.Format(@"test\Microsoft.AspNet.Razor.Test\TestFiles\CodeGenerator\{0}\Output\{1}.{2}", LanguageName, baselineName, BaselineExtension), results.GeneratedCode);
|
||||||
|
|
||||||
#if !GENERATE_BASELINES
|
#if !GENERATE_BASELINES
|
||||||
string textOutput = results.GeneratedCode;
|
string textOutput = results.GeneratedCode;
|
||||||
|
|
@ -191,34 +188,6 @@ namespace Microsoft.AspNet.Razor.Test.Generator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Conditional("GENERATE_BASELINES")]
|
|
||||||
private void WriteBaseline(string baselineFile, string output)
|
|
||||||
{
|
|
||||||
string root = RecursiveFind("Razor.sln", Path.GetFullPath("."));
|
|
||||||
string baselinePath = Path.Combine(root, baselineFile);
|
|
||||||
|
|
||||||
// Update baseline
|
|
||||||
// IMPORTANT! Replace this path with the local path on your machine to the baseline files!
|
|
||||||
if (File.Exists(baselinePath))
|
|
||||||
{
|
|
||||||
File.Delete(baselinePath);
|
|
||||||
}
|
|
||||||
File.WriteAllText(baselinePath, output.ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
private string RecursiveFind(string path, string start)
|
|
||||||
{
|
|
||||||
string test = Path.Combine(start, path);
|
|
||||||
if (File.Exists(test))
|
|
||||||
{
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return RecursiveFind(path, new DirectoryInfo(start).Parent.FullName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void VerifyNoBrokenEndOfLines(string text)
|
private void VerifyNoBrokenEndOfLines(string text)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < text.Length; i++)
|
for (int i = 0; i < text.Length; i++)
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,7 @@
|
||||||
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\CodeTree.cs" />
|
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\CodeTree.cs" />
|
||||||
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\Await.cs" />
|
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\Await.cs" />
|
||||||
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\Await.DesignTime.cs" />
|
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\Await.DesignTime.cs" />
|
||||||
|
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\CSharpCodeBuilder.cs" />
|
||||||
<Compile Include="Text\BufferingTextReaderTest.cs" />
|
<Compile Include="Text\BufferingTextReaderTest.cs" />
|
||||||
<Compile Include="Text\LineTrackingStringBufferTest.cs" />
|
<Compile Include="Text\LineTrackingStringBufferTest.cs" />
|
||||||
<Compile Include="Text\LookaheadTextReaderTestBase.cs" />
|
<Compile Include="Text\LookaheadTextReaderTestBase.cs" />
|
||||||
|
|
@ -135,6 +136,7 @@
|
||||||
<Compile Include="Tokenizer\HtmlTokenizerTestBase.cs" />
|
<Compile Include="Tokenizer\HtmlTokenizerTestBase.cs" />
|
||||||
<Compile Include="Tokenizer\TokenizerLookaheadTest.cs" />
|
<Compile Include="Tokenizer\TokenizerLookaheadTest.cs" />
|
||||||
<Compile Include="Tokenizer\TokenizerTestBase.cs" />
|
<Compile Include="Tokenizer\TokenizerTestBase.cs" />
|
||||||
|
<Compile Include="Utils\BaselineWriter.cs" />
|
||||||
<Compile Include="Utils\DisposableActionTest.cs" />
|
<Compile Include="Utils\DisposableActionTest.cs" />
|
||||||
<Compile Include="Utils\MiscUtils.cs" />
|
<Compile Include="Utils\MiscUtils.cs" />
|
||||||
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\UnfinishedExpressionInCode.Tabs.cs" />
|
<EmbeddedResource Include="TestFiles\CodeGenerator\CS\Output\UnfinishedExpressionInCode.Tabs.cs" />
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
namespace TestNamespace
|
||||||
|
{
|
||||||
|
#line 1 ""
|
||||||
|
using FakeNamespace1
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
;
|
||||||
|
#line 1 ""
|
||||||
|
using FakeNamespace2.SubNamespace
|
||||||
|
|
||||||
|
#line default
|
||||||
|
#line hidden
|
||||||
|
;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
public class TestClass
|
||||||
|
{
|
||||||
|
#line hidden
|
||||||
|
public TestClass()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma warning disable 1998
|
||||||
|
public override async Task ExecuteAsync()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#pragma warning restore 1998
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNet.Razor.Test.Utils
|
||||||
|
{
|
||||||
|
public static class BaselineWriter
|
||||||
|
{
|
||||||
|
[Conditional("GENERATE_BASELINES")]
|
||||||
|
public static void WriteBaseline(string baselineFile, string output)
|
||||||
|
{
|
||||||
|
var root = RecursiveFind("Razor.sln", Path.GetFullPath("."));
|
||||||
|
var baselinePath = Path.Combine(root, baselineFile);
|
||||||
|
|
||||||
|
// Update baseline
|
||||||
|
// IMPORTANT! Replace this path with the local path on your machine to the baseline files!
|
||||||
|
if (File.Exists(baselinePath))
|
||||||
|
{
|
||||||
|
File.Delete(baselinePath);
|
||||||
|
}
|
||||||
|
File.WriteAllText(baselinePath, output.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string RecursiveFind(string path, string start)
|
||||||
|
{
|
||||||
|
var test = Path.Combine(start, path);
|
||||||
|
if (File.Exists(test))
|
||||||
|
{
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return RecursiveFind(path, new DirectoryInfo(start).Parent.FullName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue