Repository navigation
Increase TSqlParser facade coverage for Reader overloads, builder/getters, exception path, and CLI entrypoint - #31
Conversation
Co-authored-by: fupacat <595487+fupacat@users.noreply.github.com>
TSqlParser facade coverage for Reader overloads, builder/getters, exception path, and CLI entrypoint
There was a problem hiding this comment.
🟡 Changes recommended
The subprocess-based main tests won't register JaCoCo coverage and the tests reference an undefined requirement (REQ-028), undermining the stated coverage/traceability goals.
2 open findings
What changed in this PR
This PR expands unit-test coverage for TSqlParser, the public facade/CLI entry point of the core T-SQL parsing library. The linked issue (#28) reports that TSqlParser.java line coverage was only 33.7%, with the Reader overloads, fluent Builder, getters, the parse-exception branch, and the main CLI path all uncovered. To make the internal exception branch deterministically testable, the PR also introduces a small package-private seam (createUnderlyingParser()) in production code.
Changes:
- Added tests for the
Readeroverloads, fluentBuilder(includingsqlVersion(null)fallback toSQL180), and getters. - Introduced a package-private
createUnderlyingParser()factory inTSqlParserand used it inparseScript(Reader), enabling a test override that forces the parser-exception/ParseErrorwrapping branch. - Added subprocess-based tests for
main(-h, raw SQL success, invalid SQL failure,-f <file>, and missing-file error paths).
| File | Description |
|---|---|
| tsql-scriptdom-core/src/main/java/io/github/fupacat/TSqlParser.java | Adds package-private createUnderlyingParser() factory and uses it in parseScript(Reader) as a test seam; behavior-preserving. |
| tsql-scriptdom-core/src/test/java/io/github/fupacat/TSqlParserFacadeTest.java | Adds facade/builder/getter/exception tests plus subprocess-based main CLI tests and a runMain helper. |
Notes for the author:
- The subprocess-launched JVM in
runMainis not instrumented by the JaCoCo agent, so themainmethod lines will likely remain uncovered despite these tests validating behavior — the coverage objective formainfrom issue #28 may not be met this way. - The new
TRACEABILITY_MAPPING: REQ-028comments reference a requirement that is not defined incontext/SRS.md(requirements only go up to REQ-023), breaking the traceability chain used by the project.
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| Process process = new ProcessBuilder(command).start(); | ||
| String stdout = new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8); | ||
| String stderr = new String(process.getErrorStream().readAllBytes(), StandardCharsets.UTF_8); | ||
| int exitCode = process.waitFor(); | ||
| return new MainExecution(exitCode, stdout, stderr); |
|
|
||
| public class TSqlParserFacadeTest { | ||
|
|
||
| // TRACEABILITY_MAPPING: REQ-028 |
There was a problem hiding this comment.
🔵 Needs a closer look
The main tests run in an un-instrumented child JVM so they don't raise JaCoCo coverage for main() (the PR's stated goal), and the traceability mappings reference an undefined REQ-028.
2 open findings
🧠 Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
All new tests use the traceability mapping REQ-028, which is not defined in context/SRS.md (only REQ-001..REQ-023 exist), violating the repository's established MCSWE v3 traceability convention.
2 open findings
🧠 Review effort: Balanced


TSqlParser.javahad significant uncovered control flow across facade overloads, builder/getter accessors, parse exception handling, andmain(String[] args)argument paths. This update adds focused unit coverage for those paths and introduces a minimal test seam to reliably exercise the parser-exception branch.Facade overloads + builder/getters
parse(Reader)parse(Reader, SqlVersion)initialQuotedIdentifiers,sqlVersion,build)isInitialQuotedIdentifiersOn,getTargetVersion)sqlVersion(null)fallback toSQL180.Deterministic exception-branch coverage
TSqlParser:TSql180Parser createUnderlyingParser()parseScript(Reader)now uses the factory, allowing a test override to force an internal parser exception and validateParseErrorwrapping behavior.CLI entrypoint coverage (
main)-h)-f <path>