refactor: remove redundant inclusion of header files in the fuzz tests #23294

pull stratospher wants to merge 1 commits into bitcoin:master from stratospher:fuzz-remove-redundant-headers changing 93 files +0 −528
  1. stratospher commented at 9:05 PM on October 16, 2021: contributor

    This PR removes redundant inclusion of header files in the fuzz test files. Most of the header files like #include<string>, #include<vector> etc.. are redundant because it’s imports are already included in one of these header files - src/test/fuzz/fuzz.h, src/test/fuzz/util.h and src/test/fuzz/FuzzedDataProvider.h. So they can be removed.

    This bash script was used to delete redundant import occurrences. The text files headers-fuzz.txt, headers-util.txt and headers-FuzzedDataProvider.txt were provided with the header file information which are present in src/test/fuzz/fuzz.h, src/test/fuzz/util.h and src/test/fuzz/FuzzedDataProvider.h respectively.

    #!/bin/bash
    remove-lines() (
      remove_lines="$1"
      all_lines="$2"
      tmp_file="$(mktemp)"
      grep -Fvxf "$remove_lines" "$all_lines" > "$tmp_file"
      mv "$tmp_file" "$all_lines"
    )
    
    for filename in bitcoin/src/test/fuzz/*.cpp; do
        # if FuzzedDataProvider.h is imported
        if grep -q "#include <test/fuzz/FuzzedDataProvider.h>" "$filename"
        then
            remove-lines "headers-FuzzedDataProvider.txt" "$filename"
        fi
        # if fuzz.h is imported
        if grep -q "#include <test/fuzz/fuzz.h>" "$filename"
        then
            remove-lines "headers-fuzz.txt" "$filename"
        fi
        # if util.h is imported
        if grep -q "#include <test/fuzz/util.h>" "$filename"
        then
            remove-lines "headers-util.txt" "$filename"
        fi
        # don't let 2 empty lines occur after deletion
        tempfile=$(cat -s "$filename")
        echo "$tempfile" > "$filename";
    done
    
  2. Remove redundant inclusion of header files in the fuzz tests 47f47c5d72
  3. DrahtBot added the label Refactoring on Oct 16, 2021
  4. practicalswift commented at 7:03 AM on October 17, 2021: contributor

    @stratospher

    The "include-what-you-use" policy is used in Bitcoin Core. See the "Source code organization" section in the developer notes:

    • Every .cpp and .h file should #include every header file it directly uses classes, functions or other definitions from, even if those headers are already included indirectly through other headers.

      • Rationale: Excluding headers because they are already indirectly included results in compilation failures when those indirect dependencies change. Furthermore, it obscures what the real code dependencies are.
  5. stratospher commented at 7:28 AM on October 17, 2021: contributor

    Thanks for clarifying! Closing this PR.

  6. stratospher closed this on Oct 17, 2021

  7. stratospher deleted the branch on Oct 17, 2021
  8. DrahtBot locked this on Oct 30, 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-22 06:14 UTC

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