Repository navigation
Close the gaps in the test suite, and fix what they found - #1
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andByteLesswith 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_orreads,add/try_addon 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, andsave_file()failing because the document cannot be written.Fixes they found
read_text_file()threw on a directory under libstdc++. GCC'sbasic_filebufreports the failure by throwing where MSVC and libc++ setbadbit, so a documentedreturn falsewas an exception on Linux and not on Windows. The path is checked before the stream is opened.the key at 'outer', which names a place a key cannot be in. It isthe 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
/W4 /WX-Wall -Wextra -Wpedantic -WerrorThe 32-bit builds were not run locally:
g++-multilibis 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