Skip to content

Commit 63d55d1

Browse files
committed
Move things around
1 parent efbcb57 commit 63d55d1

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

tests/pester/Syntax.Tests.ps1

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ Import-Module "$PSScriptRoot\SyntaxHelper.psm1"
44

55
Describe "Syntax highlighting" {
66

7-
if (-not (Test-Path $scopesFile)) {
7+
Context "test-file.ps1" {
8+
9+
$tokensFileName = "test-file.ps1.tokens"
10+
$tokensFolder = Join-Path $sublimeRoot "Data\Packages\User\UnitTesting\tokens"
11+
$scopesFile = Join-Path $tokensFolder $tokensFileName
12+
13+
$testFile = Resolve-Path "$PSScriptRoot\..\samples\test-file.ps1"
14+
15+
if (-not (Test-Path $scopesFile)) {
816
Write-Warning @'
917
This Pester UT file consumes scopes generated by python unit test Test_TokenGenerator.testGetTokens .
1018
You need to run python tests first to make it work.
1119
'@
1220
return
13-
}
14-
15-
Context "test-file.ps1" {
16-
17-
$scopesFile = Join-Path $sublimeRoot "Data\Packages\User\UnitTesting\tokens\PowerShell_tokens"
18-
$testFile = Resolve-Path "$PSScriptRoot\..\samples\test-file.ps1"
21+
}
1922

2023
# splitted in two lines, because of a bug in Sort-Object
2124
$stScopes = cat -Raw $scopesFile | ConvertFrom-Json; $stScopes = $stScopes | sort -Property @('startOffset', 'endOffset')
@@ -47,7 +50,7 @@ You need to run python tests first to make it work.
4750
$ignore = $true
4851
}
4952

50-
# These are bugs, TODO it
53+
# TODO: These are bugs
5154
if (@('Number', 'Redirection') -contains $psScope.Kind) {
5255
$ignore = $true
5356
}
@@ -59,6 +62,7 @@ You need to run python tests first to make it work.
5962
}
6063
}
6164
}
65+
# TODO: These are bugs, make it 0
6266
$errorCounter | Should be @(0..4)
6367
}
6468
}

tests/py/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
2-
32
import sublime
4-
3+
import os
4+
import json
55

66
class ViewTest(unittest.TestCase):
77
def setUp(self):
@@ -39,6 +39,20 @@ def setUp(self):
3939

4040
class PowerShellSyntaxTokenTest(PowerShellSyntaxTest):
4141

42+
def writeTokensToFile(self, tokens, name):
43+
outputdir = os.path.join(sublime.packages_path(), 'User', 'UnitTesting', "tokens")
44+
if not os.path.isdir(outputdir):
45+
os.makedirs(outputdir)
46+
outfile = os.path.join(outputdir, name)
47+
48+
if os.path.exists(outfile):
49+
os.remove(outfile)
50+
with open(outfile, 'w') as f:
51+
f.write(json.dumps(tokens, indent=4, separators=(',', ': ')))
52+
53+
def getTestFilePath(self):
54+
return os.path.join(sublime.packages_path(), 'PowerShell', 'tests', 'samples', 'test-file.ps1')
55+
4256
def getTokens(self):
4357
selectors = [
4458
"comment.block",

tests/py/syntax_def/test_token_gen.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,17 @@
55
from PowerShell.tests.py import PowerShellSyntaxTokenTest
66

77
class Test_TokenGenerator(PowerShellSyntaxTokenTest):
8-
def testGetTokens(self):
8+
9+
def setUp(self):
10+
super().setUp()
11+
self.test_path = os.path.join(sublime.packages_path(), 'PowerShell', 'tests', 'samples', 'test-file.ps1')
912

10-
test_path = os.path.join(sublime.packages_path(), 'PowerShell', 'tests', 'samples', 'test-file.ps1')
13+
def testGetTokens(self):
1114

12-
with open(test_path) as f:
15+
with open(self.test_path) as f:
1316
content = f.readlines()
1417
for line in content:
1518
self.append(line)
1619

17-
tokens = self.getTokens()
18-
19-
outputdir = os.path.join(sublime.packages_path(), 'User', 'UnitTesting', "tokens")
20-
if not os.path.isdir(outputdir):
21-
os.makedirs(outputdir)
22-
outfile = os.path.join(outputdir, "PowerShell_tokens")
23-
24-
if os.path.exists(outfile):
25-
os.remove(outfile)
26-
with open(outfile, 'w') as f:
27-
f.write(json.dumps(tokens, indent=4, separators=(',', ': ')))
20+
self.writeTokensToFile(self.getTokens(), "test-file.ps1.tokens")
21+

0 commit comments

Comments
 (0)