1
0

test-ref 3.5 KB

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