test: minor fixes & improvements for files linter test #21873

pull windsok wants to merge 1 commits into bitcoin:master from windsok:files-lint-fixups changing 1 files +12 −16
  1. windsok commented at 1:31 AM on May 7, 2021: contributor

    Couple of minor fixes & improvements for files linter test added in #21740

    • Use a context manager when opening files, so that files are closed are we are done with them

    • Use the -z flag when shelling out to git ls-files so that we can catch newlines and other weird control characters in filenames.

    From the git ls-files manpage:

    -z \0 line termination on output and do not quote filenames. See OUTPUT below for more information.
    
    Without the -z option, pathnames with "unusual" characters are quoted as explained for the configuration variable
    core.quotePath (see git-config(1)). Using -z the filename is output verbatim and the line is terminated by a NUL byte.
    
  2. test: minor fixes & improvements for files linter test
    Updates the lint-files.py lint test:
    * Use a context manager when opening files, so that files are closed.
    * Use the -z flag when shelling out to git ls-files so that we can catch newlines
      and other weird control characters in filenames
    2227fc4e62
  3. in test/lint/lint-files.py:81 in 2227fc4e62
      81 |      failed_tests = 0
      82 |      for filename in filenames:
      83 |          if not filename_regex.match(filename):
      84 |              print(
      85 | -                f"""File "{filename}" does not not match the allowed filename regexp ('{ALLOWED_FILENAME_REGEXP}')."""
      86 | +                f"""File {repr(filename)} does not not match the allowed filename regexp ('{ALLOWED_FILENAME_REGEXP}')."""
    


    windsok commented at 1:32 AM on May 7, 2021:

    This change is to ensure any unusual characters are printable in the test log. https://stackoverflow.com/a/31624058 https://docs.python.org/3/library/functions.html#repr

  4. fanquake added the label Tests on May 7, 2021
  5. MarcoFalke commented at 5:46 AM on May 7, 2021: member

    cr ACK 2227fc4e6203064b14e99bcf453601bd263a0196

  6. practicalswift commented at 8:20 AM on May 7, 2021: contributor

    cr ACK 2227fc4e6203064b14e99bcf453601bd263a0196: patch looks correct

    Thanks for improving linting @windsok. Keep going!

  7. MarcoFalke merged this on May 7, 2021
  8. MarcoFalke closed this on May 7, 2021

  9. gwillen referenced this in commit 45fdf8809b on Jun 1, 2022
  10. DrahtBot locked this on Aug 16, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 21:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me