diff --git a/.github/workflows/coverage-gate.yml b/.github/workflows/coverage-gate.yml new file mode 100644 index 0000000..8562a79 --- /dev/null +++ b/.github/workflows/coverage-gate.yml @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: MPL-2.0 +# KYAML content; GitHub requires the .yml extension. +{ + name: "Counted coverage gate", + on: { + pull_request: {}, + push: { + branches: [ + "main", + ], + }, + workflow_dispatch: {}, + }, + permissions: { + contents: "read", + }, + concurrency: { + group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}", + cancel-in-progress: true, + }, + jobs: { + coverage: { + name: "Counted coverage gate", + runs-on: "ubuntu-24.04", + timeout-minutes: 30, + steps: [ + { + uses: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1", # v7.0.1 + with: { + persist-credentials: false, + }, + }, + { + name: "Install llvm-tools and cargo-llvm-cov", + run: "set -euo pipefail\nrustup component add llvm-tools-preview\ncargo install cargo-llvm-cov --locked --version 0.9.2", + }, + { + name: "Gate: every instrumented line covered or justified", + run: "bash scripts/proven-coverage.sh", + }, + { + name: "Gate self-test (planted stale, uncovered and exclusion cases)", + run: "bash scripts/tests/proven-coverage-test.sh", + }, + ], + }, + }, +} diff --git a/scripts/proven-coverage.sh b/scripts/proven-coverage.sh index 38558cf..e23cb6f 100755 --- a/scripts/proven-coverage.sh +++ b/scripts/proven-coverage.sh @@ -10,7 +10,7 @@ set -euo pipefail cd "$(dirname "$0")/.." -counted=(--test properties --test proven_properties --test proven_vectors --test proven_mutation_kills) +counted=(--test properties --test proven_properties --test proven_vectors --test proven_mutation_kills --test proven_binary64) exclusions=${PROVEN_EXCLUSIONS:-.proven/coverage-exclusions.tsv} lcov=${PROVEN_LCOV:-target/proven-coverage.lcov} diff --git a/tests/proven_binary64.rs b/tests/proven_binary64.rs new file mode 100644 index 0000000..4e32c6b --- /dev/null +++ b/tests/proven_binary64.rs @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: MPL-2.0 AND CC-BY-SA-4.0 +// Code is MPL-2.0; prose is CC-BY-SA-4.0. +//! Counted evidence for the RFC 8785 binary64 reader (`parse_jcs`): the signed, +//! unsigned and float visitor branches, with a refusal for each input class +//! that must stay refused. Expectations are literal, not recomputed. + +use ijson_jcs::{parse_jcs, to_jcs_string}; + +fn canon(input: &str) -> String { + to_jcs_string(&parse_jcs(input).expect("accepted")).unwrap() +} + +#[test] +fn signed_unsigned_and_float_tokens_follow_binary64() { + // visit_i64 (negative), visit_u64 (non-negative), visit_f64. + assert_eq!(canon("-5"), "-5"); + assert_eq!(canon("[-9007199254740993]"), "[-9007199254740992]"); + assert_eq!(canon("7"), "7"); + // Above i64: must take the unsigned branch and round to binary64. + assert_eq!(canon("18446744073709551615"), "18446744073709552000"); + assert_eq!(canon("9007199254740993"), "9007199254740992"); + assert_eq!(canon("1.5e0"), "1.5"); +} + +#[test] +fn refusals_stay_refusals() { + for bad in [ + "{\"a\":1,\"a\":2}", + "1e999", + "[1,2", + "1 2", + "\"\\ud800\"", + "\"\u{ffff}\"", + ] { + assert!(parse_jcs(bad).is_err(), "must refuse {bad:?}"); + } +} + +#[test] +fn every_value_kind_goes_through_the_binary64_visitor() { + // Strings, null, booleans, nesting and keys, so the binary64 instantiation + // of every visitor method that serde_json can reach is executed. + assert_eq!(canon("\"a\\u00e9\""), "\"a\u{e9}\""); + assert_eq!(canon("null"), "null"); + assert_eq!(canon("[true,false,null,\"x\"]"), "[true,false,null,\"x\"]"); + assert_eq!( + canon("{\"b\":[1,{\"a\":-0}],\"a\":\"\\n\"}"), + "{\"a\":\"\\n\",\"b\":[1,{\"a\":0}]}" + ); +}