Skip to content

Commit 41af419

Browse files
committed
respect environment.exitcode
1 parent e1997aa commit 41af419

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/Dotnet.Script.Tests/ScriptExecutionTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,13 @@ public void ShouldThrowExceptionWhenSdkIsNotSupported()
493493
Assert.StartsWith("The sdk 'Unsupported' is not supported", processResult.StandardError);
494494
}
495495

496+
[Fact]
497+
public void ShouldRespectEnvironmentExitCodeOfTheScript()
498+
{
499+
var processResult = ScriptTestRunner.Default.ExecuteFixture("EnvironmentExitCode", "--no-cache");
500+
Assert.Equal(0xA0, processResult.ExitCode);
501+
}
502+
496503
private static string CreateTestScript(string scriptFolder)
497504
{
498505
string script = @"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Environment.ExitCode = 0xA0;
2+
Console.WriteLine("Hello World");

src/Dotnet.Script/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ private static int Wain(string[] args)
258258
};
259259

260260
var fileCommand = new ExecuteScriptCommand(ScriptConsole.Default, logFactory);
261-
return await fileCommand.Run<int, CommandLineScriptGlobals>(fileCommandOptions);
261+
var result = await fileCommand.Run<int, CommandLineScriptGlobals>(fileCommandOptions);
262+
if (Environment.ExitCode != 0) return Environment.ExitCode;
263+
264+
return result;
265+
262266
}
263267
else
264268
{

0 commit comments

Comments
 (0)