Repository navigation
test: merge the copied section tests and count reads in place of timing the C++ lexer - #260
Merged
Merged
Conversation
tests/rust_section.rs, toml_section.rs and cpp_section.rs held the same tests with the data changed, 45 in all. tests/sections.rs lists the sections in one table, with every expected message written out in its row, and has one test over the table for each rule the three shared. A rule only one language has stays its own test: TOML has no doc comment surface, the fix of TOML leaves a string alone and the TOML section reads only files ending in .toml, and C++ reads eight extensions. A test over a table passes when a row is missing, so one test checks that the table has a row for each section the config schema names except md. Two fewer test binaries: building the three took 5.4 s of CPU, and building one takes 2.0 s. Running them takes about the same. Nothing is dropped but copies. The rust and cpp tests that no two sections select one file are covered by the toml copy, which writes a file for all three sections. The md glob test, which was in the rust file only, is kept once.
Each lint puts the config message into its own report, so each keeps its custom_message case; those stay. These three checked the same thing a second time: - tests/unit.rs a_config_message_replaces_the_advice used the config and file of tests/cases/max_size_bytes/custom_message. That case's .stderr holds the whole report, so it also pins that the default advice is gone. - the one-possessive half of the report test in src/lint/possessive_own.rs is pinned by tests/cases/possessive_own/custom_message. - the one-negation half of the report test in src/lint/not_at_all.rs is pinned by tests/cases/not_at_all/custom_message. The first half of each report test, the count, the places and the default advice, stays.
sentence_lengths_by_label is ignored, checks nothing and only prints tables for issue 33, which is closed. It goes with the helpers only it used: the length and spread functions, the table printer and the abbreviation list. It pins nothing, so no test survives it. every_category_is_well_stocked stays: it is the floor that keeps the ratio tests from passing on an empty category.
- instructions.rs update_md_meets_its_budget read the budget of src/instructions/update.md from .agents/deslag.toml and ran the lints on the file. make check-deslag runs deslag on this repo with that config, so it holds update.md to the same budget and the same lints, as it holds every file. - allow.rs the_acknowledgements_credit_the_two_designs_the_entry_takes searched ACKNOWLEDGEMENTS.md for words. It pinned no behavior. Its helper goes with it. The other tests that read a file of this repo stay: each one has that file as its subject, so a fixture would test nothing.
The linear-time test for directives that open a raw string read the clock and failed above two seconds, which depends on the machine and its load. In a test build the scanner now counts the bytes it reads, in at and in the slice search of raw_string that does not go through at, and the test bounds the count at 32 times the source length. The limit is argued in a comment from the code and not found by running it. A scan that reads the rest of the file again for each directive reads on the order of the source length for every line, far over the bound. The sources are 10,000 lines instead of 100,000, since the count does not need a large input to tell linear from quadratic. A second test of 10,000 plain directives is added. In the first source one raw string swallows the file, so the scan meets one directive; the second meets 10,000. This was the one read of the clock in src and tests.
- frozen.rs the_hash_is_fnv_1a_64 tested the hash helper. Any change to frozen::hash fails no_frozen_config_is_edited_and_each_has_a_line_in_hashes, which compares it with the hashes in the repo. - instructions.rs lints_turned_on_reads_every_section tested a helper. If lints_turned_on breaks, the checks that compare a config's lints with the lints there are fail: the heading check and the one that compares the whole config's lints with lint_names. - the Tag::ALL.len() == 13 assertion in src/tag/types.rs. The type of the array, [Tag; 13], already says it. The test that every schema property has a since in since.rs stays. It keeps the check for every property from passing on an empty list.
The read counter counted `at` and the `)` search of `raw_string`, but code that sliced `self.bytes` directly was not counted. A rescan of the rest of the file in `directive`, written that way, passed both linear-time tests. `Scanner` now holds a `Reader` in its own module. The bytes are private to it, and every read goes through `at`, `byte`, `slice`, `has_at` or `find`, which count what they hand out in a test build and do nothing more otherwise. The compiler now refuses a read that skips the counter. The bound of 32 reads for each byte is unchanged. Its comment now counts the one extra read of the bytes that were indexed before.
`#[rustfmt::skip]` on `Row` and `ROWS` kept `tests/sections.rs` at 600 lines by leaving 38 lines over 100 columns, the longest 241. The 600 lines were a size guide. The rows are easier to read formatted, so the file is now what rustfmt leaves, 704 lines.
Three tests took `ROWS[1]` or `ROWS[2]`, so reordering the table would
have swapped the language they test. They now ask `row("toml")` or
`row("cpp")`, which panics if the table has no such row.
…chema The merged schema test checked only `surfaces = ["comment"]` and `density`. The tests it replaced also fitted both surfaces, a table of `banned_chars` groups and an override. Each row now has that config checked by `toml_misfit` too, with `doc_comment` left out for `toml`, which has none.
Owner
Author
|
CI is green on fb6a51b (runs 41503536723, 41503536771 and 41503537461). This PR is stacked on #257 (stack 261) and shows only its own diff until #257 merges. Decided on the maintainer's behalf: the repo-state tests stay, apart from two. The plan had moved them out; this PR keeps every test whose subject is the repo file it reads, on the 2026-10-24 tier decisions and #215, and deletes only the |
6 tasks done
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.
This builds on #257 and shows only its own diff until #257 merges. This PR resolves neither the golden-file question nor the library-oracle corpus tests.
AI Summary
Three test files were copies of one another, one test measured elapsed time, and a few tests checked things that something else already breaks on. This removes the copies and puts a counter where the clock was. No
.stderr,.json, golden or corpus file changes, and no case is deleted.The section tests are one table
tests/rust_section.rs,tests/toml_section.rsandtests/cpp_section.rs(45 tests, each file a copy of the others with the language changed) are nowtests/sections.rs: one written-out table,ROWS, with a row per code section, and one test over it per rule. A rule only one language has is its own test: TOML refusesdoc_comment, C++ reads eight extensions, TOML's fix leaves a string and keeps CRLF.the_md_section_keeps_any_globis kept once.A test that loops over the list it pins passes when an entry goes (#197, #240). So
the_table_has_a_row_for_each_code_sectioncompares the table's names with the sections the config schema names, minusmd, in both directions. Each row's expected messages are written out, never formatted from the name. A test picks its row by name (row("cpp")), so reordering the table cannot swap languages.Tests and assertions deleted, and what still pins each
a_config_message_replaces_the_advice(tests/unit.rs): the casetests/cases/max_size_bytes/custom_message, whose.stderris the whole report and so shows the advice gone.the_report_names_the_count_the_places_and_the_advice(possessive_own.rs) and the one-negation half of the same-named test innot_at_all.rs: the casespossessive_own/custom_messageandnot_at_all/custom_message.sentence_lengths_by_labeland its helpers (tests/slow/corpus.rs): an ignored test that printed a spread and checked nothing.every_category_is_well_stockedstays.update_md_meets_its_budget(tests/instructions.rs):make check-deslagholdssrc/instructions/update.mdto the same budget, as it holds every file.the_acknowledgements_credit_the_two_designs_the_entry_takes(tests/allow.rs): it grepped the wording ofACKNOWLEDGEMENTS.mdand checked no behaviour. Nothing pins it now.the_hash_is_fnv_1a_64(tests/frozen.rs):no_frozen_config_is_edited_and_each_has_a_line_in_hashesfails on any change tofrozen::hash.lints_turned_on_reads_every_section(tests/instructions.rs):each_lint_section_turns_on_its_lint_aloneandthe_lints_tables_together_are_valid. This was the only test that used a non-mdsection. The survivors catch an empty set, ignored overrides and ignored section-level lints, but not a reader that looks only atmd.assert_eq!(Tag::ALL.len(), 13)(src/tag/types.rs, an assertion): the type[Tag; 13]says it.Kept on purpose: the ten
custom_messagecases and their.jsonfiles (each lint substitutes its own placeholders in its own code),tests/emphasis.rs,tests/since.rs,stamp.rs,phrases.rs, the guide and README tests ininstructions.rs,src/lint/mod.rsand the 88 tests insrc/config/edit/.The C++ lexer's clock is a read counter
One test in
src/document/cpp.rstimed the lexer withInstant, so it could fail on a slow machine and prove nothing on a fast one. It now counts reads.Scannerholds aReaderin its own module, whose bytes are private. Every read goes throughat,byte,slice,has_atorfind, which count what they hand out in a test build and do nothing more otherwise. The compiler refuses code that reads the source without the counter, so a rescan written as a direct slice scan cannot hide.The bound is 32 reads per byte, argued from the code in the comment on
MOST_READS_PER_BYTE, not found by running it. A lexeme start makes at most 11 reads and steps over a byte; each loop in a lexeme makes at most 2 reads per byte; a blank after a backslash costs at most 6 more; a<with no>costs 2 more. That is under 21. In a raw string,findcounts each byte once and the check after each)reads the delimiter (at most 16 bytes) and the quote, so under 18. A rescan of the file per directive reads the source length per line, far over any such constant. Two tests feed it: 10,000#define X R"(alines and 10,000#define X 1lines. The first has one directive in effect (the first raw string swallows the file), so the second is the one that sees a per-directive rescan.Before and after
The saving is two fewer test binaries to link, not a faster run. CPU per binary is within noise on a loaded machine.
Decided on the maintainer's behalf
custom_messagecases stay, and the three copies of them go. Why: each lint substitutes its own placeholders in its own code, so each case pins other code; the three deleted checks pinned only what a case already shows.sentence_lengths_by_labelgoes andevery_category_is_well_stockedstays. Why: the first prints and checks nothing; the second keeps the ratio tests from passing on an empty category, and the corpus loads once, so it saves no CPU.update_md_meets_its_budgetis held bymake check-deslagand the acknowledgements test checked wording only.src/config/edit/tests stay. Why: each refusal pins thatdeslag updatenever writes a config it cannot edit safely.tests/sections.rsis lifted:#[rustfmt::skip]kept it at 600 lines by leaving 38 lines over 100 columns, the longest 241. The table is formatted by rustfmt and the file is 723 lines. Why: unreadable rows are worse than a longer file.Tests
Each mutation was made in a scratch copy and not committed.
cpprow dropped:the_table_has_a_row_for_each_code_sectionfails, left["rust","toml"], right["cpp","rust","toml"].src/config/mod.rs:a_file_that_two_sections_select_is_an_error_that_names_bothfails and names the row.max_size_bytes.rsand thenpossessive_own.rsstop replacing{path}:tests/cases.rsfails on eachcustom_messagecase.directivereads the rest of the file again throughat:many_plain_directives_are_read_in_linear_timefails at 600,570,002 reads of 120,000 bytes, while the raw-string test passes.directivescans the rest of the file with a direct slice,self.bytes[after_hash..], counting newlines. This passed both tests before theReader. It no longer compiles, because the bytes are private. The same scan through the reader'sslicefailsmany_plain_directives_are_read_in_linear_timeat 600,590,005 reads of 120,000 bytes.frozen::hashwith another multiplier:no_frozen_config_is_edited_and_each_has_a_line_in_hashesfails.lints_turned_onreturns an empty set:each_lint_section_turns_on_its_lint_aloneandthe_lints_tables_together_are_validfail.update.mdgrown past its budget:make check-deslagexits 2 with "src/instructions/update.md is 1884, which is larger than 1585 bytes".The schema-fit test checks, for every row,
surfaces = ["doc_comment", "comment"](["comment"]fortoml), abanned_charsgroups table and an override, as the three replaced tests did, and an unknown surface is refused.Testing
make ci-fast: exit 0make test: exit 0make test-tools: exit 0make check-deslag: exit 0make check-fmt: exit 0References