Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2e88ca1

Browse filesBrowse files
author
Tom Laird-McConnell
committed
Update unit test to run on linux too
1 parent e74132a commit 2e88ca1
Copy full SHA for 2e88ca1

File tree

Expand file treeCollapse file tree

1 file changed

+38
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+38
-4
lines changed
Open diff view settings
Collapse file

‎src/Dotnet.Script.Tests/ScaffoldingTests.cs‎

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Tests/ScaffoldingTests.cs
+38-4Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,57 @@ public void ShouldInitializeScriptFolder()
3030
}
3131

3232
[Fact]
33-
public void ShouldRunCsxScriptDirectly()
33+
public void ShouldRegisterToRunCsxScriptDirectly()
3434
{
3535
using (var scriptFolder = new DisposableFolder())
3636
{
3737
var (output, exitCode) = ScriptTestRunner.Default.Execute("init", scriptFolder.Path);
3838

3939
var scriptPath = Path.Combine(scriptFolder.Path, "main.csx");
40+
if (ScriptEnvironment.Default.IsWindows)
41+
{
42+
(output, exitCode) = ProcessHelper.RunAndCaptureOutput("reg.exe", @"query HKCU\Software\Classes\.csx");
43+
Assert.Equal(0, exitCode);
44+
(output, exitCode) = ProcessHelper.RunAndCaptureOutput("reg.exe", @"query HKCU\software\classes\dotnetscript");
45+
Assert.Equal(0, exitCode);
46+
}
47+
else
48+
{
49+
var text = File.ReadAllText(scriptPath);
50+
Assert.True(text.StartsWith("#!/usr/bin/env dotnet-script"), "should have shebang");
51+
Assert.True(text.IndexOf("\r\n") < 0, "should have not have windows cr/lf");
52+
}
53+
}
54+
}
55+
56+
[Fact]
57+
public void ShouldRunCsxScriptDirectly()
58+
{
59+
using (var scriptFolder = new DisposableFolder())
60+
{
61+
var scriptFolderPath = Path.Combine(Path.GetTempPath(), "xyz");
62+
Directory.CreateDirectory(scriptFolderPath);
63+
var (output, exitCode) = ScriptTestRunner.Default.Execute("init", scriptFolderPath);
64+
65+
var scriptPath = Path.Combine(scriptFolderPath, "main.csx");
4066

4167
if (ScriptEnvironment.Default.IsWindows)
4268
{
43-
(output, exitCode) = ProcessHelper.RunAndCaptureOutput("cmd.exe", $"/c {scriptPath}", scriptFolder.Path);
69+
(output, exitCode) = ProcessHelper.RunAndCaptureOutput("cmd.exe", $"/c {scriptPath}", scriptFolderPath);
70+
Assert.Equal("Hello world!", output.Trim());
4471
}
4572
else
4673
{
47-
(output, exitCode) = ProcessHelper.RunAndCaptureOutput(scriptPath, string.Empty, scriptFolder.Path);
74+
// this depends on dotnet-script being installed as a dotnet global tool because the shebang needs to
75+
// point to an executable in the environment. If you have dotnet-script installed as a global tool this
76+
// test will pass
77+
(output, exitCode) = ProcessHelper.RunAndCaptureOutput("dotnet-script", $"-h", scriptFolderPath);
78+
if (exitCode == 0)
79+
{
80+
(output, exitCode) = ProcessHelper.RunAndCaptureOutput(scriptPath, "");
81+
Assert.Equal("Hello world!", output.Trim());
82+
}
4883
}
49-
Assert.Equal("Hello world!", output.Trim());
5084
}
5185
}
5286

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.