Skip to content

Commit 389f238

Browse files
msftrncsTylerLeonhardt
authored andcommitted
improvements/changes relating to #169 (#170)
1 parent 6e2fb74 commit 389f238

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

build.ps1

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
Test: Uses Atom and atom-grammar-test to run tests against specs and sample files to guard against regression.
99
10-
.EXAMPLE Build
10+
.EXAMPLE
1111
PS C:\EditorSyntax> .\build.ps1
1212
[Starting] Converting ../PowerShellSyntax.tmLanguage to json.
1313
... Reading source file.
@@ -16,7 +16,7 @@
1616
... Creating directory: ./grammars
1717
[Finished] File written to: ../grammars/powershell.tmLanguage.json
1818
19-
.EXAMPLE Test
19+
.EXAMPLE
2020
PS C:\EditorSyntax> .\build.ps1 Test
2121
Running specs...
2222
@@ -25,9 +25,7 @@
2525
Finished in 0.281 seconds
2626
2 tests, 5 assertions, 0 failures, 0 skipped
2727
#>
28-
[cmdletbinding()]
2928
param(
30-
[parameter()]
3129
[switch]
3230
$Test
3331
)
@@ -38,19 +36,20 @@ param(
3836

3937
SyntaxBanner
4038

41-
if (-not(& npm -v)) {
39+
if (-not (npm -v)) {
4240
throw 'Requires Node.js - Could not find npm.'
4341
}
4442

45-
& npm install
43+
npm install
4644

4745
# helper tasks
4846
function RunBuild() {
4947
BuildBanner
5048
try {
5149
Write-Host "Building grammar file(s)..."
52-
& npm run build-grammar
53-
} catch {
50+
npm run build-grammar
51+
}
52+
catch {
5453
$PSCmdlet.ThrowTerminatingError($PSItem)
5554
}
5655
}

tools/build-helpers.ps1

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
function DownloadAtom {
22
Write-Host "Downloading latest Atom release..."
33

4-
$Source = "https://atom.io/download/windows_zip?channel=stable"
4+
$Source = "https://atom.io/download/windows_zip?channel=stable"
55
$Destination = Join-Path . '\atom.zip'
66

77
try {
88
Invoke-WebRequest $Source -OutFile $Destination -ErrorAction Stop
9-
} catch {
9+
}
10+
catch {
1011
$PSCmdlet.ThrowTerminatingError($PSItem)
1112
}
1213

@@ -24,7 +25,8 @@ function ExtractAtom {
2425
try {
2526
Add-Type -AssemblyName System.IO.Compression.FileSystem
2627
[System.IO.Compression.ZipFile]::ExtractToDirectory($ZipFile, $OutPath)
27-
} catch {
28+
}
29+
catch {
2830
$PSCmdlet.ThrowTerminatingError($PSItem)
2931
}
3032

@@ -35,24 +37,27 @@ function ExtractAtom {
3537
Write-Host "Atom.zip deleted..."
3638
}
3739

38-
function ParseJasmine ($String) {
39-
if ($String -match "^\s+at.*$") {
40-
' '
41-
return
42-
}
40+
filter ParseJasmine {
41+
switch -regex ($_) {
42+
^\s+at {
43+
''
44+
break
45+
}
4346

44-
if ($_ -match "^\s+it.*$") {
45-
$_ -replace '^(\s+)(it)','$1[-] It'
46-
return
47-
}
47+
^\s+it {
48+
$_ -replace '^(\s+)(it)', '$1[-] It'
49+
break
50+
}
4851

49-
if ($_ -match "^\s+Expected.*$") {
50-
$x = $_ -replace '^(\s*)(Expected)(.*)\s(to equal .*)','$1$2$3%%$1$4'
51-
$x.Replace('%%',"`n ")
52-
return
53-
}
52+
^\s+Expected {
53+
$_ -replace '^(\s*)(Expected.*?)\s(instead found .*)', "`$1`$2`n`$1`$3"
54+
break
55+
}
5456

55-
$_
57+
default {
58+
$_
59+
}
60+
}
5661
}
5762

5863
function ExitWithCode {
@@ -70,15 +75,17 @@ function RunSpecs {
7075
$specpath = Join-Path . '\spec'
7176

7277
if (Test-Path $specpath) {
73-
& "$script:ATOM_EXE_PATH" --test spec *>&1 | ForEach-Object { ParseJasmine $_ }
74-
} else {
78+
& $script:ATOM_EXE_PATH --test $specpath *>&1 | ParseJasmine
79+
}
80+
else {
7581
throw '.\spec\ not found.'
7682
}
7783

7884
if ($LASTEXITCODE -ne 0) {
7985
if ($Env:APPVEYOR) {
8086
ExitWithCode -exitcode $LASTEXITCODE
81-
} else {
87+
}
88+
else {
8289
throw "One or more tests failed."
8390
}
8491
}

0 commit comments

Comments
 (0)