Skip to content

[KYUUBI #7729][UTIL] Fail assertFileContent when the file has trailing extra lines - #7730

Open
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:kyuubi-util-scala-assertfilecontent-trailing
Open

[KYUUBI #7729][UTIL] Fail assertFileContent when the file has trailing extra lines#7730
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:kyuubi-util-scala-assertfilecontent-trailing

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

Why are the changes needed?

Closes #7729.

AssertionUtils.assertFileContent compares a file against expected lines with fileLinesIter.zipWithIndex.zip(expectedLinesIter). zip stops at the shorter side, so file lines beyond the expected content were never compared, and fileLineCount only ever reached the number of pairs zip produced. The length check assertResult(expectedLinesIter.size)(fileLineCount) therefore passed whenever the file was longer, so a golden file with stale trailing lines went unnoticed.

This drains the remaining file lines into fileLineCount after the comparison, so the length check sees the file's true length and fails when the file is longer than expected. The equal-length and shorter-file cases are unchanged. Consumers regenerate their golden files from the same source they compare against (verifyOrRegenerateGoldenFile writes toMarkdown and reads it back), so a correctly regenerated file still round-trips to the same length.

How was this patch tested?

Added AssertionUtilsSuite (the module's first self-test for the assertion helpers): a trailing-extra-line case that must throw TestFailedException with the "Line number is not expected" clue, and an exact-content case that must pass. The trailing case stops failing if the drain loop is reverted.

build/mvn test -pl kyuubi-util-scala -am
build/mvn scalastyle:check spotless:check -pl kyuubi-util-scala -am

Module green on Zulu 17.0.18 (23/23), scalastyle 0 errors, spotless clean.

Was this patch assisted by generative AI tooling?

Assisted-by: Claude Opus 4.8

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.

assertFileContent ignores trailing extra lines in golden files

1 participant