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