diff --git a/Weave.Tests.Generated/ConfigTest/AbsentConfig/TestAbsentConfig.weave b/Weave.Tests.Generated/ConfigTest/AbsentConfig/TestAbsentConfig.weave new file mode 100644 index 0000000..68e7e0d --- /dev/null +++ b/Weave.Tests.Generated/ConfigTest/AbsentConfig/TestAbsentConfig.weave @@ -0,0 +1,3 @@ +@namespace Weave.Tests.Generated.ConfigTest.AbsentConfig +@accessibility public +Hello, world! diff --git a/Weave.Tests.Generated/ConfigTest/CompiledConfig/TestCompiledConfig.weave b/Weave.Tests.Generated/ConfigTest/CompiledConfig/TestCompiledConfig.weave new file mode 100644 index 0000000..af5626b --- /dev/null +++ b/Weave.Tests.Generated/ConfigTest/CompiledConfig/TestCompiledConfig.weave @@ -0,0 +1 @@ +Hello, world! diff --git a/Weave.Tests.Generated/ConfigTest/CompiledConfig/_config.weave b/Weave.Tests.Generated/ConfigTest/CompiledConfig/_config.weave new file mode 100644 index 0000000..578e6ff --- /dev/null +++ b/Weave.Tests.Generated/ConfigTest/CompiledConfig/_config.weave @@ -0,0 +1,2 @@ +@namespace Weave.Tests.Generated.ConfigTest.CompiledConfig +@accessibility public diff --git a/Weave.Tests.Generated/ConfigTest/GeneratedConfig/TestGeneratedConfig.weave b/Weave.Tests.Generated/ConfigTest/GeneratedConfig/TestGeneratedConfig.weave new file mode 100644 index 0000000..af5626b --- /dev/null +++ b/Weave.Tests.Generated/ConfigTest/GeneratedConfig/TestGeneratedConfig.weave @@ -0,0 +1 @@ +Hello, world! diff --git a/Weave.Tests.Generated/ConfigTest/GeneratedConfig/_config.weave b/Weave.Tests.Generated/ConfigTest/GeneratedConfig/_config.weave new file mode 100644 index 0000000..881ce93 --- /dev/null +++ b/Weave.Tests.Generated/ConfigTest/GeneratedConfig/_config.weave @@ -0,0 +1,2 @@ +@namespace Weave.Tests.Generated.ConfigTest.GeneratedConfig +@accessibility public diff --git a/Weave.Tests.Generated/ConfigTest/LegacyCompiledConfig/LegacyCompiledConfig.weave b/Weave.Tests.Generated/ConfigTest/LegacyCompiledConfig/LegacyCompiledConfig.weave new file mode 100644 index 0000000..af5626b --- /dev/null +++ b/Weave.Tests.Generated/ConfigTest/LegacyCompiledConfig/LegacyCompiledConfig.weave @@ -0,0 +1 @@ +Hello, world! diff --git a/Weave.Tests.Generated/ConfigTest/LegacyCompiledConfig/_config.weave b/Weave.Tests.Generated/ConfigTest/LegacyCompiledConfig/_config.weave new file mode 100644 index 0000000..47323c9 --- /dev/null +++ b/Weave.Tests.Generated/ConfigTest/LegacyCompiledConfig/_config.weave @@ -0,0 +1,2 @@ +@namespace Weave.Tests.Generated.ConfigTest.LegacyCompiledConfig +@accessibility public diff --git a/Weave.Tests.Generated/ConfigTest/LegacyGeneratedConfig/LegacyGeneratedConfig.weave b/Weave.Tests.Generated/ConfigTest/LegacyGeneratedConfig/LegacyGeneratedConfig.weave new file mode 100644 index 0000000..af5626b --- /dev/null +++ b/Weave.Tests.Generated/ConfigTest/LegacyGeneratedConfig/LegacyGeneratedConfig.weave @@ -0,0 +1 @@ +Hello, world! diff --git a/Weave.Tests.Generated/ConfigTest/LegacyGeneratedConfig/_config.weave b/Weave.Tests.Generated/ConfigTest/LegacyGeneratedConfig/_config.weave new file mode 100644 index 0000000..dd8e00a --- /dev/null +++ b/Weave.Tests.Generated/ConfigTest/LegacyGeneratedConfig/_config.weave @@ -0,0 +1,2 @@ +@namespace Weave.Tests.Generated.ConfigTest.LegacyGeneratedConfig +@accessibility public diff --git a/Weave.Tests.Generated/ConfigTest/NoneConfig/TestNoneConfig.weave b/Weave.Tests.Generated/ConfigTest/NoneConfig/TestNoneConfig.weave new file mode 100644 index 0000000..af5626b --- /dev/null +++ b/Weave.Tests.Generated/ConfigTest/NoneConfig/TestNoneConfig.weave @@ -0,0 +1 @@ +Hello, world! diff --git a/Weave.Tests.Generated/ConfigTest/NoneConfig/_config.weave b/Weave.Tests.Generated/ConfigTest/NoneConfig/_config.weave new file mode 100644 index 0000000..35ffc3f --- /dev/null +++ b/Weave.Tests.Generated/ConfigTest/NoneConfig/_config.weave @@ -0,0 +1,2 @@ +@namespace Weave.Tests.Generated.ConfigTest.NoneConfig +@accessibility public diff --git a/Weave.Tests.Generated/Properties/AssemblyInfo.cs b/Weave.Tests.Generated/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9fd3dba --- /dev/null +++ b/Weave.Tests.Generated/Properties/AssemblyInfo.cs @@ -0,0 +1,4 @@ +// +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Weave.Tests")] diff --git a/Weave.Tests.Generated/Weave.Tests.Generated.csproj b/Weave.Tests.Generated/Weave.Tests.Generated.csproj new file mode 100644 index 0000000..f63bfaf --- /dev/null +++ b/Weave.Tests.Generated/Weave.Tests.Generated.csproj @@ -0,0 +1,51 @@ + + + + net6.0 + true + + + + + + + + + + + + false + + + + + + + + + false + + + + + false + + + + + + false + + + + + + $(GetTargetPathDependsOn);GetDependencyTargetPaths + + + + + + + + \ No newline at end of file diff --git a/Weave.Tests/GeneratedCode/ConfigTests.cs b/Weave.Tests/GeneratedCode/ConfigTests.cs new file mode 100644 index 0000000..44a5c65 --- /dev/null +++ b/Weave.Tests/GeneratedCode/ConfigTests.cs @@ -0,0 +1,81 @@ +// Copyright © John Gietzen. All Rights Reserved. This source is subject to the MIT license. Please see license.md for more information. + +namespace Weave.Tests.IntegrationTests +{ + using System; + using System.IO; + using Xunit; + + public class ConfigTests + { + private static readonly string ExpectedConfigOutput = ""; + private static readonly string ExpectedTemplateOutput = $"Hello, world!{Environment.NewLine}"; + + [Fact] + public void AbsentConfig() + { + TestHelper( + Generated.ConfigTest.AbsentConfig.Templates.RenderTestAbsentConfig, ExpectedTemplateOutput); + } + + [Fact] + public void CompiledConfig() + { + TestHelper( + (Generated.ConfigTest.CompiledConfig.Templates.Render_config, ExpectedConfigOutput), + (Generated.ConfigTest.CompiledConfig.Templates.RenderTestCompiledConfig, ExpectedTemplateOutput)); + } + + [Fact] + public void GeneratedConfig() + { + TestHelper( + (Generated.ConfigTest.GeneratedConfig.Templates.Render_config, ExpectedConfigOutput), + (Generated.ConfigTest.GeneratedConfig.Templates.RenderTestGeneratedConfig, ExpectedTemplateOutput)); + } + + [Fact] + public void LegacyCompiledConfig() + { + TestHelper( + (Generated.ConfigTest.LegacyCompiledConfig.Templates.Render_config, ExpectedConfigOutput), + (Generated.ConfigTest.LegacyCompiledConfig.Templates.RenderLegacyCompiledConfig, ExpectedTemplateOutput)); + } + + [Fact] + public void LegacyGeneratedConfig() + { + TestHelper( + (Generated.ConfigTest.LegacyGeneratedConfig.Templates.Render_config, ExpectedConfigOutput), + (Generated.ConfigTest.LegacyGeneratedConfig.Templates.RenderLegacyGeneratedConfig, ExpectedTemplateOutput)); + } + + [Fact] + public void NoneConfig() + { + TestHelper( + Generated.ConfigTest.NoneConfig.Templates.RenderTestNoneConfig, ExpectedTemplateOutput); + } + + private static void TestHelper(params (Action render, string expected)[] tests) + { + foreach (var (render, expected) in tests) + { + TestHelper(render, expected); + } + } + + private static void TestHelper(Action render, string expected) + { + var output = TestHelper(render); + Assert.Equal(expected, output); + } + + private static string TestHelper(Action render) + { + var writer = new StringWriter(); + render(null, writer, null); + return writer.ToString(); + } + } +} diff --git a/Weave.Tests/Weave.Tests.csproj b/Weave.Tests/Weave.Tests.csproj index aa568e2..560c262 100644 --- a/Weave.Tests/Weave.Tests.csproj +++ b/Weave.Tests/Weave.Tests.csproj @@ -1,12 +1,11 @@ - + Weave.Tests.ruleset Full false - net461 - + net6.0 @@ -14,18 +13,26 @@ - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - - + + + + + + + diff --git a/Weave.sln b/Weave.sln index 333de6d..33af191 100644 --- a/Weave.sln +++ b/Weave.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27428.2037 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34003.232 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D0E57E35-59EE-487F-852B-864CFC020B46}" ProjectSection(SolutionItems) = preProject @@ -25,6 +25,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Weave", "Weave\Weave.csproj EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Weave.Tests", "Weave.Tests\Weave.Tests.csproj", "{F2ECD1F3-7200-4FEA-A456-873F1749E008}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Weave.Tests.Generated", "Weave.Tests.Generated\Weave.Tests.Generated.csproj", "{46D94595-1DBC-49C6-9D77-A1E5E307E21E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {F2ECD1F3-7200-4FEA-A456-873F1749E008}.Debug|Any CPU.Build.0 = Debug|Any CPU {F2ECD1F3-7200-4FEA-A456-873F1749E008}.Release|Any CPU.ActiveCfg = Release|Any CPU {F2ECD1F3-7200-4FEA-A456-873F1749E008}.Release|Any CPU.Build.0 = Release|Any CPU + {46D94595-1DBC-49C6-9D77-A1E5E307E21E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46D94595-1DBC-49C6-9D77-A1E5E307E21E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46D94595-1DBC-49C6-9D77-A1E5E307E21E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46D94595-1DBC-49C6-9D77-A1E5E307E21E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Weave/CompileManager.cs b/Weave/CompileManager.cs index a138dd1..fbff68d 100644 --- a/Weave/CompileManager.cs +++ b/Weave/CompileManager.cs @@ -1,4 +1,4 @@ -// Copyright © John Gietzen. All Rights Reserved. This source is subject to the MIT license. Please see license.md for more information. +// Copyright © John Gietzen. All Rights Reserved. This source is subject to the MIT license. Please see license.md for more information. namespace Weave { @@ -13,29 +13,64 @@ namespace Weave internal static class CompileManager { - public static void CompileFile(string inputFile, string outputFile, Action logError) - { - outputFile = outputFile ?? inputFile + ".cs"; - var configFile = Path.Combine(Path.GetDirectoryName(inputFile), "_config.weave"); + public static readonly string ConfigFileName = "_config.weave"; - var template = ParseTemplate(inputFile, logError); - if (template == null) + public static CompileResult