Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

- **depends:** Prevent error on no URL ([#4595](https://github.com/ScoopInstaller/Scoop/issues/4595))

### Styles

- **test:** Format scripts by VSCode's PowerShell extension ([#4609](https://github.com/ScoopInstaller/Scoop/issues/4609))

<a name="2021-12-26"></a>
## [2021-12-26]

Expand Down
30 changes: 13 additions & 17 deletions test/00-Project.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
$repo_dir = (Get-Item $MyInvocation.MyCommand.Path).Directory.Parent.FullName

$repo_files = @( Get-ChildItem $repo_dir -file -recurse -force )
$repo_files = @( Get-ChildItem $repo_dir -File -Recurse -Force )

$project_file_exclusions = @(
$([regex]::Escape($repo_dir)+'(\\|/).git(\\|/).*$'),
$([regex]::Escape($repo_dir) + '(\\|/).git(\\|/).*$'),
'.sublime-workspace$',
'.DS_Store$',
'supporting(\\|/)validator(\\|/)packages(\\|/)*',
'supporting(\\|/)shimexe(\\|/)packages(\\|/)*'
)

describe 'Project code' {
Describe 'Project code' {

$files = @(
$repo_files |
where-object { $_.fullname -inotmatch $($project_file_exclusions -join '|') } |
where-object { $_.fullname -imatch '.(ps1|psm1)$' }
Where-Object { $_.fullname -inotmatch $($project_file_exclusions -join '|') } |
Where-Object { $_.fullname -imatch '.(ps1|psm1)$' }
)

$files_exist = ($files.Count -gt 0)

it $('PowerShell code files exist ({0} found)' -f $files.Count) -skip:$(-not $files_exist) {
if (-not ($files.Count -gt 0))
{
throw "No PowerShell code files were found"
It $('PowerShell code files exist ({0} found)' -f $files.Count) -Skip:$(-not $files_exist) {
if (-not ($files.Count -gt 0)) {
throw 'No PowerShell code files were found'
}
}

Expand All @@ -49,26 +48,23 @@ describe 'Project code' {
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors)

New-Object psobject -Property @{
Path = $scriptPath
Path = $scriptPath
SyntaxErrorsFound = ($errors.Count -gt 0)
}
}
}
}

it 'PowerShell code files do not contain syntax errors' -skip:$(-not $files_exist) {
It 'PowerShell code files do not contain syntax errors' -Skip:$(-not $files_exist) {
$badFiles = @(
foreach ($file in $files)
{
if ( (Test-PowerShellSyntax $file.FullName).SyntaxErrorsFound )
{
foreach ($file in $files) {
if ( (Test-PowerShellSyntax $file.FullName).SyntaxErrorsFound ) {
$file.FullName
}
}
)

if ($badFiles.Count -gt 0)
{
if ($badFiles.Count -gt 0) {
throw "The following files have syntax errors: `r`n`r`n$($badFiles -join "`r`n")"
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/Import-Bucket-Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if([String]::IsNullOrEmpty($MyInvocation.PSScriptRoot)) {
if ([String]::IsNullOrEmpty($MyInvocation.PSScriptRoot)) {
Write-Error 'This script should not be called directly! It has to be imported from a buckets test file!'
exit 1
}
Expand All @@ -10,17 +10,17 @@ if([String]::IsNullOrEmpty($MyInvocation.PSScriptRoot)) {

$repo_dir = (Get-Item $MyInvocation.PSScriptRoot).FullName

$repo_files = @(Get-ChildItem $repo_dir -file -recurse)
$repo_files = @(Get-ChildItem $repo_dir -File -Recurse)

$project_file_exclusions = @(
$([regex]::Escape($repo_dir)+'(\\|/).git(\\|/).*$'),
$([regex]::Escape($repo_dir) + '(\\|/).git(\\|/).*$'),
'.sublime-workspace$',
'.DS_Store$',
'supporting(\\|/)validator(\\|/)packages(\\|/)*'
)

$bucketdir = $repo_dir
if(Test-Path("$repo_dir\bucket")) {
if (Test-Path("$repo_dir\bucket")) {
$bucketdir = "$repo_dir\bucket"
}

Expand Down
91 changes: 36 additions & 55 deletions test/Import-File-Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
if([String]::IsNullOrEmpty($MyInvocation.PSScriptRoot)) {
if ([String]::IsNullOrEmpty($MyInvocation.PSScriptRoot)) {
Write-Error 'This script should not be called directly! It has to be imported from a buckets test file!'
exit 1
}

describe 'Style constraints for non-binary project files' {
Describe 'Style constraints for non-binary project files' {

$files = @(
# gather all files except '*.exe', '*.zip', or any .git repository files
$repo_files |
where-object { $_.fullname -inotmatch $($project_file_exclusions -join '|') } |
where-object { $_.fullname -inotmatch '(.exe|.zip|.dll)$' } |
where-object { $_.fullname -inotmatch '(unformated)' }
Where-Object { $_.fullname -inotmatch $($project_file_exclusions -join '|') } |
Where-Object { $_.fullname -inotmatch '(.exe|.zip|.dll)$' } |
Where-Object { $_.fullname -inotmatch '(unformated)' }
)

$files_exist = ($files.Count -gt 0)

it $('non-binary project files exist ({0} found)' -f $files.Count) -skip:$(-not $files_exist) {
if (-not ($files.Count -gt 0))
{
throw "No non-binary project were found"
It $('non-binary project files exist ({0} found)' -f $files.Count) -Skip:$(-not $files_exist) {
if (-not ($files.Count -gt 0)) {
throw 'No non-binary project were found'
}
}

it 'files do not contain leading UTF-8 BOM' -skip:$(-not $files_exist) {
It 'files do not contain leading UTF-8 BOM' -Skip:$(-not $files_exist) {
# UTF-8 BOM == 0xEF 0xBB 0xBF
# see http://www.powershellmagazine.com/2012/12/17/pscxtip-how-to-determine-the-byte-order-mark-of-a-text-file @@ https://archive.is/RgT42
# ref: http://poshcode.org/2153 @@ https://archive.is/sGnnu
$badFiles = @(
foreach ($file in $files)
{
if((Get-Command Get-Content).parameters.ContainsKey('AsByteStream')) {
foreach ($file in $files) {
if ((Get-Command Get-Content).parameters.ContainsKey('AsByteStream')) {
# PowerShell Core (6.0+) '-Encoding byte' is replaced by '-AsByteStream'
$content = ([char[]](Get-Content $file.FullName -AsByteStream -TotalCount 3) -join '')
} else {
Expand All @@ -41,111 +39,94 @@ describe 'Style constraints for non-binary project files' {
}
)

if ($badFiles.Count -gt 0)
{
if ($badFiles.Count -gt 0) {
throw "The following files have utf-8 BOM: `r`n`r`n$($badFiles -join "`r`n")"
}
}

it 'files end with a newline' -skip:$(-not $files_exist) {
It 'files end with a newline' -Skip:$(-not $files_exist) {
$badFiles = @(
foreach ($file in $files)
{
foreach ($file in $files) {
# Ignore previous TestResults.xml
if ($file -match "TestResults.xml") {
if ($file -match 'TestResults.xml') {
continue
}
$string = [System.IO.File]::ReadAllText($file.FullName)
if ($string.Length -gt 0 -and $string[-1] -ne "`n")
{
if ($string.Length -gt 0 -and $string[-1] -ne "`n") {
$file.FullName
}
}
)

if ($badFiles.Count -gt 0)
{
if ($badFiles.Count -gt 0) {
throw "The following files do not end with a newline: `r`n`r`n$($badFiles -join "`r`n")"
}
}

it 'file newlines are CRLF' -skip:$(-not $files_exist) {
It 'file newlines are CRLF' -Skip:$(-not $files_exist) {
$badFiles = @(
foreach ($file in $files)
{
$content = Get-Content -raw $file.FullName
if(!$content) {
foreach ($file in $files) {
$content = Get-Content -Raw $file.FullName
if (!$content) {
throw "File contents are null: $($file.FullName)"
}
$lines = [regex]::split($content, '\r\n')
$lineCount = $lines.Count

for ($i = 0; $i -lt $lineCount; $i++)
{
if ( [regex]::match($lines[$i], '\r|\n').success )
{
for ($i = 0; $i -lt $lineCount; $i++) {
if ( [regex]::match($lines[$i], '\r|\n').success ) {
$file.FullName
break
}
}
}
)

if ($badFiles.Count -gt 0)
{
if ($badFiles.Count -gt 0) {
throw "The following files have non-CRLF line endings: `r`n`r`n$($badFiles -join "`r`n")"
}
}

it 'files have no lines containing trailing whitespace' -skip:$(-not $files_exist) {
It 'files have no lines containing trailing whitespace' -Skip:$(-not $files_exist) {
$badLines = @(
foreach ($file in $files)
{
foreach ($file in $files) {
# Ignore previous TestResults.xml
if ($file -match "TestResults.xml") {
if ($file -match 'TestResults.xml') {
continue
}
$lines = [System.IO.File]::ReadAllLines($file.FullName)
$lineCount = $lines.Count

for ($i = 0; $i -lt $lineCount; $i++)
{
if ($lines[$i] -match '\s+$')
{
for ($i = 0; $i -lt $lineCount; $i++) {
if ($lines[$i] -match '\s+$') {
'File: {0}, Line: {1}' -f $file.FullName, ($i + 1)
}
}
}
)

if ($badLines.Count -gt 0)
{
if ($badLines.Count -gt 0) {
throw "The following $($badLines.Count) lines contain trailing whitespace: `r`n`r`n$($badLines -join "`r`n")"
}
}

it 'any leading whitespace consists only of spaces (excepting makefiles)' -skip:$(-not $files_exist) {
It 'any leading whitespace consists only of spaces (excepting makefiles)' -Skip:$(-not $files_exist) {
$badLines = @(
foreach ($file in $files)
{
if ($file.fullname -inotmatch '(^|.)makefile$')
{
foreach ($file in $files) {
if ($file.fullname -inotmatch '(^|.)makefile$') {
$lines = [System.IO.File]::ReadAllLines($file.FullName)
$lineCount = $lines.Count

for ($i = 0; $i -lt $lineCount; $i++)
{
if ($lines[$i] -notmatch '^[ ]*(\S|$)')
{
for ($i = 0; $i -lt $lineCount; $i++) {
if ($lines[$i] -notmatch '^[ ]*(\S|$)') {
'File: {0}, Line: {1}' -f $file.FullName, ($i + 1)
}
}
}
}
)

if ($badLines.Count -gt 0)
{
if ($badLines.Count -gt 0) {
throw "The following $($badLines.Count) lines contain TABs within leading whitespace: `r`n`r`n$($badLines -join "`r`n")"
}
}
Expand Down
74 changes: 37 additions & 37 deletions test/Scoop-Alias.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
. "$psscriptroot\..\libexec\scoop-alias.ps1" | out-null
. "$psscriptroot\..\libexec\scoop-alias.ps1" | Out-Null

reset_aliases

describe "add_alias" -Tag 'Scoop' {
mock shimdir { "TestDrive:\shim" }
mock set_config { }
mock get_config { @{} }
Describe 'add_alias' -Tag 'Scoop' {
Mock shimdir { 'TestDrive:\shim' }
Mock set_config { }
Mock get_config { @{} }

$shimdir = shimdir
mkdir $shimdir
$shimdir = shimdir
mkdir $shimdir

context "alias doesn't exist" {
it "creates a new alias" {
$alias_file = "$shimdir\scoop-rm.ps1"
$alias_file | should -not -exist
Context "alias doesn't exist" {
It 'creates a new alias' {
$alias_file = "$shimdir\scoop-rm.ps1"
$alias_file | Should -Not -Exist

add_alias "rm" '"hello, world!"'
Invoke-Expression $alias_file | should -be "hello, world!"
add_alias 'rm' '"hello, world!"'
Invoke-Expression $alias_file | Should -Be 'hello, world!'
}
}
}

context "alias exists" {
it "does not change existing alias" {
$alias_file = "$shimdir\scoop-rm.ps1"
new-item $alias_file -type file
$alias_file | should -exist
Context 'alias exists' {
It 'does not change existing alias' {
$alias_file = "$shimdir\scoop-rm.ps1"
New-Item $alias_file -type file
$alias_file | Should -Exist

add_alias "rm" "test"
$alias_file | should -FileContentMatch ""
add_alias 'rm' 'test'
$alias_file | Should -FileContentMatch ''
}
}
}
}

describe "rm_alias" {
mock shimdir { "TestDrive:\shim" }
mock set_config { }
mock get_config { @{} }
Describe 'rm_alias' {
Mock shimdir { 'TestDrive:\shim' }
Mock set_config { }
Mock get_config { @{} }

$shimdir = shimdir
mkdir $shimdir
$shimdir = shimdir
mkdir $shimdir

context "alias exists" {
it "removes an existing alias" {
$alias_file = "$shimdir\scoop-rm.ps1"
add_alias "rm" '"hello, world!"'
Context 'alias exists' {
It 'removes an existing alias' {
$alias_file = "$shimdir\scoop-rm.ps1"
add_alias 'rm' '"hello, world!"'

$alias_file | should -exist
mock get_config { @(@{"rm" = "scoop-rm"}) }
$alias_file | Should -Exist
Mock get_config { @(@{'rm' = 'scoop-rm' }) }

rm_alias "rm"
$alias_file | should -not -exist
rm_alias 'rm'
$alias_file | Should -Not -Exist
}
}
}
}
Loading