golden_test.sh 652 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/bin/bash
  2. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  3. # Exceptions. See /LICENSE for license information.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. set -e -u -o pipefail
  6. GOLDEN=$1
  7. SUBJECT=$2
  8. if [[ $# == 3 && $3 == "--update" ]]; then
  9. cp "${SUBJECT}" "${GOLDEN}"
  10. exit $?
  11. fi
  12. CMD=("diff" "-u" "${GOLDEN}" "${SUBJECT}")
  13. if "${CMD[@]}"; then
  14. echo "PASS"
  15. exit 0
  16. fi
  17. cat <<EOT
  18. When running under:
  19. ${TEST_SRCDIR}
  20. the golden contents of:
  21. ${GOLDEN}
  22. do not match generated target:
  23. ${SUBJECT}
  24. To update the golden file, run the following:
  25. bazel run ${TEST_TARGET} -- --update
  26. EOT
  27. exit 1