@@ -3,7 +3,6 @@ package ast
33import (
44 "fmt"
55 "os"
6- "path"
76 "path/filepath"
87 "strings"
98 "testing"
@@ -14,7 +13,7 @@ import (
1413)
1514
1615func TestDataParser (t * testing.T ) {
17- files , err := filepath .Glob ("testdata/parser/*.txtar" )
16+ files , err := filepath .Glob (filepath . FromSlash ( "testdata/parser/*.txtar" ) )
1817 if err != nil {
1918 t .Fatalf ("failed to list testdata files: %s" , err )
2019 }
@@ -23,21 +22,26 @@ func TestDataParser(t *testing.T) {
2322 t .Fatal ("no testdata files found" )
2423 }
2524
25+ // // normalize files
26+ // for i, file := range files {
27+ // files[i] = filepath.Clean(file)
28+ // }
29+
2630 for _ , file := range files {
2731 file := file
2832
2933 t .Run (filepath .Base (file ), func (t * testing.T ) {
30- t .Parallel ()
34+ // TODO: enable parallel tests after fixing #43
35+ // t.Parallel()
3136
37+ t .Logf ("Parse txtar file: %q" , file )
3238 ar , err := txtar .ParseFile (file )
3339 if err != nil {
3440 t .Fatalf ("failed to parse txtar file: %s" , err )
3541 }
3642
3743 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 )
4145
4246 tc := readTestCase (t , dir )
4347 testParser (t , dir , tc )
@@ -305,25 +309,26 @@ func checkTypeRef(t *testing.T, prefix string, expect, res *FieldTypeRef) {
305309 }
306310}
307311
308- //---
312+ func extractTxtar (t * testing.T , ar * txtar.Archive , dir string ) {
313+ t .Helper ()
309314
310- func extractTxtar ( ar * txtar. Archive , dir string ) error {
315+ t . Logf ( "Extracting txtar to %q" , dir )
311316 for _ , file := range ar .Files {
312317 name := filepath .Join (dir , file .Name )
318+ t .Logf ("Extracting %q to %q" , file .Name , name )
313319 if err := os .MkdirAll (filepath .Dir (name ), 0o777 ); err != nil {
314- return err
320+ t . Fatalf ( "failed to create dir: %s" , err )
315321 }
316322 if err := os .WriteFile (name , file .Data , 0o666 ); err != nil {
317- return err
323+ t . Fatalf ( "failed to write file: %s" , err )
318324 }
319325 }
320- return nil
321326}
322327
323328func readTestCase (t * testing.T , dir string ) parserTestCase {
324329 t .Helper ()
325330
326- testCaseFile , err := os .Open (path .Join (dir , "testcase.yaml" ))
331+ testCaseFile , err := os .Open (filepath .Join (dir , "testcase.yaml" ))
327332 if err != nil {
328333 t .Fatalf ("failed to open testcase file: %s" , err )
329334 }
0 commit comments