2020-03-24 11:08:37 -07:00
|
|
|
# Copyright (c) Microsoft Corporation.
|
2018-02-13 09:23:53 -08:00
|
|
|
# Licensed under the MIT License.
|
2016-07-25 14:01:41 -07:00
|
|
|
Describe "NativeLinuxCommands" -tags "CI" {
|
2017-10-23 17:54:28 -07:00
|
|
|
BeforeAll {
|
|
|
|
|
$originalDefaultParams = $PSDefaultParameterValues.Clone()
|
|
|
|
|
$PSDefaultParameterValues["It:Skip"] = $IsWindows
|
|
|
|
|
$originalPath = $env:PATH
|
|
|
|
|
$env:PATH += [IO.Path]::PathSeparator + $TestDrive
|
2016-03-17 22:48:35 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-23 17:54:28 -07:00
|
|
|
AfterAll {
|
|
|
|
|
$global:PSDefaultParameterValues = $originalDefaultParams
|
|
|
|
|
$env:PATH = $originalPath
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should find Application grep" {
|
2020-05-07 13:00:30 +01:00
|
|
|
(Get-Command grep).CommandType | Should -Be Application
|
2016-03-18 00:23:57 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-23 17:54:28 -07:00
|
|
|
It "Should pipe to grep and get result" {
|
2018-03-21 10:47:08 -07:00
|
|
|
"hello world" | grep hello | Should -BeExactly "hello world"
|
2016-03-17 22:48:35 -07:00
|
|
|
}
|
2016-04-08 13:36:54 -07:00
|
|
|
|
2017-10-23 17:54:28 -07:00
|
|
|
It "Should find Application touch" {
|
2020-05-07 13:00:30 +01:00
|
|
|
(Get-Command touch).CommandType | Should -Be Application
|
2016-03-17 22:48:35 -07:00
|
|
|
}
|
2016-11-21 16:02:52 -08:00
|
|
|
|
2017-10-23 17:54:28 -07:00
|
|
|
It "Should not redirect standard input if native command is the first command in pipeline (1)" {
|
2017-05-02 18:45:35 -07:00
|
|
|
df | ForEach-Object -Begin { $out = @() } -Process { $out += $_ }
|
2018-03-21 10:47:08 -07:00
|
|
|
$out.Length -gt 0 | Should -BeTrue
|
|
|
|
|
$out[0] -like "Filesystem*Available*" | Should -BeTrue
|
2016-11-21 16:02:52 -08:00
|
|
|
}
|
|
|
|
|
|
2017-10-23 17:54:28 -07:00
|
|
|
It "Should not redirect standard input if native command is the first command in pipeline (2)" {
|
2017-05-02 18:45:35 -07:00
|
|
|
$out = df
|
2018-03-21 10:47:08 -07:00
|
|
|
$out.Length -gt 0 | Should -BeTrue
|
|
|
|
|
$out[0] -like "Filesystem*Available*" | Should -BeTrue
|
2016-11-21 16:02:52 -08:00
|
|
|
}
|
2017-10-23 17:54:28 -07:00
|
|
|
|
|
|
|
|
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
|
2018-03-21 10:47:08 -07:00
|
|
|
foo | Should -BeExactly 'command'
|
2017-10-23 17:54:28 -07:00
|
|
|
}
|
2016-03-17 22:48:35 -07:00
|
|
|
}
|
2016-05-27 11:43:05 -07:00
|
|
|
|
2016-07-25 14:01:41 -07:00
|
|
|
Describe "Scripts with extensions" -tags "CI" {
|
2016-05-27 11:43:05 -07:00
|
|
|
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" {
|
2018-03-21 10:47:08 -07:00
|
|
|
testScript.ps1 | Should -BeExactly $data
|
2016-05-27 11:43:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
It "Should run a script with its short name" {
|
2018-03-21 10:47:08 -07:00
|
|
|
testScript | Should -BeExactly $data
|
2016-05-27 11:43:05 -07:00
|
|
|
}
|
|
|
|
|
}
|