Skip to content

Add code coverage#4

Merged
colemancda merged 23 commits into
masterfrom
feature/unit-tests
Jul 18, 2026
Merged

Add code coverage#4
colemancda merged 23 commits into
masterfrom
feature/unit-tests

Conversation

@colemancda

@colemancda colemancda commented Jul 18, 2026

Copy link
Copy Markdown
Member

Summary

Code coverage

  • Add Scripts/coverage.sh, which runs the test suite with coverage instrumentation, exports LCOV (coverage.lcov) and Cobertura (coverage.xml) reports to .build/coverage/, and fails if line coverage of the package sources drops below a threshold.
  • Add a coverage job to CI that enforces a 95% minimum (current: 96.98%, up from 66.57%), uploads the report to GitHub Code Quality for per-PR coverage display, and archives both reports as a build artifact.
  • CI now triggers only on push (plus manual workflow_dispatch), eliminating duplicate push + pull_request runs.

Tests (104 total, 68 new)

  • BindingFormatTests — UUID/Date/Data bindings, Julian day and ISO8601 conversion
  • LocationAndAffinityTestsConnection.Location, URIQueryParameter, all five TypeAffinity rules
  • ValueAccessTests — every Binding conversion and BindingConvertible conformance, Column.Value, Row reading of all five value types
  • ConnectionStatementTests — connection properties, extended error codes, execute limits, bind/step error paths
  • FunctionEdgeCaseTests — function/collation removal, all argument and result types, window-function xInverse/empty-frame paths, schema DEFAULT clauses, registration failures, stale-error column reads
  • OfficialSuitePortTests — representative cases ported from SQLite's official TCL test suite (select1, null, types, expr, insert/delete/update, collate1), via a TCLHarness wrapper reproducing execsql/catchsql semantics

Verified on Linux via Docker (swift:6.3.3, matching the CI container) in addition to macOS.

Bug fixes found by the new tests

  • Use-after-free in function registration: when SQLite rejects a registration (argument count above SQLITE_MAX_FUNCTION_ARG), it invokes the xDestroy destructor itself; the library also released the callback box manually, crashing with SIGSEGV. Fixed for scalar, aggregate, and window functions (collations correctly keep the manual release, since sqlite3_create_collation_v2 does not call xDestroy on failure).
  • Case-sensitive BLOB affinity rule: TypeAffinity("blob") returned NUMERIC instead of BLOB because rule 3 checked the non-uppercased string.
  • Discarded SQLite diagnostics: failed statement preparation threw a generic "Unable to initialize statement." instead of SQLite's own message (e.g. "no such table: t").
  • Stale test expectation: the bundled data.sqlite contains 6099 rows in site_amenities, not 5932.

Remaining uncovered lines (~3%) are defensive guards (nil sqlite3_context in C callbacks, allocation-failure paths, impossible switch defaults) that cannot be triggered without inducing crashes.

Test plan

  • All 104 tests pass on macOS
  • All tests pass on Linux (Docker, swift:6.3.3)
  • Scripts/coverage.sh exits 0 at the 95% threshold and produces both report files
  • CI green across macOS, Linux, Android, and Windows

@github-code-quality

github-code-quality Bot commented Jul 18, 2026

Copy link
Copy Markdown

Code Coverage Overview

Languages: Swift

Swift / code-coverage/llvm-cov

The overall coverage in the branch is 97%. Coverage data for the branch is not yet available.

Show a code coverage summary of the most covered files.
File c4460fa +/-
Sources/SQLite/Binding.swift 100%
Sources/SQLite/Schema.swift 100%
Sources/SQLite/...Statement.swift 100%
Sources/SQLite/Column.swift 100%
Sources/SQLite/...eAffinity.swift 100%
Sources/SQLite/Function.swift 98%
Sources/SQLite/Statement.swift 97%
Sources/SQLite/...onnection.swift 96%
Sources/SQLite/...eFunction.swift 87%
Sources/SQLite/...wFunction.swift 87%

Updated July 18, 2026 01:35 UTC
Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@colemancda
colemancda merged commit d73bcbb into master Jul 18, 2026
5 checks passed
@colemancda
colemancda deleted the feature/unit-tests branch July 18, 2026 01:42
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.

1 participant