Skip to content

Commit 85775d5

Browse files
committed
reverted breaking change to ScriptExector by restoring constructor overload and added null checks
1 parent d238444 commit 85775d5

6 files changed

Lines changed: 54 additions & 8 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using ScriptCs.Contracts;
2+
using System.Text;
3+
4+
namespace ScriptCs
5+
{
6+
public class NullScriptLibraryComposer : IScriptLibraryComposer
7+
{
8+
public void Compose(string workingDirectory, StringBuilder builder = null)
9+
{
10+
}
11+
12+
public string ScriptLibrariesFile
13+
{
14+
get { return string.Empty; }
15+
}
16+
}
17+
}

src/ScriptCs.Core/ScriptCs.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
<Compile Include="AssemblyResolver.cs" />
5353
<Compile Include="AssemblyUtility.cs" />
5454
<Compile Include="FileSystemMigrator.cs" />
55+
<Compile Include="NullScriptLibraryComposer.cs" />
5556
<Compile Include="ScriptLibraryComposer.cs" />
5657
<Compile Include="ScriptLibraryWrapper.cs" />
5758
<Compile Include="ReplCommands\AliasCommand.cs" />

src/ScriptCs.Core/ScriptExecutor.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ public class ScriptExecutor : IScriptExecutor
5353

5454
public IScriptLibraryComposer ScriptLibraryComposer { get; protected set; }
5555

56+
public ScriptExecutor(
57+
IFileSystem fileSystem, IFilePreProcessor filePreProcessor, IScriptEngine scriptEngine, ILog logger)
58+
: this(fileSystem, filePreProcessor, scriptEngine, logger, new NullScriptLibraryComposer())
59+
{
60+
}
61+
5662
public ScriptExecutor(
5763
IFileSystem fileSystem,
5864
IFilePreProcessor filePreProcessor,
@@ -202,6 +208,11 @@ IDictionary<string, object> state
202208

203209
protected internal virtual FilePreProcessorResult LoadScriptLibraries(string workingDirectory)
204210
{
211+
if (string.IsNullOrWhiteSpace(ScriptLibraryComposer.ScriptLibrariesFile))
212+
{
213+
return null;
214+
}
215+
205216
var scriptLibrariesPath = Path.Combine(workingDirectory, FileSystem.PackagesFolder,
206217
ScriptLibraryComposer.ScriptLibrariesFile);
207218

src/ScriptCs.Core/ScriptLibraryComposer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public virtual string ScriptLibrariesFile
6565

6666
public void Compose(string workingDirectory, StringBuilder builder = null)
6767
{
68+
if (string.IsNullOrWhiteSpace(ScriptLibrariesFile))
69+
{
70+
return;
71+
}
72+
6873
var namespaces = new List<string>();
6974
var references = new List<string>();
7075

src/ScriptCs/Command/InstallCommand.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ public CommandResult Execute()
4343
_logger.Info("Installing packages...");
4444

4545
var packagesFolder = Path.Combine(_fileSystem.CurrentDirectory, _fileSystem.PackagesFolder);
46-
var scriptLibrariesFile = Path.Combine(packagesFolder, _composer.ScriptLibrariesFile);
47-
48-
if (_fileSystem.DirectoryExists(packagesFolder))
46+
if (!string.IsNullOrWhiteSpace(_composer.ScriptLibrariesFile))
4947
{
50-
_logger.DebugFormat("Deleting: {0}", scriptLibrariesFile);
51-
_fileSystem.FileDelete(scriptLibrariesFile);
48+
var scriptLibrariesFile = Path.Combine(packagesFolder, _composer.ScriptLibrariesFile);
49+
50+
if (_fileSystem.FileExists(scriptLibrariesFile))
51+
{
52+
_logger.DebugFormat("Deleting: {0}", scriptLibrariesFile);
53+
_fileSystem.FileDelete(scriptLibrariesFile);
54+
}
5255
}
5356

5457
var packages = GetPackages(_fileSystem.CurrentDirectory);

test/ScriptCs.Core.Tests/ScriptExecutorTests.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5+
using Common.Logging;
56
using Moq;
67
using Moq.Protected;
78
using Ploeh.AutoFixture.Xunit;
@@ -504,13 +505,21 @@ public class TheLoadScriptLibrariesMethod
504505
{
505506
[Theory, ScriptCsAutoData]
506507
public void ShouldPreProcessTheScriptLibrariesFileIfPresent(
507-
[Frozen] Mock<IFilePreProcessor> preProcessor,
508508
[Frozen] Mock<IFileSystem> fileSystem,
509-
ScriptExecutor executor)
509+
[Frozen] Mock<IFilePreProcessor> preProcessor,
510+
[Frozen] Mock<IScriptEngine> engine,
511+
[Frozen] Mock<ILog> logger,
512+
[Frozen] Mock<IScriptLibraryComposer> composer)
510513
{
511-
preProcessor.Setup(p => p.ProcessFile(It.IsAny<string>())).Returns(new FilePreProcessorResult());
514+
// arrange
512515
fileSystem.Setup(fs => fs.FileExists(It.IsAny<string>())).Returns(true);
516+
var executor = new ScriptExecutor(
517+
fileSystem.Object, preProcessor.Object, engine.Object, logger.Object,composer.Object);
518+
519+
// act
513520
executor.LoadScriptLibraries("");
521+
522+
// assert
514523
preProcessor.Verify(p => p.ProcessFile(It.IsAny<string>()));
515524
}
516525
}

0 commit comments

Comments
 (0)