Skip to content

Commit 71da515

Browse files
leonyur15ch13
authored andcommitted
Fix some tests on linux (#2153)
* fix bom reading test in PowerShell 6 * Use join-path to fix test on Linux
1 parent 7c42787 commit 71da515

2 files changed

Lines changed: 41 additions & 17 deletions

File tree

test/00-Project.Tests.ps1

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,38 @@ describe 'Style constraints for non-binary project files' {
9797
# utf-8 BOM == 0xEF 0xBB 0xBF
9898
# see http://www.powershellmagazine.com/2012/12/17/pscxtip-how-to-determine-the-byte-order-mark-of-a-text-file @@ https://archive.is/RgT42
9999
# ref: http://poshcode.org/2153 @@ https://archive.is/sGnnu
100+
101+
# As of PowerShell 6.0, `Get-Content` on non-Windows platform does not support `-Encoding Byte`
102+
# The following try-catch is to work around that by using .NET framework
103+
$read_bytes_type = 'default'
104+
function read_bytes ([string]$FileName, [int]$Size) {
105+
if ($read_bytes_type -eq 'default') {
106+
return Get-Content "$FileName" -Encoding Byte -TotalCount $Size
107+
}
108+
else {
109+
$buffer = [byte[]](0, 0, 0)
110+
$fstream = (New-Object -TypeName System.IO.FileStream -ArgumentList ("$FileName", [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read))
111+
$fstream.Read($buffer, 0, $Size) > $null
112+
return $buffer
113+
}
114+
}
115+
try {
116+
# Following would throw exception if `-Encoding Byte` is not supported
117+
$null = read_bytes -FileName $MyInvocation.PSCommandPath -Size 3
118+
}
119+
catch {
120+
$read_bytes_type = 'dotnet'
121+
}
122+
100123
$badFiles = @(
101124
foreach ($file in $files)
102125
{
103126
# Ignore previous TestResults.xml
104127
if ($file -match "TestResults.xml") {
105128
continue
106129
}
107-
$content = ([char[]](Get-Content $file.FullName -encoding byte -totalcount 3) -join '')
130+
$buffer = read_bytes -FileName "$($file.FullName)" -Size 3
131+
$content = ([char[]]$buffer -join '')
108132
if ([regex]::match($content, '(?ms)^\xEF\xBB\xBF').success)
109133
{
110134
$file.FullName

test/Scoop-Install.Tests.ps1

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -159,30 +159,30 @@ describe 'compute_hash' {
159159
}
160160

161161
it 'computes MD5 correctly' {
162-
compute_hash "$working_dir\\invalid_wget.json" 'md5' | Should be "cf229eecc201063e32b436e73b71deba"
163-
compute_hash "$working_dir\\wget.json" 'md5' | Should be "57c397fd5092cbd6a8b4df56be2551ab"
164-
compute_hash "$working_dir\\broken_schema.json" 'md5' | Should be "0427c7f4edc33d6d336db98fc160beb0"
165-
compute_hash "$working_dir\\broken_wget.json" 'md5' | Should be "30a7d4d3f64cb7a800d96c0f2ccec87f"
162+
compute_hash (join-path "$working_dir" "invalid_wget.json") 'md5' | Should be "cf229eecc201063e32b436e73b71deba"
163+
compute_hash (join-path "$working_dir" "wget.json") 'md5' | Should be "57c397fd5092cbd6a8b4df56be2551ab"
164+
compute_hash (join-path "$working_dir" "broken_schema.json") 'md5' | Should be "0427c7f4edc33d6d336db98fc160beb0"
165+
compute_hash (join-path "$working_dir" "broken_wget.json") 'md5' | Should be "30a7d4d3f64cb7a800d96c0f2ccec87f"
166166
}
167167

168168
it 'computes SHA-1 correctly' {
169-
compute_hash "$working_dir\\invalid_wget.json" 'sha1' | Should be "33ae44df8feed86cdc8f544234029fb28280c3c5"
170-
compute_hash "$working_dir\\wget.json" 'sha1' | Should be "98bfacb887da8cd05d3a1162f89d90173294be55"
171-
compute_hash "$working_dir\\broken_schema.json" 'sha1' | Should be "6dcd64f8ce7a3ae6bbc3dc2288b7cb202dbfa3c8"
172-
compute_hash "$working_dir\\broken_wget.json" 'sha1' | Should be "60b5b1d5bcb4193d19aeab265eab0bb9b0c46c8f"
169+
compute_hash (join-path "$working_dir" "invalid_wget.json") 'sha1' | Should be "33ae44df8feed86cdc8f544234029fb28280c3c5"
170+
compute_hash (join-path "$working_dir" "wget.json") 'sha1' | Should be "98bfacb887da8cd05d3a1162f89d90173294be55"
171+
compute_hash (join-path "$working_dir" "broken_schema.json") 'sha1' | Should be "6dcd64f8ce7a3ae6bbc3dc2288b7cb202dbfa3c8"
172+
compute_hash (join-path "$working_dir" "broken_wget.json") 'sha1' | Should be "60b5b1d5bcb4193d19aeab265eab0bb9b0c46c8f"
173173
}
174174

175175
it 'computes SHA-256 correctly' {
176-
compute_hash "$working_dir\\invalid_wget.json" 'sha256' | Should be "1a92ef57c5f3cecba74015ae8e92fc3f2dbe141f9d171c3a06f98645a522d58c"
177-
compute_hash "$working_dir\\wget.json" 'sha256' | Should be "31d6d0953d4e95f0a42080acd61a8c2f92bc90cae324c0d6d2301a974c15f62f"
178-
compute_hash "$working_dir\\broken_schema.json" 'sha256' | Should be "f3e5082e366006c317d9426e590623254cb1ce23d4f70165afed340b03ce333b"
179-
compute_hash "$working_dir\\broken_wget.json" 'sha256' | Should be "da658987c3902658c6e754bfa6546dfd084aaa2c3ae25f1fd8aa4645bc9cae24"
176+
compute_hash (join-path "$working_dir" "invalid_wget.json") 'sha256' | Should be "1a92ef57c5f3cecba74015ae8e92fc3f2dbe141f9d171c3a06f98645a522d58c"
177+
compute_hash (join-path "$working_dir" "wget.json") 'sha256' | Should be "31d6d0953d4e95f0a42080acd61a8c2f92bc90cae324c0d6d2301a974c15f62f"
178+
compute_hash (join-path "$working_dir" "broken_schema.json") 'sha256' | Should be "f3e5082e366006c317d9426e590623254cb1ce23d4f70165afed340b03ce333b"
179+
compute_hash (join-path "$working_dir" "broken_wget.json") 'sha256' | Should be "da658987c3902658c6e754bfa6546dfd084aaa2c3ae25f1fd8aa4645bc9cae24"
180180
}
181181

182182
it 'computes SHA-512 correctly' {
183-
compute_hash "$working_dir\\invalid_wget.json" 'sha512' | Should be "7a7b82ec17547f5ec13dc614a8cec919e897e6c344a6ce7d71205d6f1c3aed276c7b15cbc69acac8207f72417993299cef36884e1915d56758ea09efa2259870"
184-
compute_hash "$working_dir\\wget.json" 'sha512' | Should be "216ebf07bb77062b51420f0f5eb6b7a94d9623d1d41d36c833436058f41e39898f2aa48d7020711c0d8765d02b87ac2e6810f3f502636a6e6f47dc4b9aa02d17"
185-
compute_hash "$working_dir\\broken_schema.json" 'sha512' | Should be "8d3f5617517e61c33275eafea4b166f0a245ec229c40dea436173c354786bad72e4fd9d662f6ac2b9f3dd375c00815a07f10e12975eec1b12da7ba7db10f9c14"
186-
compute_hash "$working_dir\\broken_wget.json" 'sha512' | Should be "7b16a714491e91cc6daa5f90e700547fac4d62e1fcec8c4b78f5a2386e04e68a8ed68f27503ece9555904a047df8050b3f12b4f779c05b1e4d0156e6e2d8fdbb"
183+
compute_hash (join-path "$working_dir" "invalid_wget.json") 'sha512' | Should be "7a7b82ec17547f5ec13dc614a8cec919e897e6c344a6ce7d71205d6f1c3aed276c7b15cbc69acac8207f72417993299cef36884e1915d56758ea09efa2259870"
184+
compute_hash (join-path "$working_dir" "wget.json") 'sha512' | Should be "216ebf07bb77062b51420f0f5eb6b7a94d9623d1d41d36c833436058f41e39898f2aa48d7020711c0d8765d02b87ac2e6810f3f502636a6e6f47dc4b9aa02d17"
185+
compute_hash (join-path "$working_dir" "broken_schema.json") 'sha512' | Should be "8d3f5617517e61c33275eafea4b166f0a245ec229c40dea436173c354786bad72e4fd9d662f6ac2b9f3dd375c00815a07f10e12975eec1b12da7ba7db10f9c14"
186+
compute_hash (join-path "$working_dir" "broken_wget.json") 'sha512' | Should be "7b16a714491e91cc6daa5f90e700547fac4d62e1fcec8c4b78f5a2386e04e68a8ed68f27503ece9555904a047df8050b3f12b4f779c05b1e4d0156e6e2d8fdbb"
187187
}
188188
}

0 commit comments

Comments
 (0)