Skip to content

Commit 9ed6e96

Browse files
committed
Make harness
1 parent 596dbfc commit 9ed6e96

File tree

4 files changed

+50
-10
lines changed

4 files changed

+50
-10
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ install:
77
- ps: mkdir "C:\st\Data\Packages\PowerShell" -force > $null
88
- ps: cp -Recurse * "C:\st\Data\Packages\PowerShell" -Force
99
- ps: git clone -q --branch=master https://github.com/my-personal-forks/UnitTesting.git "C:\st\Data\Packages\UnitTesting"
10-
- ps: write-host -ForegroundColor Yellow "installing pester" -
10+
- ps: write-host -ForegroundColor Yellow "installing pester"
1111
- ps: cinst pester
1212

1313
build: false

tests/pester/Syntax.Tests.ps1

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
<#
1+
$sublimeRoot = "C:\st"
2+
$scopesFile = Join-Path $sublimeRoot "Data\Packages\User\UnitTesting\tokens\PowerShell_tokens"
3+
$testFile = Resolve-Path "$PSScriptRoot\..\samples\test-file.ps1"
24

3-
This Pester UT file consumes tokens generated by python unit test Test_TokenGenerator.testGetTokens .
5+
Import-Module "$PSScriptRoot\SyntaxHelper.psm1"
6+
7+
Describe "Syntax highlighting" {
8+
9+
if (-not (Test-Path $scopesFile)) {
10+
Write-Warning @'
11+
This Pester UT file consumes scopes generated by python unit test Test_TokenGenerator.testGetTokens .
412
You need to run python tests first to make it work.
13+
'@
14+
return
15+
}
516

6-
#>
17+
Context "test-file.ps1" {
18+
19+
$scopes = cat -Raw $scopesFile | ConvertFrom-Json
20+
$tokens = Get-TokensFromFile $testFile
721

8-
Describe "Syntax highlighting" {
9-
Context "bla" {
10-
It "test" {
11-
1 | Should be 1
22+
It "doesn't split tokens to scopes" {
23+
1224
}
1325
}
1426
}

tests/pester/SyntaxHelper.psm1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function Get-TokensFromFile
2+
{
3+
[CmdletBinding()]
4+
param(
5+
[Parameter(ValueFromPipeline)]
6+
[string] $filePath
7+
)
8+
9+
$tokens = $null
10+
$errors = $null
11+
$ast = [System.Management.Automation.Language.Parser]::ParseFile((Resolve-Path $filePath).Path, [ref]$tokens, [ref]$errors)
12+
13+
return $tokens
14+
}
15+
16+
17+
function Get-TokensFromInput
18+
{
19+
[CmdletBinding()]
20+
param(
21+
[Parameter(ValueFromPipeline)]
22+
[string] $inputString
23+
)
24+
25+
$tokens = $null
26+
$errors = $null
27+
$ast = [System.Management.Automation.Language.Parser]::ParseInput($inputString, [ref]$tokens, [ref]$errors)
28+
29+
return $tokens
30+
}

tests/py/syntax_def/test_token_gen.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@ def testGetTokens(self):
2525
os.remove(outfile)
2626
with open(outfile, 'w') as f:
2727
f.write(json.dumps(tokens, indent=4, separators=(',', ': ')))
28-
f.write(test_path)
29-

0 commit comments

Comments
 (0)