mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
merging upstream changes to local branch
Merge branch 'develop' of mshttps://msostc.visualstudio.com/DefaultCollection/PS/_git/monad-linux into dev/180-out-file
This commit is contained in:
+1
-1
Submodule src/monad updated: df562ce7ec...d541b07343
+1
-1
Submodule src/monad-ext updated: 20468e65da...ea31eca622
+1
-1
Submodule src/monad-native updated: a99c56eea3...5693da6a46
@@ -1,15 +1,34 @@
|
||||
Describe "Test-Environment-Variables" {
|
||||
It "Should have environment variable" {
|
||||
It "Should have environment variables" {
|
||||
Get-Item ENV: | Should Not BeNullOrEmpty
|
||||
}
|
||||
|
||||
It "Should be able to access the members of the environment variable in two ways" {
|
||||
(Get-Item ENV:HOME).Value | Should be "/root"
|
||||
(Get-Item ENV:HOSTNAME).Value | Should Not BeNullOrEmpty
|
||||
(Get-Item ENV:PATH).Value | Should Not BeNullOrEmpty
|
||||
It "Should have a nonempty PATH" {
|
||||
$ENV:PATH | Should Not BeNullOrEmpty
|
||||
}
|
||||
|
||||
(ls ENV:HOME).Value | Should be "/root"
|
||||
(ls ENV:HOSTNAME).Value | Should Not BeNullOrEmpty
|
||||
(ls ENV:PATH).Value | Should Not BeNullOrEmpty
|
||||
It "Should contain /bin in the PATH" {
|
||||
$ENV:PATH | Should Match "/bin"
|
||||
}
|
||||
|
||||
It "Should be able to access the members of the environment variable" {
|
||||
$expected = /bin/bash -c "cd ~ && pwd"
|
||||
|
||||
(Get-Item ENV:HOME).Value | Should Be $expected
|
||||
}
|
||||
|
||||
It "Should be able to set the environment variables" {
|
||||
$expected = "this is a test environment variable"
|
||||
{ $ENV:TESTENVIRONMENTVARIABLE = $expected } | Should Not Throw
|
||||
|
||||
$ENV:TESTENVIRONMENTVARIABLE | Should Not BeNullOrEmpty
|
||||
$ENV:TESTENVIRONMENTVARIABLE | Should Be $expected
|
||||
|
||||
}
|
||||
|
||||
It "Should have the correct HOSTNAME" {
|
||||
$expected = /bin/hostname
|
||||
|
||||
$ENV:HOSTNAME | Should Be $expected
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
Describe "Test-Remove-Item" {
|
||||
$testpath = "/tmp/"
|
||||
$testfile = "testfile.txt"
|
||||
$testfilepath = $testpath + $testfile
|
||||
Context "File removal Tests" {
|
||||
BeforeEach {
|
||||
New-Item -Name $testfile -Path $testpath -ItemType "file" -Value "lorem ipsum" -Force
|
||||
|
||||
Test-Path $testfilepath | Should Be $true
|
||||
|
||||
}
|
||||
|
||||
It "Should be able to be called on a regular file without error using the Path switch" {
|
||||
{ Remove-Item -Path $testfilepath } | Should Not Throw
|
||||
|
||||
Test-Path $testfilepath | Should Be $false
|
||||
}
|
||||
|
||||
It "Should be able to be called on a file without the Path switch" {
|
||||
{ Remove-Item $testfilepath } | Should Not Throw
|
||||
|
||||
Test-Path $testfilepath | Should Be $false
|
||||
}
|
||||
|
||||
It "Should be able to call the rm alias" {
|
||||
{ rm $testfilepath } | Should Not Throw
|
||||
|
||||
Test-Path $testfilepath | Should Be $false
|
||||
}
|
||||
|
||||
It "Should be able to call the del alias" {
|
||||
{ del $testfilepath } | Should Not Throw
|
||||
|
||||
Test-Path $testfilepath | Should Be $false
|
||||
}
|
||||
|
||||
It "Should be able to call the erase alias" {
|
||||
{ erase $testfilepath } | Should Not Throw
|
||||
|
||||
Test-Path $testfilepath | Should Be $false
|
||||
}
|
||||
|
||||
It "Should be able to call the ri alias" {
|
||||
{ ri $testfilepath } | Should Not Throw
|
||||
|
||||
Test-Path $testfilepath | Should Be $false
|
||||
}
|
||||
|
||||
It "Should not be able to remove a read-only document without using the force switch" {
|
||||
# Set to read only
|
||||
Set-ItemProperty -Path $testfilepath -Name IsReadOnly -Value $true
|
||||
|
||||
# attempt to remove the file
|
||||
{ Remove-Item $testfilepath -ErrorAction SilentlyContinue } | Should Not Throw
|
||||
|
||||
# validate
|
||||
Test-Path $testfilepath | Should Be $true
|
||||
|
||||
# remove using the -force switch on the readonly object
|
||||
Remove-Item $testfilepath -Force
|
||||
|
||||
# Validate
|
||||
Test-Path $testfilepath | Should Be $false
|
||||
}
|
||||
|
||||
It "Should be able to remove all files matching a regular expression with the include switch" {
|
||||
# Create multiple files with specific string
|
||||
New-Item -Name file1.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
|
||||
New-Item -Name file2.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
|
||||
New-Item -Name file3.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
|
||||
# Create a single file that does not match that string - already done in BeforeEach
|
||||
|
||||
# Delete the specific string
|
||||
Remove-Item /tmp/* -Include file*.txt
|
||||
# validate that the string under test was deleted, and the nonmatching strings still exist
|
||||
Test-path /tmp/file1.txt | Should Be $false
|
||||
Test-path /tmp/file2.txt | Should Be $false
|
||||
Test-path /tmp/file3.txt | Should Be $false
|
||||
Test-Path $testfilepath | Should Be $true
|
||||
|
||||
# Delete the non-matching strings
|
||||
Remove-Item $testfilepath
|
||||
|
||||
Test-Path $testfilepath | Should Be $false
|
||||
}
|
||||
|
||||
It "Should be able to not remove any files matching a regular expression with the exclude switch" {
|
||||
# Create multiple files with specific string
|
||||
New-Item -Name file1.wav -Path $testpath -ItemType "file" -Value "lorem ipsum"
|
||||
New-Item -Name file2.wav -Path $testpath -ItemType "file" -Value "lorem ipsum"
|
||||
|
||||
# Create a single file that does not match that string
|
||||
New-Item -Name file1.txt -Path $testpath -ItemType "file" -Value "lorem ipsum"
|
||||
|
||||
# Delete the specific string
|
||||
Remove-Item /tmp/file* -Exclude *.wav -Include *.txt
|
||||
|
||||
# validate that the string under test was deleted, and the nonmatching strings still exist
|
||||
Test-Path /tmp/file1.wav | Should Be $true
|
||||
Test-Path /tmp/file2.wav | Should Be $true
|
||||
Test-Path /tmp/file1.txt | Should Be $false
|
||||
|
||||
# Delete the non-matching strings
|
||||
Remove-Item /tmp/file1.wav
|
||||
Remove-Item /tmp/file2.wav
|
||||
|
||||
Test-Path /tmp/file1.wav | Should Be $false
|
||||
Test-Path /tmp/file2.wav | Should Be $false
|
||||
}
|
||||
}
|
||||
|
||||
Context "Directory Removal Tests" {
|
||||
$testdirectory = "/tmp/testdir"
|
||||
$testsubdirectory = $testdirectory + "/subd"
|
||||
BeforeEach {
|
||||
New-Item -Name "testdir" -Path "/tmp/" -ItemType "directory" -Force
|
||||
|
||||
Test-Path $testdirectory | Should Be $true
|
||||
}
|
||||
|
||||
It "Should be able to remove a directory" {
|
||||
{ Remove-Item $testdirectory } | Should Not Throw
|
||||
|
||||
Test-Path $testdirectory | Should Be $false
|
||||
}
|
||||
|
||||
It "Should be able to recursively delete subfolders" {
|
||||
New-Item -Name "subd" -Path $testdirectory -ItemType "directory"
|
||||
New-Item -Name $testfile -Path $testsubdirectory -ItemType "file" -Value "lorem ipsum"
|
||||
|
||||
$complexDirectory = $testsubdirectory + "/" + $testfile
|
||||
test-path $complexDirectory | Should Be $true
|
||||
|
||||
{ Remove-Item $testdirectory -Recurse} | Should Not Throw
|
||||
|
||||
Test-Path $testdirectory | Should Be $false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,86 @@
|
||||
Describe "Test-Split-Path" {
|
||||
<#
|
||||
Dependencies:
|
||||
1. Split-Path - FUT
|
||||
2. ForEach
|
||||
3. Object piping
|
||||
4. ls/Get-ChildItem - filter output of ls
|
||||
|
||||
#>
|
||||
It "Should return a string object when invoked" {
|
||||
(Split-Path .).GetType().Name | Should Be "String"
|
||||
(Split-Path . -Leaf).GetType().Name | Should Be "String"
|
||||
(Split-Path . -Resolve).GetType().Name | Should Be "String"
|
||||
( Split-Path . ).GetType().Name | Should Be "String"
|
||||
( Split-Path . -Leaf ).GetType().Name | Should Be "String"
|
||||
( Split-Path . -Resolve ).GetType().Name | Should Be "String"
|
||||
}
|
||||
|
||||
It "Should return the name of the drive when the qualifier switch is used" {
|
||||
Split-Path / -Qualifier | Should Be "/"
|
||||
Split-Path / -Qualifier | Should Be "/"
|
||||
Split-Path /usr/bin -Qualifier | Should Be "/"
|
||||
}
|
||||
|
||||
It "Should return the parent folder name when the leaf switch is used" {
|
||||
Split-Path . -Leaf | Should be "pester-tests"
|
||||
It "Should error when using the qualifier switch for a windows path while on a nonwindows machine" {
|
||||
# ErrorAction SilentlyContinue merely suppresses the error from the console.
|
||||
# Throwing exceptions still seen by Pester.
|
||||
|
||||
Split-Path "C:\Users" -Qualifier -ErrorAction SilentlyContinue | Should Throw
|
||||
}
|
||||
|
||||
It "Should error when no directory separator characters are used with a qualifier" {
|
||||
Split-Path "abadTest" -Qualifier -ErrorAction SilentlyContinue | Should Throw
|
||||
}
|
||||
|
||||
It "Should return the path when the noqualifier switch is used on a Linux system" {
|
||||
{ Split-Path /usr/bin -NoQualifier } | Should Not Throw
|
||||
Split-Path /usr/bin -NoQualifier | Should Be "/usr/bin"
|
||||
}
|
||||
|
||||
It "Should return the base name when the leaf switch is used" {
|
||||
Split-Path /usr/bin -Leaf | Should be "bin"
|
||||
Split-Path /usr/local/bin -Leaf | Should be "bin"
|
||||
Split-Path usr/bin -Leaf | Should be "bin"
|
||||
Split-Path ./bin -Leaf | Should be "bin"
|
||||
Split-Path bin -Leaf | Should be "bin"
|
||||
}
|
||||
|
||||
It "Should be able to accept regular expression input and output an array for multiple objects" {
|
||||
(Split-Path *Get*.ps1 -Leaf -Resolve).GetType().BaseType.Name | Should Be "Array"
|
||||
$testDir = "./tmp"
|
||||
Remove-Item $testDir -Recurse -Force -ErrorAction Ignore
|
||||
|
||||
$testFile1 = "testfile1.ps1"
|
||||
$testFile2 = "testfile2.ps1"
|
||||
$testFilePath1 = $testDir + "/" + $testFile1
|
||||
$testFilePath2 = $testDir + "/" + $testFile2
|
||||
|
||||
New-Item -ItemType file -Path $testFilePath1, $testFilePath2 -Force
|
||||
|
||||
Test-Path $testFilePath1 | Should Be $true
|
||||
Test-Path $testFilePath2 | Should Be $true
|
||||
|
||||
$actual = ( Split-Path $testDir/*file*.ps1 -Leaf -Resolve ) | Sort-Object
|
||||
$actual.GetType().BaseType.Name | Should Be "Array"
|
||||
$actual[0] | Should Be $testFile1
|
||||
$actual[1] | Should Be $testFile2
|
||||
|
||||
Remove-Item $testDir -Recurse -Force -ErrorAction Ignore
|
||||
Test-Path $testDir | Should Be $false
|
||||
}
|
||||
|
||||
It "Should be able to tell if a given path is an absolute path" {
|
||||
(Split-Path /usr/bin -IsAbsolute) | Should be $true
|
||||
(Split-Path . -IsAbsolute) | Should be $false
|
||||
( Split-Path /usr/bin -IsAbsolute ) | Should be $true
|
||||
( Split-Path .. -IsAbsolute ) | Should be $false
|
||||
( Split-Path /usr/.. -IsAbsolute ) | Should be $true
|
||||
( Split-Path /usr/../ -IsAbsolute ) | Should be $true
|
||||
( Split-Path ../ -IsAbsolute ) | Should be $false
|
||||
( Split-Path . -IsAbsolute ) | Should be $false
|
||||
( Split-Path ~/ -IsAbsolute ) | Should be $false
|
||||
( Split-Path ~/.. -IsAbsolute ) | Should be $false
|
||||
( Split-Path ~/../.. -IsAbsolute ) | Should be $false
|
||||
|
||||
}
|
||||
|
||||
It "Should support piping" {
|
||||
("." | Split-Path -leaf) | Should Be "pester-tests"
|
||||
( "/usr/bin" | Split-Path ) | Should Be "/usr"
|
||||
}
|
||||
|
||||
It "Should return the path up to the parent of the directory when Parent switch is used" {
|
||||
Split-Path "/usr/bin" -Parent | Should Be "/usr"
|
||||
Split-Path "/usr/local/bin" -Parent | Should Be "/usr/local"
|
||||
Split-Path "usr/local/bin" -Parent | Should Be "usr/local"
|
||||
}
|
||||
|
||||
It "Should throw if a parameterSetName is incorrect" {
|
||||
{ Split-Path "/usr/bin/" -Parentaoeu } | Should Throw "A parameter cannot be found that matches parameter name"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,25 +456,6 @@ namespace ps_hello_world
|
||||
}
|
||||
}
|
||||
|
||||
public static void init()
|
||||
{
|
||||
//string psBasePath = System.IO.Directory.GetCurrentDirectory();
|
||||
//PowerShellAssemblyLoadContextInitializer.SetPowerShellAssemblyLoadContext(psBasePath);
|
||||
|
||||
//Assembly a = Assembly.Load(new AssemblyName("System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"));
|
||||
//Console.WriteLine("##########################\nloaded assembly a=" + a + " during init\n#########################");
|
||||
|
||||
// PH: this debugging requires a change in the core PS stuff that was stashed away
|
||||
// during source cleanup
|
||||
/*
|
||||
PowerShellAssemblyLoadContext asmLoadContext = PowerShellAssemblyLoadContextInitializer.AsmLoadContext;
|
||||
IEnumerable<Assembly> assemblies = asmLoadContext.GetAssemblies("System.Management.Automation");
|
||||
foreach (Assembly a in assemblies)
|
||||
{
|
||||
Console.WriteLine("a: " + a);
|
||||
}*/
|
||||
}
|
||||
|
||||
static void test1(string[] args)
|
||||
{
|
||||
InitialSessionState iss = InitialSessionState.CreateDefault2();
|
||||
@@ -525,50 +506,8 @@ namespace ps_hello_world
|
||||
}
|
||||
}
|
||||
|
||||
public static int UnmanagedMain(int argc, [MarshalAs(UnmanagedType.LPArray,ArraySubType=UnmanagedType.LPStr,SizeParamIndex=0)] String[] argv)
|
||||
{
|
||||
init();
|
||||
List<String> allArgs = new List<String>();
|
||||
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
allArgs.Add(argv[i]);
|
||||
}
|
||||
|
||||
List<string> filteredArgs = new List<string>();
|
||||
if (allArgs.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < allArgs.Count; ++i)
|
||||
{
|
||||
string arg = allArgs[i];
|
||||
bool hasNext = (i+1)<allArgs.Count;
|
||||
string nextArg = hasNext ? allArgs[i+1] : "";
|
||||
|
||||
if (hasNext && arg == "--working-dir")
|
||||
{
|
||||
Console.WriteLine("working dir set to: " + nextArg);
|
||||
Directory.SetCurrentDirectory(nextArg);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
filteredArgs.Add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
test2(filteredArgs.ToArray());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// important:
|
||||
// - this function must be called for the current version of PowerShell for Linux
|
||||
// in order to load the assembly load context before anything else is loaded
|
||||
// - this requirement will be removed through future updates to the native
|
||||
// CLR hosting code (currently corerun)
|
||||
init();
|
||||
|
||||
//test1(args);
|
||||
test2(args);
|
||||
}
|
||||
|
||||
@@ -53,15 +53,42 @@ namespace PSTests
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false
|
||||
};
|
||||
Process process = Process.Start(startInfo);
|
||||
// The process should always exit, but wait a set time just in case
|
||||
process.WaitForExit(1000);
|
||||
// The process should return an exit code of 0 on success
|
||||
Assert.Equal(0, process.ExitCode);
|
||||
// Get output of call to whoami without trailing newline
|
||||
string username = process.StandardOutput.ReadToEnd().Trim();
|
||||
// It should be the same as what our platform code returns
|
||||
Assert.Equal(username, Platform.NonWindowsGetUserName());
|
||||
using (Process process = Process.Start(startInfo))
|
||||
{
|
||||
// Get output of call to whoami without trailing newline
|
||||
string username = process.StandardOutput.ReadToEnd().Trim();
|
||||
process.WaitForExit();
|
||||
|
||||
// The process should return an exit code of 0 on success
|
||||
Assert.Equal(0, process.ExitCode);
|
||||
// It should be the same as what our platform code returns
|
||||
Assert.Equal(username, Platform.NonWindowsGetUserName());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static void TestGetMachineName()
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = @"/usr/bin/env",
|
||||
Arguments = "hostname",
|
||||
RedirectStandardOutput = true,
|
||||
UseShellExecute = false
|
||||
};
|
||||
using (Process process = Process.Start(startInfo))
|
||||
{
|
||||
// Get output of call to hostname without trailing newline
|
||||
string hostname = process.StandardOutput.ReadToEnd().Trim();
|
||||
process.WaitForExit();
|
||||
|
||||
// The process should return an exit code of 0 on success
|
||||
Assert.Equal(0, process.ExitCode);
|
||||
// It should be the same as what our platform code returns
|
||||
Assert.Equal(hostname, Platform.NonWindowsGetMachineName());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user