Skip to content

Commit c3c1ef8

Browse files
committed
Review changes
1 parent d6cb6f0 commit c3c1ef8

File tree

3 files changed

+42
-45
lines changed

3 files changed

+42
-45
lines changed

src/Dotnet.Script.Tests/ScriptExecutionTests.cs

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class ScriptExecutionTests
2020
{
2121
[Fact]
2222
public void ShouldExecuteHelloWorld()
23-
{
23+
{
2424
var result = ExecuteInProcess(Path.Combine("HelloWorld", "HelloWorld.csx"));
2525
//Assert.Contains("Hello World", result.output);
2626
}
@@ -47,9 +47,9 @@ public void ShouldHandlePackageWithNativeLibraries()
4747
{
4848
var result = Execute(Path.Combine("NativeLibrary", "NativeLibrary.csx"));
4949
Assert.Contains("Connection successful", result.output);
50-
}
50+
}
5151
}
52-
52+
5353
[Fact]
5454
public static void ShouldReturnExitCodeOnenWhenScriptFails()
5555
{
@@ -88,7 +88,7 @@ public static void ShouldHandleIssue166()
8888
{
8989
var result = Execute(Path.Combine("Issue166", "Issue166.csx"));
9090
Assert.Contains("Connection successful", result.output);
91-
}
91+
}
9292
}
9393

9494
[Fact]
@@ -109,7 +109,7 @@ public static void ShouldPassKnownArgumentToScriptWhenEscapedByDoubleHyphen()
109109
public static void ShouldNotPassUnEscapedKnownArgumentToScript()
110110
{
111111
var result = Execute($"{Path.Combine("Arguments", "Arguments.csx")}", "-v");
112-
Assert.DoesNotContain("-v", result.output);
112+
Assert.DoesNotContain("-v", result.output);
113113
}
114114

115115
[Fact]
@@ -128,15 +128,15 @@ public static void ShouldHandleIssue181()
128128

129129
[Fact]
130130
public static void ShouldHandleIssue198()
131-
{
131+
{
132132
var result = Execute(Path.Combine("Issue198", "Issue198.csx"));
133133
Assert.Contains("NuGet.Client", result.output);
134134
}
135135

136136

137137
[Fact]
138138
public static void ShouldHandleIssue204()
139-
{
139+
{
140140
var result = Execute(Path.Combine("Issue204", "Issue204.csx"));
141141
Assert.Contains("System.Net.WebProxy", result.output);
142142
}
@@ -203,22 +203,42 @@ public void ShouldSupportInlineNugetReferencesWithTrailingSemicoloninEvaluatedCo
203203
[Fact]
204204
public static void ShouldHandleIssue235()
205205
{
206-
var logger = new ScriptLogger(Console.Error, true);
207-
var runtimeDependencyResolver = new RuntimeDependencyResolver(type => ((level, message) => {}));
208-
var compiler = new ScriptCompiler(logger, runtimeDependencyResolver);
209-
//Copied from Execute(string fixture, params string[] arguments)
210-
//Probably there should be a better place for this
211-
var workingDirectory = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "TestFixtures", "Issue235");
212-
var scriptContext = new ScriptContext(SourceText.From(File.ReadAllText(Path.Combine(workingDirectory, "TestClass.csx"))), workingDirectory, Enumerable.Empty<string>(), scriptMode: ScriptMode.REPL);
213-
var compilationResult = compiler.CreateCompilationContext<object, InteractiveScriptGlobals>(scriptContext);
214-
using(var ms = File.OpenWrite(Path.Combine(workingDirectory, "TestClass.dll")))
206+
string code =
207+
@"using AgileObjects.AgileMapper;
208+
public class TestClass
209+
{
210+
public TestClass()
211+
{
212+
IMapper mapper = Mapper.CreateNew();
213+
}
214+
}";
215+
216+
string script =
217+
@"#! ""netcoreapp2.0""
218+
#r ""nuget: AgileObjects.AgileMapper, 0.23.1""
219+
#r ""TestLibrary.dll""
220+
221+
using AgileObjects.AgileMapper;
222+
223+
IMapper mapper = Mapper.CreateNew();
224+
var testClass = new TestClass();
225+
Console.WriteLine(""Hello World!"");";
226+
227+
228+
using (var disposableFolder = new DisposableFolder())
215229
{
216-
compilationResult.Script.GetCompilation().Emit(ms);
230+
var projectFolder = Path.Combine(disposableFolder.Path, "TestLibrary");
231+
ProcessHelper.RunAndCaptureOutput("dotnet", new[] { "new classlib -n TestLibrary" }, disposableFolder.Path);
232+
ProcessHelper.RunAndCaptureOutput("dotnet", new[] { "add TestLibrary.csproj package AgileObjects.AgileMapper -v 0.23.0" }, projectFolder);
233+
File.WriteAllText(Path.Combine(projectFolder, "Class1.cs"), code);
234+
File.WriteAllText(Path.Combine(projectFolder, "script.csx"), script);
235+
ProcessHelper.RunAndCaptureOutput("dotnet", new[] { "build -c release -o ./" }, projectFolder);
236+
237+
var dotnetScriptArguments = GetDotnetScriptArguments(Path.Combine(projectFolder, "script.csx"));
238+
var result = ProcessHelper.RunAndCaptureOutput("dotnet", dotnetScriptArguments);
239+
Assert.Contains("Hello World!", result.output);
217240
}
218-
var result = Execute(Path.Combine("Issue235", "Issue235.csx"));
219-
Assert.Contains("Hello World!", result.output);
220241
}
221-
222242
private static (string output, int exitCode) Execute(string fixture, params string[] arguments)
223243
{
224244
var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments(Path.Combine("..", "..", "..", "TestFixtures", fixture), arguments));
@@ -236,8 +256,8 @@ private static (string output, int exitCode) ExecuteCode(string code)
236256
/// </summary>
237257
private static int ExecuteInProcess(string fixture, params string[] arguments)
238258
{
239-
var pathToFixture = Path.Combine("..", "..", "..","TestFixtures", fixture);
240-
var allArguments = new List<string>(new[] {pathToFixture});
259+
var pathToFixture = Path.Combine("..", "..", "..", "TestFixtures", fixture);
260+
var allArguments = new List<string>(new[] { pathToFixture });
241261
if (arguments != null)
242262
{
243263
allArguments.AddRange(arguments);

src/Dotnet.Script.Tests/TestFixtures/Issue235/Issue235.csx

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Dotnet.Script.Tests/TestFixtures/Issue235/TestClass.csx

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)