RunSplitTests loads YAML test cases and runs them against a SplitSQL function. For engines with dual implementations (lexer and parser), it enforces that both produce identical results when both succeed. When run with -record flag, it updates the YAML file with actual results: go test -run TestXx
(t *testing.T, testDataPath string, opts SplitTestOptions)
| 116 | // |
| 117 | // go test -run TestXxxSplitSQL -args -record |
| 118 | func RunSplitTests(t *testing.T, testDataPath string, opts SplitTestOptions) { |
| 119 | t.Helper() |
| 120 | |
| 121 | require.NotNil(t, opts.SplitFunc, "SplitFunc is required") |
| 122 | |
| 123 | // Get the full path to the test file |
| 124 | _, callerFile, _, ok := runtime.Caller(1) |
| 125 | require.True(t, ok, "failed to get caller info") |
| 126 | callerDir := filepath.Dir(callerFile) |
| 127 | fullPath := filepath.Join(callerDir, testDataPath) |
| 128 | |
| 129 | // Caller depth 2: skip loadTestCases (1) and RunSplitTests (2) to get the actual test function |
| 130 | testCases := loadTestCases(t, testDataPath, 2) |
| 131 | require.NotEmpty(t, testCases, "no test cases found in %s", testDataPath) |
| 132 | |
| 133 | // Record mode: update expected results in YAML file |
| 134 | if *record { |
| 135 | recordTestResults(t, fullPath, testCases, opts) |
| 136 | return |
| 137 | } |
| 138 | |
| 139 | for _, tc := range testCases { |
| 140 | t.Run(tc.Description, func(t *testing.T) { |
| 141 | runSingleTest(t, tc, opts) |
| 142 | }) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | // recordTestResults runs all test cases and updates the YAML file with actual results. |
| 147 | func recordTestResults(t *testing.T, fullPath string, testCases []SplitTestCase, opts SplitTestOptions) { |