File size: 2,185 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | # Copyright (c) Microsoft Corporation.
# 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 -BeExactly "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 -BeTrue
$out[0] -like "Filesystem*Available*" | Should -BeTrue
}
It "Should not redirect standard input if native command is the first command in pipeline (2)" {
$out = df
$out.Length -gt 0 | Should -BeTrue
$out[0] -like "Filesystem*Available*" | Should -BeTrue
}
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 -BeExactly $data
}
It "Should run a script with its short name" {
testScript | Should -BeExactly $data
}
}
|