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
5 changes: 4 additions & 1 deletion src/ScriptCs.Hosting/ModuleLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class ModuleLoader : IModuleLoader
{"mono", "ScriptCs.Engine.Mono.dll"}
};

internal static readonly string DefaultCSharpExtension = ".csx";

private readonly IAssemblyResolver _resolver;
private readonly ILog _logger;
private readonly Action<Assembly, AggregateCatalog> _addToCatalog;
Expand Down Expand Up @@ -69,7 +71,8 @@ public void Load(IModuleConfiguration config, string[] modulePackagesPaths, stri
{
if (modulePackagesPaths == null) return;

if (moduleNames.Length == 1 && DefaultCSharpModules.ContainsKey(moduleNames[0])) // only CSharp module needed
// only CSharp module needed - use fast path
if (moduleNames.Length == 1 && DefaultCSharpModules.ContainsKey(moduleNames[0]) && (string.IsNullOrWhiteSpace(extension) || extension.Equals(DefaultCSharpExtension, StringComparison.InvariantCultureIgnoreCase)))
{
_logger.Debug("Only CSharp module is needed - will skip module lookup");
var csharpModuleAssembly = DefaultCSharpModules[moduleNames[0]];
Expand Down
15 changes: 13 additions & 2 deletions test/ScriptCs.Hosting.Tests/ModuleLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void ShouldLoadEngineAssemblyByHandIfItsTheOnlyModule()
var path = Path.Combine("c:\\foo", ModuleLoader.DefaultCSharpModules["roslyn"]);
_mockAssemblyUtility.Setup(x => x.LoadFile(path));
var loader = new ModuleLoader(_mockAssemblyResolver.Object, _mockLogger.Object, (a, c) => { }, _getModules, _mockFileSystem.Object, _mockAssemblyUtility.Object);
loader.Load(null, new string[0], "c:\\foo", null, "roslyn");
loader.Load(null, new string[0], "c:\\foo", ModuleLoader.DefaultCSharpExtension, "roslyn");

_mockAssemblyUtility.Verify(x => x.LoadFile(path), Times.Once());
}
Expand All @@ -130,11 +130,22 @@ public void ShouldLoadEngineModuleFromFile()

var config = new ModuleConfiguration(true, string.Empty, false, LogLevel.Debug, true,
new Dictionary<Type, object> {{typeof (string), "not loaded"}});
loader.Load(config, new string[0], "c:\\foo", null, "roslyn");
loader.Load(config, new string[0], "c:\\foo", ModuleLoader.DefaultCSharpExtension, "roslyn");

config.Overrides[typeof(string)].ShouldEqual("module loaded");
}

[Fact]
public void ShouldNotLoadEngineAssemblyByHandIfItsTheOnlyModuleButExtensionIsNotDefault()
{
var path = Path.Combine("c:\\foo", ModuleLoader.DefaultCSharpModules["roslyn"]);
_mockAssemblyUtility.Setup(x => x.LoadFile(path));
var loader = new ModuleLoader(_mockAssemblyResolver.Object, _mockLogger.Object, (a, c) => { }, _getModules, _mockFileSystem.Object, _mockAssemblyUtility.Object);

loader.Load(null, new string[0], "c:\\foo", ".fsx", "roslyn");
_mockAssemblyUtility.Verify(x => x.LoadFile(It.IsAny<string>()), Times.Never);
}

public class ModuleMetadata : IModuleMetadata
{
public string Name { get; set; }
Expand Down