Skip to content

Commit e858c15

Browse files
committed
trying to make tests cross-platform
testing that generated exectuables execute correctly
1 parent 81677f4 commit e858c15

File tree

1 file changed

+50
-13
lines changed

1 file changed

+50
-13
lines changed

src/Dotnet.Script.Tests/ScriptPublisherTests.cs

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Dotnet.Script.DependencyModel.Environment;
1+
using Dotnet.Script.Core;
2+
using Dotnet.Script.DependencyModel.Environment;
3+
using Dotnet.Script.DependencyModel.Logging;
4+
using Dotnet.Script.DependencyModel.Process;
25
using System.IO;
36
using Xunit;
47

@@ -7,10 +10,12 @@ namespace Dotnet.Script.Tests
710
public class ScriptPublisherTests
811
{
912
private readonly ScriptEnvironment _scriptEnvironment;
13+
private readonly CommandRunner _commandRunner;
1014

1115
public ScriptPublisherTests()
1216
{
1317
_scriptEnvironment = ScriptEnvironment.Default;
18+
_commandRunner = new CommandRunner(GetLogFactory());
1419
}
1520

1621
[Fact]
@@ -22,9 +27,13 @@ public void SimplePublishTest()
2227
var mainPath = Path.Combine(scriptFolder.Path, "main.csx");
2328
File.WriteAllText(mainPath, code);
2429
var args = new string[] { "publish", mainPath };
25-
var result = Execute(string.Join(" ", args), scriptFolder.Path);
26-
Assert.Equal(0, result.exitCode);
27-
Assert.True(File.Exists(Path.Combine(scriptFolder.Path, "publish", "script.exe")));
30+
var publishResult = Execute(string.Join(" ", args), scriptFolder.Path);
31+
Assert.Equal(0, publishResult.exitCode);
32+
33+
var exePath = Path.Combine(scriptFolder.Path, "publish", "script");
34+
var executableRunResult = _commandRunner.Execute(exePath);
35+
36+
Assert.Equal(0, executableRunResult);
2837
}
2938
}
3039

@@ -38,9 +47,13 @@ public void SimplePublishToOtherFolderTest()
3847
var mainPath = Path.Combine(workspaceFolder.Path, "main.csx");
3948
File.WriteAllText(mainPath, code);
4049
var args = new string[] { "publish", mainPath, "-o", publishRootFolder.Path };
41-
var result = Execute(string.Join(" ", args), workspaceFolder.Path);
42-
Assert.Equal(0, result.exitCode);
43-
Assert.True(File.Exists(Path.Combine(publishRootFolder.Path, "script.exe")));
50+
var publishResult = Execute(string.Join(" ", args), workspaceFolder.Path);
51+
Assert.Equal(0, publishResult.exitCode);
52+
53+
var exePath = Path.Combine(publishRootFolder.Path, "script");
54+
var executableRunResult = _commandRunner.Execute(exePath);
55+
56+
Assert.Equal(0, executableRunResult);
4457
}
4558
}
4659

@@ -53,9 +66,13 @@ public void SimplePublishFromCurrentDirectoryTest()
5366
var mainPath = Path.Combine(workspaceFolder.Path, "main.csx");
5467
File.WriteAllText(mainPath, code);
5568
var args = new string[] { "publish", "main.csx" };
56-
var result = Execute(string.Join(" ", args), workspaceFolder.Path);
57-
Assert.Equal(0, result.exitCode);
58-
Assert.True(File.Exists(Path.Combine(workspaceFolder.Path, "publish", "script.exe")));
69+
var publishResult = Execute(string.Join(" ", args), workspaceFolder.Path);
70+
Assert.Equal(0, publishResult.exitCode);
71+
72+
var exePath = Path.Combine(workspaceFolder.Path, "publish", "script");
73+
var executableRunResult = _commandRunner.Execute(exePath);
74+
75+
Assert.Equal(0, executableRunResult);
5976
}
6077
}
6178

@@ -68,9 +85,13 @@ public void SimplePublishFromCurrentDirectoryToOtherFolderTest()
6885
var mainPath = Path.Combine(workspaceFolder.Path, "main.csx");
6986
File.WriteAllText(mainPath, code);
7087
var args = new string[] { "publish", "main.csx", "-o", "publish" };
71-
var result = Execute(string.Join(" ", args), workspaceFolder.Path);
72-
Assert.Equal(0, result.exitCode);
73-
Assert.True(File.Exists(Path.Combine(workspaceFolder.Path, "publish", "script.exe")));
88+
var publishResult = Execute(string.Join(" ", args), workspaceFolder.Path);
89+
Assert.Equal(0, publishResult.exitCode);
90+
91+
var exePath = Path.Combine(workspaceFolder.Path, "publish", "script");
92+
var executableRunResult = _commandRunner.Execute(exePath);
93+
94+
Assert.Equal(0, executableRunResult);
7495
}
7596
}
7697

@@ -98,5 +119,21 @@ private string[] GetDotnetScriptArguments(string args)
98119
#endif
99120
return new[] { "exec", Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "..", "..", "Dotnet.Script", "bin", configuration, _scriptEnvironment.TargetFramework, "dotnet-script.dll"), args };
100121
}
122+
123+
private LogFactory GetLogFactory()
124+
{
125+
var logger = new ScriptLogger(ScriptConsole.Default.Error, true);
126+
return type => ((level, message) =>
127+
{
128+
if (level == LogLevel.Debug)
129+
{
130+
logger.Verbose(message);
131+
}
132+
if (level == LogLevel.Info)
133+
{
134+
logger.Log(message);
135+
}
136+
});
137+
}
101138
}
102139
}

0 commit comments

Comments
 (0)