Skip to content

Increase TSqlParser facade coverage for Reader overloads, builder/getters, exception path, and CLI entrypoint - #31

Merged
fupacat merged 4 commits into
masterfrom
copilot/add-unit-test-coverage-tsqlparser
Oct 12, 2026
Merged

fupacat merged 4 commits into
masterfrom
copilot/add-unit-test-coverage-tsqlparser

Conversation

Copilot AI commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

TSqlParser.java had significant uncovered control flow across facade overloads, builder/getter accessors, parse exception handling, and main(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

    • Added tests for:
      • parse(Reader)
      • parse(Reader, SqlVersion)
      • fluent builder behavior (initialQuotedIdentifiers, sqlVersion, build)
      • getter values (isInitialQuotedIdentifiersOn, getTargetVersion)
    • Included explicit assertion for sqlVersion(null) fallback to SQL180.
  • Deterministic exception-branch coverage

    • Added package-private factory method in TSqlParser:
      • TSql180Parser createUnderlyingParser()
    • parseScript(Reader) now uses the factory, allowing a test override to force an internal parser exception and validate ParseError wrapping behavior.
  • CLI entrypoint coverage (main)

    • Added subprocess-based tests for:
      • help output (-h)
      • raw SQL success path
      • invalid SQL failure path (non-zero exit)
      • file input via -f <path>
      • missing file error path (non-zero exit)
TSqlParser parser = new TSqlParser() {
    @Override
    TSql180Parser createUnderlyingParser() {
        return new TSql180Parser() {
            @Override
            public TSqlFragment parse(java.io.Reader reader, List errors) {
                throw new RuntimeException("boom");
            }
        };
    }
};

Co-authored-by: fupacat <595487+fupacat@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit test coverage for TSqlParser facade and CLI Increase TSqlParser facade coverage for Reader overloads, builder/getters, exception path, and CLI entrypoint Oct 12, 2026
Copilot AI requested a review from fupacat October 12, 2026 19:20
@fupacat
fupacat marked this pull request as ready for review October 12, 2026 20:08
Copilot AI balanced review requested due to automatic review settings October 12, 2026 20:08
@fupacat
fupacat enabled auto-merge (squash) October 12, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 Reader overloads, fluent Builder (including sqlVersion(null) fallback to SQL180), and getters.
  • Introduced a package-private createUnderlyingParser() factory in TSqlParser and used it in parseScript(Reader), enabling a test override that forces the parser-exception/ParseError wrapping 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 runMain is not instrumented by the JaCoCo agent, so the main method lines will likely remain uncovered despite these tests validating behavior — the coverage objective for main from issue #28 may not be met this way.
  • The new TRACEABILITY_MAPPING: REQ-028 comments reference a requirement that is not defined in context/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.

Comment on lines +196 to +200
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
Copilot AI balanced review requested due to automatic review settings October 12, 2026 20:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Copilot AI balanced review requested due to automatic review settings October 12, 2026 20:22
@fupacat
fupacat merged commit dddfaef into master Oct 12, 2026
6 checks passed
@fupacat
fupacat deleted the copilot/add-unit-test-coverage-tsqlparser branch October 12, 2026 20:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

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.

Add unit test coverage for TSqlParser facade overloads, builder, and CLI

3 participants