Skip to content

Commit

Permalink
(cake-buildGH-2099) Fix and add script cache integration test
Browse files Browse the repository at this point in the history
* relates to cake-build#2099
  • Loading branch information
devlead committed Apr 8, 2022
1 parent 48baa8a commit c9cb034
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
37 changes: 31 additions & 6 deletions tests/integration/Cake/ScriptCache.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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<FilePath, CakeSettings> CakeExecuteScript { get; }
private Func<FilePath, FileHash> CalculateFileHash { get; }
Expand All @@ -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<ProcessArgumentBuilder, ProcessArgumentBuilder> argumentCustomization) =>
public (TimeSpan Elapsed, string Hash) TimeCakeExecuteScript(Func<ProcessArgumentBuilder, ProcessArgumentBuilder> argumentCustomization, FilePath scriptPath = null) =>
(
Time(
() => {
Settings.ArgumentCustomization = argumentCustomization;
CakeExecuteScript(
ScriptPath,
scriptPath ?? ScriptPath,
Settings);
}),
CalculateFileHash(ScriptCacheAssemblyPath).ToHex()
Expand All @@ -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<string, string> {
{ "CAKE_SETTINGS_ENABLESCRIPTCACHE", "true" }
{ "CAKE_SETTINGS_ENABLESCRIPTCACHE", "true" },
{ "TEST_ROOT_PATH", configCacheRootPath.FullPath },
{ "TEST_LEAF_PATH", "CacheLeafPath" }
},
Verbosity = Verbosity.Quiet
};
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -129,8 +143,19 @@ Task("Cake.ScriptCache.ReCompile")
Assert.NotEqual(data.CompileResult.Hash , data.ReCompileResult.Hash);
});

Task("Cake.ScriptCache.Config")
.Does<ScriptCacheData>((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");
.IsDependentOn("Cake.ScriptCache.ReCompile")
.IsDependentOn("Cake.ScriptCache.Config");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Information("Hello from compiled script!");
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[Paths]
Cache=%TEST_ROOT_PATH%/cake-build/%TEST_LEAF_PATH%

0 comments on commit c9cb034

Please sign in to comment.