From 389f2387c069047525fa8c063f7e200d1f6d9120 Mon Sep 17 00:00:00 2001 From: Carl Morris Date: Wed, 8 May 2019 10:28:36 -0500 Subject: [PATCH] improvements/changes relating to #169 (#170) --- build.ps1 | 15 ++++++------- tools/build-helpers.ps1 | 49 +++++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 29 deletions(-) diff --git a/build.ps1 b/build.ps1 index 3e85430..213fcf5 100644 --- a/build.ps1 +++ b/build.ps1 @@ -7,7 +7,7 @@ Test: Uses Atom and atom-grammar-test to run tests against specs and sample files to guard against regression. - .EXAMPLE Build + .EXAMPLE PS C:\EditorSyntax> .\build.ps1 [Starting] Converting ../PowerShellSyntax.tmLanguage to json. ... Reading source file. @@ -16,7 +16,7 @@ ... Creating directory: ./grammars [Finished] File written to: ../grammars/powershell.tmLanguage.json - .EXAMPLE Test + .EXAMPLE PS C:\EditorSyntax> .\build.ps1 Test Running specs... @@ -25,9 +25,7 @@ Finished in 0.281 seconds 2 tests, 5 assertions, 0 failures, 0 skipped #> -[cmdletbinding()] param( - [parameter()] [switch] $Test ) @@ -38,19 +36,20 @@ param( SyntaxBanner -if (-not(& npm -v)) { +if (-not (npm -v)) { throw 'Requires Node.js - Could not find npm.' } -& npm install +npm install # helper tasks function RunBuild() { BuildBanner try { Write-Host "Building grammar file(s)..." - & npm run build-grammar - } catch { + npm run build-grammar + } + catch { $PSCmdlet.ThrowTerminatingError($PSItem) } } diff --git a/tools/build-helpers.ps1 b/tools/build-helpers.ps1 index fa1efe7..8baae7c 100644 --- a/tools/build-helpers.ps1 +++ b/tools/build-helpers.ps1 @@ -1,12 +1,13 @@ function DownloadAtom { Write-Host "Downloading latest Atom release..." - $Source = "https://atom.io/download/windows_zip?channel=stable" + $Source = "https://atom.io/download/windows_zip?channel=stable" $Destination = Join-Path . '\atom.zip' try { Invoke-WebRequest $Source -OutFile $Destination -ErrorAction Stop - } catch { + } + catch { $PSCmdlet.ThrowTerminatingError($PSItem) } @@ -24,7 +25,8 @@ function ExtractAtom { try { Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::ExtractToDirectory($ZipFile, $OutPath) - } catch { + } + catch { $PSCmdlet.ThrowTerminatingError($PSItem) } @@ -35,24 +37,27 @@ function ExtractAtom { Write-Host "Atom.zip deleted..." } -function ParseJasmine ($String) { - if ($String -match "^\s+at.*$") { - ' ' - return - } +filter ParseJasmine { + switch -regex ($_) { + ^\s+at { + '' + break + } - if ($_ -match "^\s+it.*$") { - $_ -replace '^(\s+)(it)','$1[-] It' - return - } + ^\s+it { + $_ -replace '^(\s+)(it)', '$1[-] It' + break + } - if ($_ -match "^\s+Expected.*$") { - $x = $_ -replace '^(\s*)(Expected)(.*)\s(to equal .*)','$1$2$3%%$1$4' - $x.Replace('%%',"`n ") - return - } + ^\s+Expected { + $_ -replace '^(\s*)(Expected.*?)\s(instead found .*)', "`$1`$2`n`$1`$3" + break + } - $_ + default { + $_ + } + } } function ExitWithCode { @@ -70,15 +75,17 @@ function RunSpecs { $specpath = Join-Path . '\spec' if (Test-Path $specpath) { - & "$script:ATOM_EXE_PATH" --test spec *>&1 | ForEach-Object { ParseJasmine $_ } - } else { + & $script:ATOM_EXE_PATH --test $specpath *>&1 | ParseJasmine + } + else { throw '.\spec\ not found.' } if ($LASTEXITCODE -ne 0) { if ($Env:APPVEYOR) { ExitWithCode -exitcode $LASTEXITCODE - } else { + } + else { throw "One or more tests failed." } }