Skip to content

Commit

Permalink
Auto merge of #6158 - giraffate:improve_updating_references, r=phansch
Browse files Browse the repository at this point in the history
Remove the generated files by `update-references.sh` if they are empty

An empty file may be generated by `update-references.sh` and committed as is when creating a patch like #6101 (comment) and #6079 (review). So, I think it would be helpful to add documentation, and automatically remove the generated file if it's empty.

changelog: none
  • Loading branch information
bors committed Oct 12, 2020
2 parents 92783e3 + 377d1fa commit 18ffea0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion doc/adding_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ every time before running `tests/ui/update-all-references.sh`.
Running `TESTNAME=foo_functions cargo uitest` should pass then. When we commit
our lint, we need to commit the generated `.stderr` files, too. In general, you
should only commit files changed by `tests/ui/update-all-references.sh` for the
specific lint you are creating/editing.
specific lint you are creating/editing. Note that if the generated files are
empty, they should be removed.

### Cargo lints

Expand Down
8 changes: 8 additions & 0 deletions tests/ui-cargo/update-references.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ while [[ "$1" != "" ]]; do
! (cmp -s -- "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"); then
echo updating "$MYDIR"/"$STDOUT_NAME"
cp "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"
if [[ ! -s "$MYDIR"/"$STDOUT_NAME" ]]; then
echo removing "$MYDIR"/"$STDOUT_NAME"
rm "$MYDIR"/"$STDOUT_NAME"
fi
fi
if [[ -f "$BUILD_DIR"/"$STDERR_NAME" ]] && \
! (cmp -s -- "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"); then
echo updating "$MYDIR"/"$STDERR_NAME"
cp "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"
if [[ ! -s "$MYDIR"/"$STDERR_NAME" ]]; then
echo removing "$MYDIR"/"$STDERR_NAME"
rm "$MYDIR"/"$STDERR_NAME"
fi
fi
done
8 changes: 8 additions & 0 deletions tests/ui-toml/update-references.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ while [[ "$1" != "" ]]; do
! (cmp -s -- "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"); then
echo updating "$MYDIR"/"$STDOUT_NAME"
cp "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"
if [[ ! -s "$MYDIR"/"$STDOUT_NAME" ]]; then
echo removing "$MYDIR"/"$STDOUT_NAME"
rm "$MYDIR"/"$STDOUT_NAME"
fi
fi
if [[ -f "$BUILD_DIR"/"$STDERR_NAME" ]] && \
! (cmp -s -- "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"); then
echo updating "$MYDIR"/"$STDERR_NAME"
cp "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"
if [[ ! -s "$MYDIR"/"$STDERR_NAME" ]]; then
echo removing "$MYDIR"/"$STDERR_NAME"
rm "$MYDIR"/"$STDERR_NAME"
fi
fi
done
12 changes: 12 additions & 0 deletions tests/ui/update-references.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,27 @@ while [[ "$1" != "" ]]; do
! (cmp -s -- "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"); then
echo updating "$MYDIR"/"$STDOUT_NAME"
cp "$BUILD_DIR"/"$STDOUT_NAME" "$MYDIR"/"$STDOUT_NAME"
if [[ ! -s "$MYDIR"/"$STDOUT_NAME" ]]; then
echo removing "$MYDIR"/"$STDOUT_NAME"
rm "$MYDIR"/"$STDOUT_NAME"
fi
fi
if [[ -f "$BUILD_DIR"/"$STDERR_NAME" ]] && \
! (cmp -s -- "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"); then
echo updating "$MYDIR"/"$STDERR_NAME"
cp "$BUILD_DIR"/"$STDERR_NAME" "$MYDIR"/"$STDERR_NAME"
if [[ ! -s "$MYDIR"/"$STDERR_NAME" ]]; then
echo removing "$MYDIR"/"$STDERR_NAME"
rm "$MYDIR"/"$STDERR_NAME"
fi
fi
if [[ -f "$BUILD_DIR"/"$FIXED_NAME" ]] && \
! (cmp -s -- "$BUILD_DIR"/"$FIXED_NAME" "$MYDIR"/"$FIXED_NAME"); then
echo updating "$MYDIR"/"$FIXED_NAME"
cp "$BUILD_DIR"/"$FIXED_NAME" "$MYDIR"/"$FIXED_NAME"
if [[ ! -s "$MYDIR"/"$FIXED_NAME" ]]; then
echo removing "$MYDIR"/"$FIXED_NAME"
rm "$MYDIR"/"$FIXED_NAME"
fi
fi
done

0 comments on commit 18ffea0

Please sign in to comment.