| 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright 2026 The Fuchsia Authors |
| 4 | # |
| 5 | # Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 |
| 6 | # <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT |
| 7 | # license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. |
| 8 | # This file may not be copied, modified, or distributed except according to |
| 9 | # those terms. |
| 10 | |
| 11 | set -eo pipefail |
| 12 | |
| 13 | # Directories to search |
| 14 | DIRS=("tests" "zerocopy-derive/tests") |
| 15 | |
| 16 | EXIT_CODE=0 |
| 17 | |
| 18 | for dir in "${DIRS[@]}"; do |
| 19 | if [ ! -d "$dir" ]; then |
| 20 | echo "Warning: Directory $dir does not exist, skipping." >&2 |
| 21 | continue |
| 22 | fi |
| 23 | |
| 24 | # Find all .stderr files |
| 25 | while IFS= read -r -d '' stderr_file; do |
| 26 | # Construct the corresponding .rs file path |
| 27 | rs_file="${stderr_file%.stderr}.rs" |
| 28 | |
| 29 | # Check if the .rs file exists. The `-e` flag checks if file exists: |
| 30 | # It returns true for regular files and valid symlinks, and false for |
| 31 | # broken symlinks or missing files. |
| 32 | if [ ! -e "$rs_file" ]; then |
| 33 | echo "Error: Orphaned stderr file found: $stderr_file" >&2 |
| 34 | echo " Missing regular file or valid symlink: $rs_file" >&2 |
| 35 | EXIT_CODE=1 |
| 36 | fi |
| 37 | done < <(find "$dir" -name "*.stderr" -print0) |
| 38 | done |
| 39 | |
| 40 | if [ "$EXIT_CODE" -eq 1 ]; then |
| 41 | echo "Found stale .stderr files. Please delete them." >&2 |
| 42 | fi |
| 43 | |
| 44 | exit "$EXIT_CODE" |