Repository: bitcoin/bitcoin
File: ci/test/03_test_script.sh (Shell)

Code before:
  cd "${BASE_BUILD_DIR}/src/"
  if ! ( run-clang-tidy-"${TIDY_LLVM_V}" -quiet -load="/tidy-build/libbitcoin-tidy.so" "${MAKEJOBS}" | tee tmp.tidy-out.txt ); then
    grep -C5 "error: " tmp.tidy-out.txt
    echo "^^^ ⚠️ Failure generated from clang-tidy"
    false
  fi

  # TODO: Consider enforcing IWYU across the entire codebase.
  FILES_WITH_FORCED_IWYU="/src/(crypto|index)/.*\\.cpp"
  jq --arg patterns "$FILES_WITH_FORCED_IWYU" 'map(select(.file | test($patterns)))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_errors.json"
  jq --arg patterns "$FILES_WITH_FORCED_IWYU" 'map(select(.file | test($patterns) | not))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_warnings.json"

  cd "${BASE_ROOT_DIR}"

  run_iwyu() {
    mv "${BASE_BUILD_DIR}/$1" "${BASE_BUILD_DIR}/compile_commands.json"
    python3 "/include-what-you-use/iwyu_tool.py" \
             -p "${BASE_BUILD_DIR}" "${MAKEJOBS}" \
             -- -Xiwyu --cxx17ns -Xiwyu --mapping_file="${BASE_ROOT_DIR}/contrib/devtools/iwyu/bitcoin.core.imp" \
             -Xiwyu --max_line_length=160 \
             2>&1 | tee /tmp/iwyu_ci.out
    python3 "/include-what-you-use/fix_includes.py" --nosafe_headers < /tmp/iwyu_ci.out
  }

  run_iwyu "compile_commands_iwyu_errors.json"
  git --no-pager diff --exit-code

  run_iwyu "compile_commands_iwyu_warnings.json"
  git --no-pager diff
fi

if [ "$RUN_FUZZ_TESTS" = "true" ]; then
  # shellcheck disable=SC2086
  LD_LIBRARY_PATH="${DEPENDS_DIR}/${HOST}/lib" \
  "${BASE_BUILD_DIR}/test/fuzz/test_runner.py" \
    ${FUZZ_TESTS_CONFIG} \
    "${MAKEJOBS}" \
    -l DEBUG \
    "${DIR_FUZZ_IN}" \
    --empty_min_time=60
fi


Review comment (bug):
Could check the return code and print something to clarify this is an error, similar to the tidy error above:

```sh
    echo "^^^ ⚠️ Failure generated from clang-tidy"
    false
```

Code after:

if [ "${RUN_TIDY}" = "true" ]; then
  cmake -B /tidy-build -DLLVM_DIR=/usr/lib/llvm-"${TIDY_LLVM_V}"/cmake -DCMAKE_BUILD_TYPE=Release -S "${BASE_ROOT_DIR}"/contrib/devtools/bitcoin-tidy
  cmake --build /tidy-build "$MAKEJOBS"
  cmake --build /tidy-build --target bitcoin-tidy-tests "$MAKEJOBS"

  set -eo pipefail
  # Filter out:
  # * qt qrc and moc generated files
  jq 'map(select(.file | test("src/qt/.*_autogen/.*\\.cpp$") | not))' "${BASE_BUILD_DIR}/compile_commands.json" > tmp.json
  mv tmp.json "${BASE_BUILD_DIR}/compile_commands.json"

  cd "${BASE_BUILD_DIR}/src/"
  if ! ( run-clang-tidy-"${TIDY_LLVM_V}" -quiet -load="/tidy-build/libbitcoin-tidy.so" "${MAKEJOBS}" | tee tmp.tidy-out.txt ); then
    grep -C5 "error: " tmp.tidy-out.txt
    echo "^^^ ⚠️ Failure generated from clang-tidy"
    false
  fi

  # TODO: Consider enforcing IWYU across the entire codebase.
  FILES_WITH_ENFORCED_IWYU="/src/(crypto|index)/.*\\.cpp"
  jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns)))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_errors.json"
  jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns) | not))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_warnings.json"

  cd "${BASE_ROOT_DIR}"

  run_iwyu() {
    mv "${BASE_BUILD_DIR}/$1" "${BASE_BUILD_DIR}/compile_commands.json"
    python3 "/include-what-you-use/iwyu_tool.py" \
             -p "${BASE_BUILD_DIR}" "${MAKEJOBS}" \
             -- -Xiwyu --cxx17ns -Xiwyu --mapping_file="${BASE_ROOT_DIR}/contrib/devtools/iwyu/bitcoin.core.imp" \
             -Xiwyu --max_line_length=160 \
             2>&1 | tee /tmp/iwyu_ci.out
    python3 "/include-what-you-use/fix_includes.py" --nosafe_headers < /tmp/iwyu_ci.out
  }

  run_iwyu "compile_commands_iwyu_errors.json"
  if ! ( git --no-pager diff --exit-code ); then
    echo "^^^ ⚠️ Failure generated from IWYU"
    false
  fi

  run_iwyu "compile_commands_iwyu_warnings.json"
  git --no-pager diff
fi

if [ "$RUN_FUZZ_TESTS" = "true" ]; then
  # shellcheck disable=SC2086
  LD_LIBRARY_PATH="${DEPENDS_DIR}/${HOST}/lib" \
  "${BASE_BUILD_DIR}/test/fuzz/test_runner.py" \
    ${FUZZ_TESTS_CONFIG} \