Skip to content

Close the gaps in the test suite, and fix what they found - #1

Merged
leiddev merged 2 commits into
mainfrom
tests/close-the-gaps
Nov 13, 2026
Merged

leiddev merged 2 commits into
mainfrom
tests/close-the-gaps

Conversation

@leiddev

@leiddev leiddev commented Nov 13, 2026

Copy link
Copy Markdown
Owner

What this does

The suite covered the happy path of every header and touched some of the API not at all. This closes those gaps and fixes the three things the new tests found.

Tests

49 cases / 345 checks → 105 cases / 916 checks.

  • tests/json_index_test.cpp (new) — the path syntax and its escaping, the line and column of every token, the kind of every value, duplicates, and ByteLess with the high-byte case that made it necessary.
  • tests/decimal_test.cpp (new) — decimal_text() at every length and at the largest value, signed_text() including the most negative value, and the token kind names.
  • tests/json_text_test.cpp — as_* leaving its output alone on failure, the _or reads, add/try_add on a container that cannot hold them, the path in a write failure, and the boundary between valid and invalid UTF-8.
  • tests/json_document_test.cpp — every array read failing and changing nothing, last_error() for every kind of fallback, the container a write creates at each depth, and a write that fails below the root leaving the document whole.
  • tests/text_file_test.cpp — an empty file, a directory as a target, the cleanup of a write that cannot go through, and save_file() failing because the document cannot be written.

Fixes they found

  • read_text_file() threw on a directory under libstdc++. GCC's basic_filebuf reports the failure by throwing where MSVC and libc++ set badbit, so a documented return false was an exception on Linux and not on Windows. The path is checked before the stream is opened.
  • The message for a key that holds a NUL byte read the key at 'outer', which names a place a key cannot be in. It is the key of 'outer' now.
  • get_documents() takes an item of any kind. That was the behaviour, but not a decision anyone had written down. It is documented and pinned now, next to the scalar array reads that do refuse such an item.

Version

0.1.1 — a fix and tests, no new API. version.hpp, the CMake project version and the CHANGELOG are bumped together.

Verification

Configuration Result
MSVC x64 Debug and Release, /W4 /WX 105 passed
GCC 9.3 Linux, compiled, -Wall -Wextra -Wpedantic -Werror 105 passed
GCC 9.3 Linux, header-only 105 passed
clang-format 19.1.7 (the pinned CI release) clean

The 32-bit builds were not run locally: g++-multilib is not installed on the Linux box used here, and CI installs it itself. That matrix entry is the one thing this PR relies on CI to confirm.

🤖 Generated with BaoCode

leiddev and others added 2 commits November 13, 2026 15:13
The suite covered the happy path of every header and touched some of the API
not at all. Two headers had no test of their own: the path syntax with its
escaping and the line and column of every token from json_index.hpp, which is
what a tool that only reports a mistake uses, and decimal_text() with
signed_text(), where the most negative value of the type is the one a hand
written conversion gets wrong.

The failure paths are the other half. A read that fails now has to leave its
output alone, every _or read of every kind has to keep last_error(), each array
read has to fail and change nothing, and a write that fails below the root has
to leave the document whole. The valid UTF-8 sequences are pinned next to the
invalid ones the suite already refused, because a scanner that only ever saw
the invalid side would still refuse half of the world.

Three things came out of that:

- read_text_file() threw on a directory under libstdc++, which reports the
  failure by throwing where MSVC and libc++ set badbit. The path is checked
  before the stream is opened, so reading a directory is a false and a message
  on every platform.
- A key that holds a NUL byte was named by "the key at 'outer'", which reads as
  a place a key cannot be in. It is now "the key of 'outer'".
- get_documents() takes an item of any kind. That was the behaviour and not a
  documented decision; it is documented now and pinned by a test, next to the
  scalar array reads that do refuse such an item.

Version 0.1.1: a fix and tests, no new API.

Co-Authored-By: BaoCode <noreply@baocode.dev>
The first push turned the 32 bit jobs red, which is what those jobs are for.

signed_text() carried the magnitude of a negative long long through std::size_t.
That is a 64 bit type on the machines this was developed on and a 32 bit one on
every 32 bit platform, so the high half of the number was cut off and
signed_text(-9223372036854775807LL - 1) printed "-0". The magnitude now goes
through unsigned long long, which is at least as wide as the value it has to
hold by definition, and decimal_text() keeps its std::size_t parameter because a
subscript is what it formats.

write_text_file() deleted a directory that was passed as its target. The retry
after a failed rename removes the target before trying again, and on a POSIX
system std::remove() removes a directory, so the second rename put the file in
the directory's place and the call reported success. The retry is now only taken
when the target is a regular file.

The test for that case wrote over the directory every other file test uses, so
when it went wrong it took five other cases down with it. It now makes a
directory of its own, and checks that the directory survived.

Both were found by cross compiling the suite for 32 bit ARM (arm-himix200-linux,
the Hi3516 toolchain) and running it on ARMv7 hardware, where all 105 cases pass.

Co-Authored-By: BaoCode <noreply@baocode.dev>
@leiddev
leiddev merged commit 75a551c into main Nov 13, 2026
24 checks passed
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