@@ -15,11 +15,10 @@ import (
1515 "github.com/mendixlabs/mxcli/mdl/visitor"
1616)
1717
18- // TestMxCheck_DoctypeScripts executes all doctype-tests/*.mdl example scripts
19- // against a fresh Mendix project and validates the result with mx check.
18+ // TestMxCheck_DoctypeScripts executes each doctype-tests/*.mdl example script
19+ // in its own fresh Mendix project and validates the result with mx check.
2020//
21- // Scripts are executed in alphabetical order on the same project copy so that
22- // later scripts (e.g., pages) can reference entities created by earlier ones.
21+ // Each script runs in isolation so errors are cleanly attributed.
2322// Files matching *.test.mdl or *.tests.mdl are skipped (they require Docker).
2423func TestMxCheck_DoctypeScripts (t * testing.T ) {
2524 if ! mxCheckAvailable () {
@@ -52,58 +51,51 @@ func TestMxCheck_DoctypeScripts(t *testing.T) {
5251 }
5352 scripts = append (scripts , name )
5453 }
55- sort .Strings (scripts ) // Execute in alphabetical order (01-, 02-, ...)
54+ sort .Strings (scripts )
5655
5756 if len (scripts ) == 0 {
5857 t .Skip ("no eligible MDL scripts found" )
5958 }
6059
61- // Set up a single project for all scripts
62- env := setupTestEnv (t )
63- defer env .teardown ()
64-
65- // Execute each script in order, recording any execution errors per-script
66- var execErrors []string
6760 for _ , name := range scripts {
6861 scriptPath := filepath .Join (doctypeDir , name )
6962 content , err := os .ReadFile (scriptPath )
7063 if err != nil {
7164 t .Fatalf ("Failed to read %s: %v" , name , err )
7265 }
7366
74- t .Run ("exec/" + name , func (t * testing.T ) {
67+ t .Run (name , func (t * testing.T ) {
68+ t .Parallel ()
69+
70+ // Fresh project for each script
71+ env := setupTestEnv (t )
72+ defer env .teardown ()
73+
74+ // Execute the script
7575 prog , errs := visitor .Build (string (content ))
7676 if len (errs ) > 0 {
7777 t .Fatalf ("Parse error: %v" , errs [0 ])
7878 }
7979
8080 if err := env .executor .ExecuteProgram (prog ); err != nil {
81- // Log but don't fatal — allow other scripts to continue
8281 t .Errorf ("Execution error: %v" , err )
83- execErrors = append (execErrors , name + ": " + err .Error ())
8482 }
85- })
86- }
87-
88- // Disconnect to flush all changes to disk
89- env .executor .Execute (& ast.DisconnectStmt {})
9083
91- // Run mx check on the final project state
92- t .Run ("mx-check" , func (t * testing.T ) {
93- if len (execErrors ) > 0 {
94- t .Logf ("Note: %d script(s) had execution errors" , len (execErrors ))
95- }
96-
97- output , err := runMxCheck (t , env .projectPath )
98- if err != nil {
99- lowerOutput := strings .ToLower (output )
100- if strings .Contains (lowerOutput , "error" ) {
101- t .Errorf ("mx check found errors after executing all doctype scripts:\n %s" , output )
84+ // Flush to disk
85+ env .executor .Execute (& ast.DisconnectStmt {})
86+
87+ // Run mx check
88+ output , mxErr := runMxCheck (t , env .projectPath )
89+ if mxErr != nil {
90+ lowerOutput := strings .ToLower (output )
91+ if strings .Contains (lowerOutput , "error" ) {
92+ t .Errorf ("mx check found errors:\n %s" , output )
93+ } else {
94+ t .Logf ("mx check output:\n %s" , output )
95+ }
10296 } else {
103- t .Logf ("mx check output: \n %s" , output )
97+ t .Logf ("mx check passed: 0 errors" )
10498 }
105- } else {
106- t .Logf ("mx check passed:\n %s" , output )
107- }
108- })
99+ })
100+ }
109101}
0 commit comments