This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ps1
56 lines (54 loc) · 1.6 KB
/
test.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Usage:
# - test
# - test tokens <filename under example/>
# - test tree <filename under example/>
# - test gui <filename under example/>
$origin = Get-Location
$option = $args[0]
$filename = $args[1]
if (!$option -and !$filename) {
# test all
Set-Location $PSScriptRoot
# get all ASN.1 files
$filelist = Get-ChildItem -Path examples/* -Include *.asn1
# complie the grammar
antlr4 -o .antlr src/asn1.g4 && `
Set-Location .antlr && `
javac *.java
$total = ($filelist | Measure-Object).Count
$numOk = 0
$numError = 0
foreach ($file in $filelist) {
$filename = $file.Name
# temporary file to store errors
$temp = New-TemporaryFile
grun asn1 moduleDefinitions `
-encoding utf-8 `
$PSScriptRoot/examples/$filename > $null 2>$temp
$result = Get-Content $temp | Measure-Object -Character
if ($result.Characters -eq 0) {
$numOk += 1
Write-Host "✅" $filename
} else {
$numError += 1
Copy-Item $temp -Destination $PSScriptRoot/test-$filename-error.log
Write-Host "❌" $filename
}
}
Write-Host "✅" $numOk "❌" $numError "#️⃣" $total
Set-Location $origin
exit $numError
} else {
# test a specific file
if ($option -eq "tokens" -or $option -eq "tree" -or $option -eq "gui") {
Set-Location $PSScriptRoot
antlr4 -o .antlr src/asn1.g4 && `
Set-Location .antlr && `
javac *.java && `
grun asn1 moduleDefinitions -$option `
-encoding utf-8 `
$PSScriptRoot/examples/$filename > $PSScriptRoot/test-$option-$filename.log `
2>$PSScriptRoot/test-$option-$filename-error.log
Set-Location $origin
}
}