Skip to content

Conversation

rogervinas
Copy link
Contributor

@rogervinas rogervinas commented Nov 29, 2024

Having a snapshot with a scenario and a body that contains something similar to [xxx]=yyy makes the Snapshot.parse regex fail, resulting in tests failing due to ERROR: Found orphan snapshots

Issue #178

Test shouldParseSnapshotWithScenarioAndBodyWithSomethingSimilarToAnScenarioToConfuseRegex will fail, one possible solution is to change the regex in Snapshot.parse:

from:

String regex = "^(?<name>.*?)(\\[(?<scenario>.*)\\])?=(?<header>\\{.*?\\})?(?<snapshot>(.*)$)";

to:

String regex = "^(?<name>.*?)(\\[(?<scenario>[^]]*)])?=(?<header>\\{[^}]*?})?(?<snapshot>(.*)$)";

See commit Improve regex and note the [^]]* in scenario group and [^}]* in header group, instead of just .*

@jackmatt2
Copy link
Member

Can you run the following command and then push the files again?

./gradlew :java-snapshot-testing-core:spotlessApply

@rogervinas
Copy link
Contributor Author

@jackmatt2 done!

@jackmatt2
Copy link
Member

Thanks, I actually want to encode the body of the snapshot ... eventually which would make this PR unnecessary. However as a stopgap this is fine.

@jackmatt2 jackmatt2 merged commit 2e2087b into origin-energy:master Dec 16, 2024
6 checks passed
@rogervinas rogervinas deleted the snapshot-regex-fix branch December 20, 2024 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants