@@ -135,7 +135,7 @@ the regresql update command again to reset the expected output files.
135135
136136// Test runs regression tests for all queries.
137137// Each query runs in its own transaction that rolls back (unless commit is true).
138- func Test (root , runFilter , formatName , outputPath string , commit bool ) {
138+ func Test (root , runFilter , formatName , outputPath string , commit , noRestore bool ) {
139139 config , err := ReadConfig (root )
140140 ignorePatterns := []string {}
141141 if err == nil {
@@ -153,6 +153,25 @@ func Test(root, runFilter, formatName, outputPath string, commit bool) {
153153 // Cache config for plan quality analysis
154154 SetGlobalConfig (config )
155155
156+ // Auto-restore snapshot before test
157+ if ! noRestore && ShouldAutoRestore (config .Snapshot ) {
158+ snapshotPath := GetSnapshotPath (config .Snapshot , root )
159+ if _ , err := os .Stat (snapshotPath ); os .IsNotExist (err ) {
160+ fmt .Printf ("Error: snapshot file not found: %s\n \n Run 'regresql snapshot build' to create a snapshot, or use '--no-restore' to skip\n " , snapshotPath )
161+ os .Exit (1 )
162+ }
163+ fmt .Printf ("Restoring snapshot: %s\n " , snapshotPath )
164+ opts := RestoreOptions {
165+ InputPath : snapshotPath ,
166+ Clean : true ,
167+ }
168+ if err := RestoreSnapshot (config .PgUri , opts ); err != nil {
169+ fmt .Printf ("Error: failed to restore snapshot: %s\n " , err )
170+ os .Exit (1 )
171+ }
172+ fmt .Println ()
173+ }
174+
156175 // Validate schema hasn't changed since last snapshot build
157176 if err := ValidateSchemaHash (root ); err != nil {
158177 fmt .Printf ("Error: %s\n " , err )
0 commit comments