Skip to content

Commit 0e91e7c

Browse files
committed
Fix Compilation
1 parent 6a53b1a commit 0e91e7c

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/Dotnet.Script.Tests/ScriptExecutionTests.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Reflection;
66
using System.Security.Cryptography;
77
using Dotnet.Script.Core;
8+
using Dotnet.Script.DependencyModel.Context;
89
using Dotnet.Script.DependencyModel.Environment;
910
using Dotnet.Script.DependencyModel.Runtime;
1011
using Microsoft.CodeAnalysis;
@@ -211,15 +212,20 @@ public TestClass()
211212
IMapper mapper = Mapper.CreateNew();
212213
}
213214
}";
214-
var wd = Path.GetDirectoryName(typeof(ScriptExecutionTests).Assembly.Location);
215-
var compiler = new ScriptCompiler(new ScriptLogger(Console.Error, true), new RuntimeDependencyResolver(type => ((level, message) => {})));
216-
var res = compiler.CreateCompilationContext<object, InteractiveScriptGlobals>(new ScriptContext(SourceText.From(code), wd, Enumerable.Empty<string>()));
217-
using(var ms = File.OpenWrite(Path.Combine(wd, "Issue235.dll")))
215+
var logger = new ScriptLogger(Console.Error, true);
216+
var runtimeDependencyResolver = new RuntimeDependencyResolver(type => ((level, message) => {}));
217+
var compiler = new ScriptCompiler(logger, runtimeDependencyResolver);
218+
//Copied from Execute(string fixture, params string[] arguments)
219+
//Probably there should be a better place for this
220+
var workingDirectory = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "TestFixtures", "Issue235");
221+
var scriptContext = new ScriptContext(SourceText.From(code), workingDirectory, Enumerable.Empty<string>(), scriptMode: ScriptMode.REPL);
222+
var compilationResult = compiler.CreateCompilationContext<object, InteractiveScriptGlobals>(scriptContext);
223+
using(var ms = File.OpenWrite(Path.Combine(workingDirectory, "Issue235.dll")))
218224
{
219-
res.Script.GetCompilation().Emit(ms);
225+
compilationResult.Script.GetCompilation().Emit(ms);
220226
}
221-
// var result = Execute(Path.Combine("Issue235", "Issue235.csx"));
222-
// Assert.Contains("Hello World!", result.output);
227+
var result = Execute(Path.Combine("Issue235", "Issue235.csx"));
228+
Assert.Contains("Hello World!", result.output);
223229
}
224230

225231
private static (string output, int exitCode) Execute(string fixture, params string[] arguments)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
#! "netcoreapp2.0"
2+
#r "nuget: AgileObjects.AgileMapper, 0.23.1"
3+
#r "Issue235.dll"
24

5+
using AgileObjects.AgileMapper;
6+
7+
IMapper mapper = Mapper.CreateNew();
8+
new Submission#0.TestClass();
39
Console.WriteLine("Hello World!");

0 commit comments

Comments
 (0)