@@ -3,7 +3,6 @@ package ast
3
3
import (
4
4
"fmt"
5
5
"os"
6
- "path"
7
6
"path/filepath"
8
7
"strings"
9
8
"testing"
@@ -14,7 +13,7 @@ import (
14
13
)
15
14
16
15
func TestDataParser (t * testing.T ) {
17
- files , err := filepath .Glob ("testdata/ parser/ *.txtar" )
16
+ files , err := filepath .Glob (filepath . Join ( "testdata" , " parser" , " *.txtar") )
18
17
if err != nil {
19
18
t .Fatalf ("failed to list testdata files: %s" , err )
20
19
}
@@ -23,21 +22,26 @@ func TestDataParser(t *testing.T) {
23
22
t .Fatal ("no testdata files found" )
24
23
}
25
24
25
+ // normalize files
26
+ for i , file := range files {
27
+ files [i ] = filepath .Clean (file )
28
+ }
29
+
26
30
for _ , file := range files {
27
31
file := file
28
32
29
33
t .Run (filepath .Base (file ), func (t * testing.T ) {
30
- t .Parallel ()
34
+ // TODO: enable parallel tests after fixing #43
35
+ // t.Parallel()
31
36
37
+ t .Logf ("Parse txtar file: %q" , file )
32
38
ar , err := txtar .ParseFile (file )
33
39
if err != nil {
34
40
t .Fatalf ("failed to parse txtar file: %s" , err )
35
41
}
36
42
37
43
dir := t .TempDir ()
38
- if err := extractTxtar (ar , dir ); err != nil {
39
- t .Fatalf ("failed to extract txtar: %s" , err )
40
- }
44
+ extractTxtar (t , ar , dir )
41
45
42
46
tc := readTestCase (t , dir )
43
47
testParser (t , dir , tc )
@@ -305,25 +309,26 @@ func checkTypeRef(t *testing.T, prefix string, expect, res *FieldTypeRef) {
305
309
}
306
310
}
307
311
308
- //---
312
+ func extractTxtar (t * testing.T , ar * txtar.Archive , dir string ) {
313
+ t .Helper ()
309
314
310
- func extractTxtar ( ar * txtar. Archive , dir string ) error {
315
+ t . Logf ( "Extracting txtar to %q" , dir )
311
316
for _ , file := range ar .Files {
312
317
name := filepath .Join (dir , file .Name )
318
+ t .Logf ("Extracting %q to %q" , file .Name , name )
313
319
if err := os .MkdirAll (filepath .Dir (name ), 0o777 ); err != nil {
314
- return err
320
+ t . Fatalf ( "failed to create dir: %s" , err )
315
321
}
316
322
if err := os .WriteFile (name , file .Data , 0o666 ); err != nil {
317
- return err
323
+ t . Fatalf ( "failed to write file: %s" , err )
318
324
}
319
325
}
320
- return nil
321
326
}
322
327
323
328
func readTestCase (t * testing.T , dir string ) parserTestCase {
324
329
t .Helper ()
325
330
326
- testCaseFile , err := os .Open (path .Join (dir , "testcase.yaml" ))
331
+ testCaseFile , err := os .Open (filepath .Join (dir , "testcase.yaml" ))
327
332
if err != nil {
328
333
t .Fatalf ("failed to open testcase file: %s" , err )
329
334
}
0 commit comments