Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidy: add unit tests for alphabetical checks #117149

Merged
merged 4 commits into from
Oct 28, 2023

Commits on Oct 24, 2023

  1. Fix a bug in tidy's alphabetical checking.

    Currently, if a `tidy-alphabetical-end` marker appears on the last line
    of a file, tidy will erroneously issue a "reach end of file expecting
    `tidy-alphabetical-end`" error. This is because it uses `take_while`
    within `check_section`, which consumes the line with the end marker, and
    then after `check_section` returns `check` peeks for at least one more
    line, which won't be there is the marker was on the last line.
    
    This commit fixes the problem, by removing the use of `take_while`, and
    doing the "reached end of file" test within `check_section` without
    using `peek`.
    
    It also renames `{START,END}_COMMENT` as `{START,END}_MARKER`, which is
    a more appropriate name.
    nnethercote committed Oct 24, 2023
    Configuration menu
    Copy the full SHA
    b7bea6e View commit details
    Browse the repository at this point in the history
  2. tidy: skip lines starting with # in alphabetical check.

    These are comment lines in `Cargo.toml` files.
    
    But exclude lines starting with `#!` from the skipping, because we want
    to check them. (Rust `#![feature(...)]` lines.)
    
    Also allow empty lines, which are occasionally useful.
    nnethercote committed Oct 24, 2023
    Configuration menu
    Copy the full SHA
    40797ee View commit details
    Browse the repository at this point in the history
  3. tidy: some minor improvements.

    - Tweak some comments.
    - No need to do the `concat!` trick on `START_MARKER` because it's
      immediately followed by `END_MARKER`.
    - Fix an off-by-one error in the line number for an error message.
    - When a second start marker is found without an intervening end marker,
      after giving an error, treat it as though it ends the section. It's
      hard to know exactly what to do in this case, but it makes unit
      testing this case a little simpler (in the next commit).
    - If an end marker occurs without a preceding start marker, issue an
      error.
    nnethercote committed Oct 24, 2023
    Configuration menu
    Copy the full SHA
    a79a2c7 View commit details
    Browse the repository at this point in the history
  4. tidy: add unit tests for alphabetical markers.

    This requires introducing `tidy_error_ext!` as an alternative to
    `tidy_error!`. It is passed a closure that is called for an error. This
    lets tests capture tidy error messages in a buffer instead of printing
    them to stderr.
    
    It also requires pulling part of `check` out into a new function
    `check_lines`, so that tests can pass in an iterator over some strings
    instead of a file.
    nnethercote committed Oct 24, 2023
    Configuration menu
    Copy the full SHA
    a0b0ace View commit details
    Browse the repository at this point in the history