Merge pull request 141 from dev/175-run-ps-from-xunit into develop
This commit is contained in:
commit
074acd4a8f
|
@ -194,7 +194,7 @@ native-tests: dotnetlibs/monad_native
|
|||
|
||||
xunit-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr $(addprefix $(TESTRUN_FOLDER)/, ps_test.dll xunit.console.netcore.exe xunit.runner.utility.dll xunit.abstractions.dll xunit.execution.dll)
|
||||
# execute the xUnit runner, with XML output
|
||||
cd exec_env/app_base && PSMODULEPATH=$(shell pwd)/exec_env/app_base/Modules LD_LIBRARY_PATH=../coreclr:. ../coreclr/corerun xunit.console.netcore.exe ps_test.dll -xml ../../xunittests.xml
|
||||
exec_env/app_base/runps-test.sh ps_test.dll -xml ../../xunittests.xml
|
||||
|
||||
pester-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr
|
||||
# execute the Pester tests, which needs a TEMP environment variable to be set
|
||||
|
|
7
scripts/runps-test.sh
Executable file
7
scripts/runps-test.sh
Executable file
|
@ -0,0 +1,7 @@
|
|||
#!/bin/bash
|
||||
|
||||
CWD=$(pwd)
|
||||
SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
cd "$SCRIPTDIR"
|
||||
PSMODULEPATH="$SCRIPTDIR/Modules" LD_LIBRARY_PATH="$SCRIPTDIR" ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa xunit.console.netcore.exe xunit.console.netcore.exe "$@"
|
48
src/ps_test/test_Runspace.cs
Normal file
48
src/ps_test/test_Runspace.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using Xunit;
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Runspaces;
|
||||
|
||||
namespace PSTests
|
||||
{
|
||||
public static class RunspaceTests
|
||||
{
|
||||
[Fact]
|
||||
public static void TestMethod()
|
||||
{
|
||||
InitialSessionState iss = InitialSessionState.CreateDefault2();
|
||||
|
||||
// NOTE: instantiate custom host myHost for the next line to capture stdout and stderr output
|
||||
// in addition to just the PSObjects
|
||||
using (Runspace rs = RunspaceFactory.CreateRunspace(/*myHost,*/iss))
|
||||
{
|
||||
rs.Open();
|
||||
using (PowerShell ps = PowerShell.Create())
|
||||
{
|
||||
ps.Runspace = rs;
|
||||
|
||||
string script = "get-process | select-object -first 3";
|
||||
ps.AddScript(script);
|
||||
|
||||
// IMPORTANT NOTE: do not call AddCommand("out-host") here or
|
||||
// MergeMyResults, otherwise Invoke will not return any objects
|
||||
|
||||
var results = ps.Invoke();
|
||||
|
||||
// check that there are 3 captured objects
|
||||
int objCount = 0;
|
||||
foreach (var result in results)
|
||||
{
|
||||
// this is how an object would be captured here and looked at,
|
||||
// each result is a PSObject with the data from the pipeline
|
||||
++objCount;
|
||||
Assert.NotNull(result);
|
||||
}
|
||||
Assert.Equal(3,objCount);
|
||||
ps.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue