]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/update-references.sh
Auto merge of #78448 - rylev:cache-foreign_modules, r=wesleywiser
[rust.git] / src / tools / clippy / tests / ui / update-references.sh
1 #!/bin/bash
2
3 # A script to update the references for particular tests. The idea is
4 # that you do a run, which will generate files in the build directory
5 # containing the (normalized) actual output of the compiler. This
6 # script will then copy that output and replace the "expected output"
7 # files. You can then commit the changes.
8 #
9 # If you find yourself manually editing a `foo.stderr` file, you're
10 # doing it wrong.
11
12 if [[ "$1" == "--help" || "$1" == "-h" || "$1" == "" || "$2" == "" ]]; then
13     echo "usage: $0 <build-directory> <relative-path-to-rs-files>"
14     echo ""
15     echo "For example:"
16     echo "   $0 ../../../build/x86_64-apple-darwin/test/ui *.rs */*.rs"
17 fi
18
19 MYDIR=$(dirname "$0")
20
21 BUILD_DIR="$1"
22 shift
23
24 while [[ "$1" != "" ]]; do
25     STDERR_NAME="${1/%.rs/.stderr}"
26     STDOUT_NAME="${1/%.rs/.stdout}"
27     FIXED_NAME="${1/%.rs/.fixed}"
28     shift
29     if [[ -f "$BUILD_DIR"/"$STDOUT_NAME" ]] && \
30            ! (cmp -s -- "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"); then
31         echo updating "$MYDIR"/"$STDOUT_NAME"
32         cp "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"
33         if [[ ! -s "$MYDIR"/"$STDOUT_NAME" ]]; then
34             echo removing "$MYDIR"/"$STDOUT_NAME"
35             rm "$MYDIR"/"$STDOUT_NAME"
36         fi
37     fi
38     if [[ -f "$BUILD_DIR"/"$STDERR_NAME" ]] && \
39            ! (cmp -s -- "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"); then
40         echo updating "$MYDIR"/"$STDERR_NAME"
41         cp "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"
42         if [[ ! -s "$MYDIR"/"$STDERR_NAME" ]]; then
43             echo removing "$MYDIR"/"$STDERR_NAME"
44             rm "$MYDIR"/"$STDERR_NAME"
45         fi
46     fi
47     if [[ -f "$BUILD_DIR"/"$FIXED_NAME" ]] && \
48            ! (cmp -s -- "$BUILD_DIR"/"$FIXED_NAME" "$MYDIR"/"$FIXED_NAME"); then
49         echo updating "$MYDIR"/"$FIXED_NAME"
50         cp "$BUILD_DIR"/"$FIXED_NAME" "$MYDIR"/"$FIXED_NAME"
51         if [[ ! -s "$MYDIR"/"$FIXED_NAME" ]]; then
52             echo removing "$MYDIR"/"$FIXED_NAME"
53             rm "$MYDIR"/"$FIXED_NAME"
54         fi
55     fi
56 done