From c1c7c8ede3d56946089edd1879b1eabbb6668763 Mon Sep 17 00:00:00 2001 From: Daniel Egbers Date: Mon, 23 Nov 2020 19:35:19 +0100 Subject: [PATCH 1/3] cache script per file instead of per directory --- src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs index 6bf3809c..470a4e52 100644 --- a/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs +++ b/src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs @@ -45,7 +45,7 @@ private async Task DownloadAndRunCode(ExecuteScriptCommandOpti private string GetLibrary(ExecuteScriptCommandOptions executeOptions) { - var projectFolder = FileUtils.GetPathToScriptTempFolder(Path.GetDirectoryName(executeOptions.File.Path)); + var projectFolder = FileUtils.GetPathToScriptTempFolder(executeOptions.File.Path); var executionCacheFolder = Path.Combine(projectFolder, "execution-cache"); var pathToLibrary = Path.Combine(executionCacheFolder, "script.dll"); From 9dbd650db180475ea76caef82ad0f28e4986816d Mon Sep 17 00:00:00 2001 From: Daniel Egbers Date: Mon, 23 Nov 2020 22:14:21 +0100 Subject: [PATCH 2/3] adjust test to changed cache location --- src/Dotnet.Script.Tests/ExecutionCacheTests.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Dotnet.Script.Tests/ExecutionCacheTests.cs b/src/Dotnet.Script.Tests/ExecutionCacheTests.cs index 64992f3c..6ba4e4b6 100644 --- a/src/Dotnet.Script.Tests/ExecutionCacheTests.cs +++ b/src/Dotnet.Script.Tests/ExecutionCacheTests.cs @@ -25,10 +25,12 @@ public void ShouldNotUpdateHashWhenSourceIsNotChanged() WriteScript(pathToScript, "WriteLine(42);"); var firstResult = Execute(pathToScript); Assert.Contains("42", firstResult.output); + Assert.NotNull(firstResult.hash); WriteScript(pathToScript, "WriteLine(42);"); var secondResult = Execute(pathToScript); Assert.Contains("42", secondResult.output); + Assert.NotNull(secondResult.hash); Assert.Equal(firstResult.hash, secondResult.hash); } @@ -45,10 +47,12 @@ public void ShouldUpdateHashWhenSourceChanges() WriteScript(pathToScript, "WriteLine(42);"); var firstResult = Execute(pathToScript); Assert.Contains("42", firstResult.output); + Assert.NotNull(firstResult.hash); WriteScript(pathToScript, "WriteLine(84);"); var secondResult = Execute(pathToScript); Assert.Contains("84", secondResult.output); + Assert.NotNull(secondResult.hash); Assert.NotEqual(firstResult.hash, secondResult.hash); } @@ -103,7 +107,7 @@ public void ShouldCopyDllAndPdbToExecutionCacheFolder() private static string GetPathToExecutionCache(string pathToScript) { - var pathToTempFolder = Path.GetDirectoryName(Dotnet.Script.DependencyModel.ProjectSystem.FileUtils.GetPathToScriptTempFolder(pathToScript)); + var pathToTempFolder = Dotnet.Script.DependencyModel.ProjectSystem.FileUtils.GetPathToScriptTempFolder(pathToScript); var pathToExecutionCache = Path.Combine(pathToTempFolder, "execution-cache"); return pathToExecutionCache; } From 2a098f2a20832cb47b2b47b2f94d2b80b4739427 Mon Sep 17 00:00:00 2001 From: Daniel Egbers Date: Mon, 23 Nov 2020 22:19:44 +0100 Subject: [PATCH 3/3] add test "should cache scripts from same folder individually" --- .../ExecutionCacheTests.cs | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/Dotnet.Script.Tests/ExecutionCacheTests.cs b/src/Dotnet.Script.Tests/ExecutionCacheTests.cs index 6ba4e4b6..7b4a0a15 100644 --- a/src/Dotnet.Script.Tests/ExecutionCacheTests.cs +++ b/src/Dotnet.Script.Tests/ExecutionCacheTests.cs @@ -1,5 +1,6 @@ -using System.IO; using Dotnet.Script.Shared.Tests; +using System; +using System.IO; using Xunit; using Xunit.Abstractions; @@ -89,6 +90,61 @@ public void ShouldCopyDllAndPdbToExecutionCacheFolder() } } + [Fact] + public void ShouldCacheScriptsFromSameFolderIndividually() + { + (string Output, bool Cached) Execute(string pathToScript) + { + var result = ScriptTestRunner.Default.Execute($"{pathToScript} --debug"); + return (Output: result.output, Cached: result.output.Contains("Using cached compilation")); + } + + using (var scriptFolder = new DisposableFolder()) + { + var pathToScriptA = Path.Combine(scriptFolder.Path, "script.csx"); + var pathToScriptB = Path.Combine(scriptFolder.Path, "script"); + + + var idScriptA = Guid.NewGuid().ToString(); + File.AppendAllText(pathToScriptA, $@"WriteLine(""{idScriptA}"");"); + + var idScriptB = Guid.NewGuid().ToString(); + File.AppendAllText(pathToScriptB, $@"WriteLine(""{idScriptB}"");"); + + + var firstResultOfScriptA = Execute(pathToScriptA); + Assert.Contains(idScriptA, firstResultOfScriptA.Output); + Assert.False(firstResultOfScriptA.Cached); + + var firstResultOfScriptB = Execute(pathToScriptB); + Assert.Contains(idScriptB, firstResultOfScriptB.Output); + Assert.False(firstResultOfScriptB.Cached); + + + var secondResultOfScriptA = Execute(pathToScriptA); + Assert.Contains(idScriptA, secondResultOfScriptA.Output); + Assert.True(secondResultOfScriptA.Cached); + + var secondResultOfScriptB = Execute(pathToScriptB); + Assert.Contains(idScriptB, secondResultOfScriptB.Output); + Assert.True(secondResultOfScriptB.Cached); + + + var idScriptB2 = Guid.NewGuid().ToString(); + File.AppendAllText(pathToScriptB, $@"WriteLine(""{idScriptB2}"");"); + + + var thirdResultOfScriptA = Execute(pathToScriptA); + Assert.Contains(idScriptA, thirdResultOfScriptA.Output); + Assert.True(thirdResultOfScriptA.Cached); + + var thirdResultOfScriptB = Execute(pathToScriptB); + Assert.Contains(idScriptB, thirdResultOfScriptB.Output); + Assert.Contains(idScriptB2, thirdResultOfScriptB.Output); + Assert.False(thirdResultOfScriptB.Cached); + } + } + private (string output, string hash) Execute(string pathToScript) { var result = ScriptTestRunner.Default.Execute(pathToScript); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy