test-ref 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. set -eo pipefail
  3. # Check $TESTS_DIR is given
  4. if [[ -z "$TESTS_DIR" ]]; then
  5. echo "Must provide \$TESTS_DIR env variable"
  6. exit 1
  7. fi
  8. # Check $INVOCATION_ID is given: we use it as cache key to be sure compiled tester-lcmp is actual (see file $TESTS_DIR/tester-lcmp/tester-lcmp.$INVOCATION_ID)
  9. if [[ -z "$INVOCATION_ID" ]]; then
  10. echo "Must provide \$INVOCATION_ID env variable"
  11. exit 1
  12. fi
  13. mkdir -p "$TESTS_DIR"/tester-lcmp
  14. # If compiled tester-lcmp is not actual
  15. if [ ! -f "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" ]; then
  16. # Clear
  17. rm -f "$TESTS_DIR"/tester-lcmp/*
  18. # Compile it
  19. CPP_INCLUDE_DIR_=$CPP_INCLUDE_DIR
  20. export CPP_INCLUDE_DIR=$TESTS_DIR/lib
  21. bash "$TESTS_DIR"/scripts/compile "$TESTS_DIR"/src/tester-lcmp.cpp
  22. export CPP_INCLUDE_DIR=$CPP_INCLUDE_DIR_
  23. # Move from current dir to /tester-lcmp
  24. if [ ! -d ./tester-lcmp ]; then
  25. mv -f ./tester-lcmp "$TESTS_DIR"/tester-lcmp
  26. else
  27. mv -f ./tester-lcmp.exe "$TESTS_DIR"/tester-lcmp
  28. fi
  29. # Create file to inform that it was compiled to this $INVOCATION_ID
  30. touch "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID"
  31. fi
  32. # First argument as a subdirectory in ./refs
  33. ref_dir=$1
  34. if [[ -z "$ref_dir" ]]; then
  35. echo "Must provide \$1 for test-ref"
  36. exit 1
  37. fi
  38. refs=refs/$1
  39. shift 1
  40. # Check if we don't have invocation reference files
  41. if [ ! -d "$refs" ]; then
  42. if [[ "$TEST_REF_FORBID_GEN_REFS" == "true" ]]; then
  43. echo "You forgot to run push ref files for invocation: "$*""
  44. echo "Run test locally, it will produce ref files and push it into the repo"
  45. exit 1
  46. fi
  47. # Create them
  48. mkdir -p "$refs"
  49. echo Generating tester refs: "$*"
  50. exit_code=0
  51. # shellcheck disable=SC2048
  52. $* 1>"$refs"/stdout 2>"$refs"/stderr || exit_code=$?
  53. echo $exit_code >"$refs"/exit_code
  54. echo "[SUCCESS] generated execution reference files (exit code: $exit_code)"
  55. else
  56. # Do invocation
  57. echo Testing refs: "$*"
  58. exit_code=0
  59. # shellcheck disable=SC2048
  60. $* 1>"$refs"/stdout.aux 2>"$refs"/stderr.aux || exit_code=$?
  61. echo $exit_code >"$refs"/exit_code.aux
  62. # Check exit code is the same
  63. tester_lcmp_exit_code=0
  64. "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/exit_code.aux "$refs"/exit_code 2>tester-lcmp.out || tester_lcmp_exit_code=$?
  65. if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
  66. echo "[FAILED] exit_code mismatched"
  67. cat tester-lcmp.out
  68. rm -f tester-lcmp.out
  69. rm -f "$refs"/*.aux
  70. exit 1
  71. fi
  72. echo $exit_code >"$refs"/exit_code.aux
  73. # Check stdout is the same
  74. "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/stdout.aux "$refs"/stdout 2>tester-lcmp.out || tester_lcmp_exit_code=$?
  75. if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
  76. echo "[FAILED] stdout mismatched"
  77. cat tester-lcmp.out
  78. rm -f tester-lcmp.out
  79. rm -f "$refs"/*.aux
  80. exit 1
  81. fi
  82. # Check stderr is the same
  83. "$TESTS_DIR"/tester-lcmp/tester-lcmp "$TESTS_DIR"/tester-lcmp/tester-lcmp."$INVOCATION_ID" "$refs"/stderr.aux "$refs"/stderr 2>tester-lcmp.out || tester_lcmp_exit_code=$?
  84. if [[ ! "$tester_lcmp_exit_code" == "0" ]]; then
  85. echo "[FAILED] stderr mismatched"
  86. cat tester-lcmp.out
  87. rm -f tester-lcmp.out
  88. rm -f "$refs"/*.aux
  89. exit 1
  90. fi
  91. # Invocation is the same!
  92. echo "[SUCCESS] execution matched with reference (exit code: $exit_code)"
  93. rm -f tester-lcmp.out
  94. rm -f "$refs"/*.aux
  95. fi