Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Dotnet.Script.Core/Commands/ExecuteScriptCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private async Task<TReturn> DownloadAndRunCode<TReturn>(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");

Expand Down
64 changes: 62 additions & 2 deletions src/Dotnet.Script.Tests/ExecutionCacheTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using Dotnet.Script.Shared.Tests;
using System;
using System.IO;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -25,10 +26,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);
}
Expand All @@ -45,10 +48,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);
}
Expand Down Expand Up @@ -85,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);
Expand All @@ -103,7 +163,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;
}
Expand Down