PowerShell/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1
Steve Lee c1c5344a88 Update copyright and license headers (#6134)
Based on standard practices, we need to have a copyright and license notice at the top of each source file. Removed existing copyrights and updated/added copyright notices for .h, .cpp, .cs, .ps1, and .psm1 files.

Updated module manifests for consistency to have Author = "PowerShell" and Company = "Microsoft Corporation". Removed multiple line breaks.

Separate PR coming to update contribution document for new source files: #6140

Manually reviewed each change.

Fix #6073
2018-02-13 09:23:53 -08:00

72 lines
2.1 KiB
PowerShell

# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
Describe "NativeLinuxCommands" -tags "CI" {
BeforeAll {
$originalDefaultParams = $PSDefaultParameterValues.Clone()
$PSDefaultParameterValues["It:Skip"] = $IsWindows
$originalPath = $env:PATH
$env:PATH += [IO.Path]::PathSeparator + $TestDrive
}
AfterAll {
$global:PSDefaultParameterValues = $originalDefaultParams
$env:PATH = $originalPath
}
It "Should find Application grep" {
(get-command grep).CommandType | Should Be Application
}
It "Should pipe to grep and get result" {
"hello world" | grep hello | Should Be "hello world"
}
It "Should find Application touch" {
(get-command touch).CommandType | Should Be Application
}
It "Should not redirect standard input if native command is the first command in pipeline (1)" {
df | ForEach-Object -Begin { $out = @() } -Process { $out += $_ }
$out.Length -gt 0 | Should Be $true
$out[0] -like "Filesystem*Available*" | Should Be $true
}
It "Should not redirect standard input if native command is the first command in pipeline (2)" {
$out = df
$out.Length -gt 0 | Should Be $true
$out[0] -like "Filesystem*Available*" | Should Be $true
}
It "Should find command before script with same name" {
Set-Content "$TestDrive\foo" -Value @"
#!/usr/bin/env bash
echo 'command'
"@ -Encoding Ascii
chmod +x "$TestDrive/foo"
Set-Content "$TestDrive\foo.ps1" -Value @"
'script'
"@ -Encoding Ascii
foo | Should BeExactly 'command'
}
}
Describe "Scripts with extensions" -tags "CI" {
BeforeAll {
$data = "Hello World"
Setup -File testScript.ps1 -Content "'$data'"
$originalPath = $env:PATH
$env:PATH += [IO.Path]::PathSeparator + $TestDrive
}
AfterAll {
$env:PATH = $originalPath
}
It "Should run a script with its full name" {
testScript.ps1 | Should Be $data
}
It "Should run a script with its short name" {
testScript | Should Be $data
}
}