xref: /aosp_15_r20/external/bazelbuild-rules_license/tools/diff_test.sh (revision f578df4fd057ffe2023728444759535685631548)
1#!/bin/bash
2# Copyright 2020 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# https://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16# Diff two files and PASS if they are equal, FAIL otherwise.
17# Usage:
18#   diff_test.sh path_to_expected path_to_got
19
20# Find input files
21declare -r EXPECTED="$1"
22declare -r GOT="$2"
23
24diff_out=$(mktemp /tmp/diff_test.XXXXXXXXX)
25diff -cB "$EXPECTED" "$GOT" >"$diff_out"
26err=0
27if [[ -s "$diff_out" ]] ; then
28  cat "$diff_out"
29  err=1
30  echo 'To update:'
31  echo '  cp bazel-bin/'"$GOT" "$EXPECTED"
32  echo FAIL
33else
34  echo PASS
35fi
36exit $err
37