Repository navigation
test: let a golden baseline hold a text of another language than SQL - #74
xperiandri wants to merge 1 commit into
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 42 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
There was a problem hiding this comment.
🟡 Changes recommended
Unrejected Windows filename aliases can overwrite or delete scripts, while whitespace normalization can falsely report semantically different Groovy scripts as matching.
2 open issues
What changed in this PR
Extends the shared golden-baseline helpers beyond SQL to support future Gremlin script tests, while preserving the existing SQL comparison APIs.
Changes:
- Adds extension-based
compareTextandassertTextMatcheshelpers with extension validation. - Adds Groovy round-trip, SQL-wrapper, and invalid-extension tests.
- Updates naming and documentation to describe language-independent text baselines.
| File | Description |
|---|---|
tests/Cosmos.Tests/TestInfrastructure/BaselineTests.fs |
Tests custom extensions, SQL compatibility, and extension rejection. |
tests/Cosmos.Tests.Infrastructure/Baseline.fs |
Generalizes baseline comparison and assertions while retaining SQL wrappers. |
.github/copilot-instructions.md |
Documents rewriting baselines for languages other than SQL. |
Review effort: Balanced
24d64a9 to
9a083d4
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The comparison-mode test expects AssertFailedException but receives AssertInconclusiveException when baseline rewriting is enabled outside CI, causing it to fail during the documented rewrite workflow.
1 open issue
2 resolved since last review
Review effort: Balanced
|
|
||
| [<TestMethod>] | ||
| member _.``assertTextMatches fails the test for a text that differs from its baseline in a line break`` () = | ||
| inTemporaryDirectory (fun directory -> |
The tests of the Gremlin libraries will compare Groovy scripts with golden files, as the tests of the query translator compare SQL. `Baseline` wrote and read only `<case>.sql`. `Baseline.compareText` and `Baseline.assertTextMatches` take the extension of the text file as their first argument, for example `groovy`. They compare two texts after `normalizeText`, which changes only the line breaks and the whitespace at both ends. In Groovy, a line break ends a comment, so the line breaks must count. `Baseline.compare` and `Baseline.assertMatches` use `SqlExtension` and still collapse the whitespace of a query with `normalizeSql`. Thus the tests that compare SQL do not change. `Baseline.isRewriting` tells whether the assertions write the baselines instead of comparing them, so that a test of an assertion can be inconclusive then. `compareText` refuses an extension that is empty, starts with a dot, cannot be part of a file name, or is the extension of the parameter file (`params.json`, in capital or small letters). A suite, a case name or an extension must not end with a dot or a space: Windows removes such a character from the end of a file or directory name, so the extension `params.json.` would give the parameter file. The union cases `Missing` and `Rewritten` name their path `textPath`, because the text can be other than SQL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9a083d4 to
75ca625
Compare


Summary
Baselinecan now compare a golden file of another language than SQL, for example a Groovy script. The tests of the Gremlin libraries will compare their Groovy scripts in this way, as the tests of the query translator compare SQL. This is the second step of the plan for the Gremlin libraries. It is independent of the first step (branchfeat/cosmos-json-package).Change
Baseline.compareTextandBaseline.assertTextMatchestake the extension of the text file as their first argument, for examplegroovy. The files areBaselines/<suite>/<case>.<extension>andBaselines/<suite>/<case>.params.json.Baseline.normalizeText, which changes only the line breaks and the whitespace at both ends. In Groovy, a line break ends a comment:g.V() // allfollowed by.hasLabel('P')on the next line is another script than the same text on one line.Baseline.compareandBaseline.assertMatchesuseBaseline.SqlExtension(sql) and still compare afterBaseline.normalizeSql, which collapses the whitespace. Thus the tests that compare SQL do not change.compareTextrefuses an extension that is empty, starts with a dot, cannot be part of a file name, or is the extension of the parameter file (params.json, in capital or small letters). On Windows and macOS, a text file with that extension is the parameter file.params.json.would give the parameter file, and the suiteSuite.would give the directorySuite.Comparison.MissingandComparison.Rewrittenname their pathtextPath.COSMOS_REWRITE_BASELINESin.github/copilot-instructions.mdnamesassertTextMatches.On
mainand on the open branches, onlyBaselineTestsusesBaseline. Thus the new names break no other code.Tests
groovybaseline, which also checks thatcomparelooks for the.sqlfile of the same case; a text that differs from its baseline only in a line break; a text that differs only in the kind of line break;normalizeText; the two assertion functions; eight extensions thatcompareTextrefuses; two suite names that end with a dot or a space.BaselineTestspass. 16 of them are new.compareTextthat collapses whitespace and acomparethat does not; anormalizeTextthat keeps a carriage return or does not trim; anassertMatchesthat compares exactly; an assertion that ignores a difference.Review
Round 1 (Copilot): a dot or a space at the end of an extension, and the line breaks of a text other than SQL. The commit has the fixes for both.
Not in this change
The plan had an overridable
CleanupAsyncof the emulator fixture in this step too. It moves to the step that adds the fixture of the Gremlin emulator tests, its only user.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation