-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from perrylets/new-features
Add new properties and crude access to the internal process
- Loading branch information
Showing
5 changed files
with
108 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
namespace CommandExec.Tests; | ||
|
||
public class EnvironmentTests | ||
{ | ||
[Fact(DisplayName = "Run shell command")] | ||
public void ShellCommandTest() | ||
{ | ||
Command shell = Command.Shell("echo test"); | ||
Command shell = CommandUtils.Shell("echo", "test"); | ||
shell | ||
.RedirectStdOut() | ||
.RedirectStdErr() | ||
.Run(); | ||
|
||
string STDOut = shell.STDOut.ReadToEnd().TrimEnd(); | ||
Assert.Equal("test", STDOut); | ||
|
||
//! There can be errors with the shell itself, not the process. | ||
// string STDErr = shell.STDErr.ReadToEnd().TrimEnd(); | ||
// Assert.Equal(string.Empty, STDErr); | ||
Assert.Equal("test", shell.stdOut.ReadToEnd().TrimEnd()); | ||
Assert.Equal(0, shell.exitCode); | ||
Assert.False(shell.hasError); | ||
} | ||
|
||
[Fact(DisplayName = "Check if command exists")] | ||
public void CommandExistsTest() | ||
{ | ||
Assert.True(CommandUtils.CommandExists("type")); | ||
Assert.False(CommandUtils.CommandExists("fake-test-command-that-is-not-real")); | ||
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
Command cmd = CommandUtils.Shell("file", "/bin/sh").RedirectStdOut(); | ||
cmd.Run(); | ||
Assert.Equal("/bin/sh: symbolic link to", cmd.stdOut.ReadToEnd()[..25]); | ||
} | ||
Assert.True(CommandUtils.Exists("type")); | ||
Assert.False(CommandUtils.Exists("fake-test-command-that-is-not-real")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters