From c9cb03495669b081414da9046ab02c4f3a5dc07c Mon Sep 17 00:00:00 2001 From: Mattias Karlsson Date: Wed, 6 Apr 2022 13:14:28 +0200 Subject: [PATCH] (GH-2099) Fix and add script cache integration test * relates to #2099 --- tests/integration/Cake/ScriptCache.cake | 37 ++++++++++++++++--- .../Cake/ScriptCache/Config/build.cake | 1 + .../Cake/ScriptCache/Config/cake.config | 2 + 3 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 tests/integration/resources/Cake/ScriptCache/Config/build.cake create mode 100644 tests/integration/resources/Cake/ScriptCache/Config/cake.config diff --git a/tests/integration/Cake/ScriptCache.cake b/tests/integration/Cake/ScriptCache.cake index 22d51fb6b7..f97268f064 100644 --- a/tests/integration/Cake/ScriptCache.cake +++ b/tests/integration/Cake/ScriptCache.cake @@ -7,9 +7,14 @@ public class ScriptCacheData public FilePath ScriptPath { get; } public FilePath ScriptCacheAssemblyPath { get; } public FilePath ScriptCacheHashPath { get; } + public FilePath ConfigScriptPath { get; } + public DirectoryPath ConfigScriptCachePath { get; } + public FilePath ConfigScriptCacheAssemblyPath { get; } + public FilePath ConfigScriptCacheHashPath { get; } public (TimeSpan Elapsed, string Hash) CompileResult { get; set; } public (TimeSpan Elapsed, string Hash) ExecuteResult { get; set; } public (TimeSpan Elapsed, string Hash) ReCompileResult { get; set; } + public (TimeSpan Elapsed, string Hash) ConfigCompileResult { get; set; } public CakeSettings Settings { get; } private Action CakeExecuteScript { get; } private Func CalculateFileHash { get; } @@ -28,15 +33,16 @@ public class ScriptCacheData return stopwatch.Elapsed; } - public (TimeSpan Elapsed, string Hash) TimeCakeExecuteScript() => TimeCakeExecuteScript(args => args); + public (TimeSpan Elapsed, string Hash) TimeCakeExecuteScript(FilePath scriptPath = null) + => TimeCakeExecuteScript(args => args, scriptPath); - public (TimeSpan Elapsed, string Hash) TimeCakeExecuteScript(Func argumentCustomization) => + public (TimeSpan Elapsed, string Hash) TimeCakeExecuteScript(Func argumentCustomization, FilePath scriptPath = null) => ( Time( () => { Settings.ArgumentCustomization = argumentCustomization; CakeExecuteScript( - ScriptPath, + scriptPath ?? ScriptPath, Settings); }), CalculateFileHash(ScriptCacheAssemblyPath).ToHex() @@ -52,9 +58,17 @@ public class ScriptCacheData var cacheDirectoryPath = scriptDirectoryPath.Combine("tools").Combine("cache"); ScriptCacheAssemblyPath = cacheDirectoryPath.CombineWithFilePath("build.cake.dll"); ScriptCacheHashPath = cacheDirectoryPath.CombineWithFilePath("build.cake.hash"); + var configScriptDirectoryPath = scriptDirectoryPath.Combine("Config"); + ConfigScriptPath = configScriptDirectoryPath.CombineWithFilePath("build.cake"); + var configCacheRootPath = configScriptDirectoryPath.Combine("CacheRootPath"); + ConfigScriptCachePath = configCacheRootPath.Combine("cake-build").Combine("CacheLeafPath"); + ConfigScriptCacheAssemblyPath = ConfigScriptCachePath.CombineWithFilePath("build.cake.dll"); + ConfigScriptCacheHashPath = ConfigScriptCachePath.CombineWithFilePath("build.cake.hash"); Settings = new CakeSettings { EnvironmentVariables = new Dictionary { - { "CAKE_SETTINGS_ENABLESCRIPTCACHE", "true" } + { "CAKE_SETTINGS_ENABLESCRIPTCACHE", "true" }, + { "TEST_ROOT_PATH", configCacheRootPath.FullPath }, + { "TEST_LEAF_PATH", "CacheLeafPath" } }, Verbosity = Verbosity.Quiet }; @@ -98,7 +112,7 @@ Task("Cake.ScriptCache.Compile") // Then Assert.True(FileExists(data.ScriptCacheAssemblyPath), $"Script Cache Assembly Path {data.ScriptCacheAssemblyPath} missing."); - Assert.True(FileExists(data.ScriptCacheAssemblyPath), $"Script Cache Hash Path {data.ScriptCacheHashPath} missing."); + Assert.True(FileExists(data.ScriptCacheHashPath), $"Script Cache Hash Path {data.ScriptCacheHashPath} missing."); }); var scriptCacheExecute = Task("Cake.ScriptCache.Execute"); @@ -129,8 +143,19 @@ Task("Cake.ScriptCache.ReCompile") Assert.NotEqual(data.CompileResult.Hash , data.ReCompileResult.Hash); }); +Task("Cake.ScriptCache.Config") + .Does((context, data) => { + // Given / When + data.ConfigCompileResult = data.TimeCakeExecuteScript(data.ConfigScriptPath); + + // Then + Assert.True(FileExists(data.ConfigScriptCacheAssemblyPath), $"Script Cache Assembly Path {data.ConfigScriptCacheAssemblyPath} missing."); + Assert.True(FileExists(data.ConfigScriptCacheHashPath), $"Script Cache Hash Path {data.ConfigScriptCacheHashPath} missing."); + }); + Task("Cake.ScriptCache") .IsDependentOn("Cake.ScriptCache.Setup") .IsDependentOn("Cake.ScriptCache.Compile") .IsDependentOn("Cake.ScriptCache.Execute") - .IsDependentOn("Cake.ScriptCache.ReCompile"); \ No newline at end of file + .IsDependentOn("Cake.ScriptCache.ReCompile") + .IsDependentOn("Cake.ScriptCache.Config"); \ No newline at end of file diff --git a/tests/integration/resources/Cake/ScriptCache/Config/build.cake b/tests/integration/resources/Cake/ScriptCache/Config/build.cake new file mode 100644 index 0000000000..e98d44e8e9 --- /dev/null +++ b/tests/integration/resources/Cake/ScriptCache/Config/build.cake @@ -0,0 +1 @@ +Information("Hello from compiled script!"); diff --git a/tests/integration/resources/Cake/ScriptCache/Config/cake.config b/tests/integration/resources/Cake/ScriptCache/Config/cake.config new file mode 100644 index 0000000000..af28129718 --- /dev/null +++ b/tests/integration/resources/Cake/ScriptCache/Config/cake.config @@ -0,0 +1,2 @@ +[Paths] +Cache=%TEST_ROOT_PATH%/cake-build/%TEST_LEAF_PATH% \ No newline at end of file