public void each_BinPath_can_have_multiple_OutputPath() { var output1 = TestHelper.CleanupFolder(_outputFolder.AppendPart("each_BinPath_can_have_multiple_OutputPath").AppendPart("o1"), false); var output2 = TestHelper.CleanupFolder(_outputFolder.AppendPart("each_BinPath_can_have_multiple_OutputPath").AppendPart("o2"), false); var config = new StObjEngineConfiguration(); config.Aspects.Add(new TypeScriptAspectConfiguration()); var b = new BinPathConfiguration(); b.AspectConfigurations.Add(new XElement("TypeScript", new XElement("OutputPath", output1), new XElement("OutputPath", output2))); config.BinPaths.Add(b); var engine = new StObjEngine(TestHelper.Monitor, config); engine.Run(new MonoCollectorResolver(typeof(Simple))).Should().BeTrue("StObjEngine.Run worked."); Directory.Exists(output1).Should().BeTrue(); Directory.Exists(output2).Should().BeTrue(); var f1 = output1.Combine("CK/StObj/TypeScript/Tests/Simple.ts"); var f2 = output2.Combine("CK/StObj/TypeScript/Tests/Simple.ts"); File.Exists(f1).Should().BeTrue(); File.Exists(f2).Should().BeTrue(); var s = File.ReadAllText(f1); s.Should().StartWith("export enum Simple"); s.Should().Be(File.ReadAllText(f2)); }
static GenerateCodeResult DoGenerateCode(StObjCollectorResult result, Func <StObjEngineConfiguration, StObjEngineConfiguration>?engineConfigurator, bool generateSourceFiles, CompileOption compileOption) { Throw.CheckArgument(!result.HasFatalError); var assemblyName = StObjContextRoot.GeneratedAssemblyName + DateTime.Now.ToString(".yyMdHmsffff"); var config = new StObjEngineConfiguration() { GeneratedAssemblyName = assemblyName, }; config.BinPaths.Add(new BinPathConfiguration() { CompileOption = compileOption, GenerateSourceFiles = generateSourceFiles, ProjectPath = TestHelper.TestProjectFolder }); if (engineConfigurator != null) { config = engineConfigurator.Invoke(config); Throw.CheckState("The engine configuration returned by the engineConfigurator cannot be null.", config != null); } return(new GenerateCodeResult(result, Setup.StObjEngine.Run(TestHelper.Monitor, result, config))); }
public void parsing_a_configuration() { StObjEngineConfiguration c = new StObjEngineConfiguration(_config); c.BasePath.Should().Be(new NormalizedPath("/The/Base/Path")); c.BinPaths.Should().HaveCount(2); var b1 = c.BinPaths[0]; b1.Path.Should().Be(new NormalizedPath("../../Relative/To/Base/[Debug|Release]/netcoreapp3.1")); b1.Assemblies.Should().BeEquivalentTo("An.Assembly.Name", "Another.Assembly"); b1.Types.Should().HaveCount(3); var t1 = b1.Types[0]; t1.Name.Should().Be("CK.Core.IActivityMonitor, CK.ActivityMonitor"); t1.Kind.Should().Be(AutoServiceKind.IsScoped); t1.Optional.Should().BeFalse(); var t2 = b1.Types[1]; t2.Name.Should().Be("Microsoft.Extensions.Hosting.IHostedService, Microsoft.Extensions.Hosting.Abstractions"); t2.Kind.Should().Be(AutoServiceKind.IsMultipleService | AutoServiceKind.IsSingleton); t2.Optional.Should().BeTrue(); var t3 = b1.Types[2]; t3.Name.Should().Be("Microsoft.Extensions.Options.IOptions`1, Microsoft.Extensions.Options"); t3.Kind.Should().Be(AutoServiceKind.IsFrontProcessService | AutoServiceKind.IsSingleton); t3.Optional.Should().BeTrue(); var bSample = b1.GetAspectConfiguration <SampleAspectConfiguration>(); Debug.Assert(bSample != null); bSample.Element("Param")?.Value.Should().Be("Test"); b1.GetAspectConfiguration("SampleAspectConfiguration").Should().BeSameAs(bSample); b1.GetAspectConfiguration("SampleConfiguration").Should().BeSameAs(bSample); b1.GetAspectConfiguration("Sample").Should().BeSameAs(bSample); b1.GetAspectConfiguration("SampleAspect").Should().BeSameAs(bSample); var bAnother = b1.GetAspectConfiguration <AnotherAspectConfiguration>(); Debug.Assert(bAnother != null); bSample.Element("Path")?.Value.Should().Be("comm/ands"); b1.ExcludedTypes.Should().BeEquivalentTo("CK.Core.ActivityMonitor, CK.ActivityMonitor", "CK.Testing.StObjEngineTestHelper, CK.Testing.StObjEngine"); b1.OutputPath.Should().Be(new NormalizedPath("Another/Relative")); b1.CompileOption.Should().Be(CompileOption.Parse); b1.GenerateSourceFiles.Should().BeTrue(); c.GeneratedAssemblyName.Should().Be("CK.StObj.AutoAssembly.Not the default"); c.InformationalVersion.Should().Be("This will be in the generated Assembly."); c.TraceDependencySorterInput.Should().BeTrue(); c.TraceDependencySorterOutput.Should().BeTrue(); c.RevertOrderingNames.Should().BeTrue(); c.GlobalExcludedTypes.Should().BeEquivalentTo("CK.Core.ActivityMonitor, CK.ActivityMonitor", "CK.Testing.StObjEngineTestHelper, CK.Testing.StObjEngine"); c.Aspects.Should().HaveCount(2); c.Aspects[0].Should().BeAssignableTo <SampleAspectConfiguration>(); c.Aspects[1].Should().BeAssignableTo <AnotherAspectConfiguration>(); }
/// <summary> /// Low level helper that initializes a new <see cref="StObjEngineConfiguration"/> and computes the force setup flag /// that can be used by other helpers that need to run a setup. /// </summary> /// <param name="helper">The <see cref="IStObjSetupTestHelper"/> helper.</param> /// <returns>The configuration and the flag.</returns> static public (StObjEngineConfiguration Configuration, ForceSetupLevel ForceSetup) CreateDefaultConfiguration(IActivityMonitor monitor, IStObjSetupTestHelper helper) { var stObjConf = new StObjEngineConfiguration { RevertOrderingNames = helper.StObjRevertOrderingNames, TraceDependencySorterInput = helper.StObjTraceGraphOrdering, TraceDependencySorterOutput = helper.StObjTraceGraphOrdering, }; // BinPath by default is: the first "CKSetup/DefaultBinPaths" if it has been configured // otherwise it is the {ClosestSUTProjectFolder}/{PathToBin} (if no ClosestSUTProjectFolder // has been found, {ClosestSUTProjectFolder} is the {TestProjectFolder} so {ClosestSUTProjectFolder}/{PathToBin} // is... this {BinFolder}) NormalizedPath binPath; if (helper.CKSetup.DefaultBinPaths.Count > 0) { binPath = helper.CKSetup.DefaultBinPaths[0]; monitor.Info($"Using first configured 'CKSetup/DefaultBinPaths' = {binPath}"); } else { binPath = helper.ClosestSUTProjectFolder.Combine(helper.PathToBin); monitor.Info($"No 'CKSetup/DefaultBinPaths' configuration. Using ClosestSUTProjectFolder/PathToBin: {binPath}."); } var b = new BinPathConfiguration { // The name of the BinPath to use is the current IStObjMapTestHelper.BinPathName. Name = helper.BinPathName, Path = binPath, // Then the OutputPath will copy the generated assembly to this bin folder. OutputPath = helper.BinFolder, CompileOption = CompileOption.Compile, // ...and the G0.cs to the TestProjectFolder. GenerateSourceFiles = helper.StObjGenerateSourceFiles, ProjectPath = helper.TestProjectFolder }; stObjConf.BinPaths.Add(b); // Consider by default the CKSetup configuration that be not None, // but if it is None, set it to Engine: the engine must run even if // all the binaries are unchanged to check the G0.cs and assembly. var f = helper.CKSetup.ForceSetup; if (f == ForceSetupLevel.None) { monitor.Trace($"Setting CKSetup ForceSetupLevel to Engine so it can check the required artifacts."); f = ForceSetupLevel.Engine; } return(stObjConf, f); }
public void configuration_to_xml() { StObjEngineConfiguration c1 = new StObjEngineConfiguration(_config); var e1 = c1.ToXml(); e1 = NormalizeWithoutAnyOrder(e1); StObjEngineConfiguration c2 = new StObjEngineConfiguration(e1); var e2 = c2.ToXml(); e2 = NormalizeWithoutAnyOrder(e2); e1.Should().BeEquivalentTo(e2); }
static NormalizedPath GenerateTSCode(string testName, params Type[] types) { var output = TestHelper.CleanupFolder(_outputFolder.AppendPart(testName), false); var config = new StObjEngineConfiguration(); config.Aspects.Add(new TypeScriptAspectConfiguration()); var b = new BinPathConfiguration(); b.AspectConfigurations.Add(new XElement("TypeScript", new XElement("OutputPath", output))); config.BinPaths.Add(b); var engine = new StObjEngine(TestHelper.Monitor, config); engine.Run(new MonoCollectorResolver(types)).Should().BeTrue("StObjEngine.Run worked."); Directory.Exists(output).Should().BeTrue(); return(output); }
CKSetupRunResult DoRunStObjSetup(StObjEngineConfiguration stObjConf, ForceSetupLevel forceSetup) { Throw.CheckNotNullArgument(stObjConf); using (_ckSetup.Monitor.OpenInfo($"Invoking StObjSetupRunning event.")) { try { var ev = new StObjSetupRunningEventArgs(stObjConf, forceSetup); _stObjSetupRunning?.Invoke(this, ev); var ckSetupConf = new SetupConfiguration(new XDocument(ev.StObjEngineConfiguration.ToXml()), "CK.Setup.StObjEngine, CK.StObj.Engine"); ckSetupConf.CKSetupName = _ckSetup.TestProjectName; return(_ckSetup.CKSetup.Run(ckSetupConf, forceSetup: ev.ForceSetup)); } catch (Exception ex) { _ckSetup.Monitor.Error(ex); throw; } } }
static (NormalizedPath BinTSPath1, NormalizedPath BinTSPath2) GenerateTSCode(string testName, params Type[] types) { var output1 = TestHelper.CleanupFolder(_outputFolder.AppendPart(testName).AppendPart("b1"), false); var output2 = TestHelper.CleanupFolder(_outputFolder.AppendPart(testName).AppendPart("b2"), false); var config = new StObjEngineConfiguration(); config.Aspects.Add(new TypeScriptAspectConfiguration()); var b1 = new BinPathConfiguration(); b1.AspectConfigurations.Add(new XElement("TypeScript", new XElement("OutputPath", output1))); var b2 = new BinPathConfiguration(); b2.AspectConfigurations.Add(new XElement("TypeScript", new XElement("OutputPath", output2))); // b3 has no TypeScript aspect or no OutputPath or an empty OutputPath: nothing must be generated and this is just a warning. var b3 = new BinPathConfiguration(); switch (Environment.TickCount % 3) { case 0: b3.AspectConfigurations.Add(new XElement("TypeScript", new XElement("OutputPath", " "))); break; case 1: b3.AspectConfigurations.Add(new XElement("TypeScript")); break; } config.BinPaths.Add(b1); config.BinPaths.Add(b2); config.BinPaths.Add(b3); var engine = new StObjEngine(TestHelper.Monitor, config); engine.Run(new MonoCollectorResolver(types)).Should().BeTrue("StObjEngine.Run worked."); Directory.Exists(output1).Should().BeTrue(); Directory.Exists(output2).Should().BeTrue(); return(output1, output2); }
/// <summary> /// Initializes a new event with an existing configuration. /// </summary> /// <param name="conf">The configuration.</param> /// <param name="forceSetup">Initial <see cref="ForceSetup"/> configuration.</param> public StObjSetupRunningEventArgs(StObjEngineConfiguration conf, ForceSetupLevel forceSetup) { _configuration = conf; ForceSetup = forceSetup; }