Skip to content

Commit

Permalink
feat: Improve the error messages in PlSqlCheckVerifierTest assertions
Browse files Browse the repository at this point in the history
This commit enhances the clarity of error messages described in assertions within PlSqlCheckVerifierTest. This adjustment includes the precise expected value and the actual output, allowing for clearer comprehension of any errors thrown during the test's execution.
  • Loading branch information
felipebz committed Feb 9, 2024
1 parent 4ca6ac6 commit 25f8dc4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,12 @@ class PlSqlCheckVerifier : PlSqlCheck() {
assertEquals(expected.startColumn, actual.primaryLocation().startLineOffset() + 1, "Bad start column at line ${expected.line}")
assertEquals(expected.endColumn, actual.primaryLocation().endLineOffset() + 1, "Bad end column at line ${expected.line}")
assertEquals(expected.endLine, actual.primaryLocation().endLine(), "Bad end line at line ${expected.line}")
if (expected.secondaryLines != null && expected.secondaryLines != secondary(actual)) {
throw AssertionError("Bad secondary locations at line ${expected.line} ==> expected: ${expected.secondaryLines} but was: ${secondary(actual)}")
}
assertEquals(expected.secondaryLines, secondary(actual), "Bad secondary locations at line ${expected.line}")
}

private fun assertEquals(expected: Any?, actual: Any?, message: String) {
if (expected != null && expected != actual) {
throw AssertionError(message)
throw AssertionError("$message ==> expected: \"${expected}\" but was: \"${actual}\"")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class PlSqlCheckVerifierTest {
PlSqlCheckVerifier.verify("src/test/resources/check_verifier_incorrect_secondary_location.sql", visitor)
fail("Test should fail")
} catch (e: AssertionError) {
assertThat(e).hasMessage("Bad secondary locations at line 8 ==> expected: [4] but was: [3, 4]")
assertThat(e).hasMessage("Bad secondary locations at line 8 ==> expected: \"[4]\" but was: \"[3, 4]\"")
}
}

Expand All @@ -130,7 +130,7 @@ class PlSqlCheckVerifierTest {
PlSqlCheckVerifier.verify("src/test/resources/check_verifier_incorrect_secondary_location2.sql", visitor)
fail("Test should fail")
} catch (e: AssertionError) {
assertThat(e).hasMessage("Bad secondary locations at line 8 ==> expected: [3, 4, 5] but was: [3, 4]")
assertThat(e).hasMessage("Bad secondary locations at line 8 ==> expected: \"[3, 4, 5]\" but was: \"[3, 4]\"")
}
}

Expand Down

0 comments on commit 25f8dc4

Please sign in to comment.