Skip to content

Commit 8a802cd

Browse files
committed
Add test for non zero return codes
1 parent 2b89752 commit 8a802cd

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/ServiceControlInstaller.Engine.UnitTests/Setup/SetupInstanceTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ public void Should_capture_and_rethrow_failures()
1717

1818
Assert.That(ex.Message, Does.Contain("Fake exception"));
1919
}
20+
21+
[Test]
22+
public void Should_capture_and_rethrow_non_zero_exit_codes()
23+
{
24+
var ex = Assert.Throws<Exception>(() => InstanceSetup.Run(TestContext.CurrentContext.WorkDirectory, "SetupProcessFake.exe", "test", "non-zero-exit-code"));
25+
26+
Assert.That(ex.Message, Does.Contain("returned a non-zero exit code: 3"));
27+
}
2028
}

src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ internal static void Run(string installPath, string exeName, string instanceName
6060

6161
if (p.ExitCode != 0)
6262
{
63-
throw new Exception($"{exeName} threw an error when performing setup. This typically indicates a configuration error. The error output from {exeName} was:\r\n {error}");
63+
throw new Exception($"{exeName} returned a non-zero exit code: {p.ExitCode}. This typically indicates a configuration error. The error output was:\r\n {error}");
6464
}
6565
}
6666
}

src/SetupProcessFake/Program.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
if (args.Any(a => a == "fail"))
22
{
33
throw new Exception("Fake exception");
4-
}
4+
}
5+
6+
if (args.Any(a => a == "non-zero-exit-code"))
7+
{
8+
return 3;
9+
}
10+
11+
return 0;

0 commit comments

Comments
 (0)