KLL Compiler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

common.bash 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. # Common functions for running kll unit tests
  3. # Jacob Alexander 2016
  4. PASSED=0
  5. FAILED=0
  6. # Results
  7. result() {
  8. echo "--- Results ---"
  9. echo "${PASSED}/$((PASSED+FAILED))"
  10. if (( FAILED == 0 )); then
  11. return 0
  12. else
  13. return 1
  14. fi
  15. }
  16. # Runs a command, increments test passed/failed
  17. # Args: Command
  18. cmd() {
  19. # Run command
  20. echo "CMD: $@"
  21. $@
  22. local RET=$?
  23. # Check command
  24. if [[ ${RET} -ne 0 ]]; then
  25. ((FAILED++))
  26. else
  27. ((PASSED++))
  28. fi
  29. return ${RET}
  30. }
  31. # Run a command multiple times using an array of values
  32. # Arg #1: Base command
  33. # Arg #2: Static arguments
  34. # Arg #3: Static arguments to call when command fails (debug info)
  35. # Arg #4+: Array of variations to swap into the command
  36. cmds() {
  37. local BASE=${1}
  38. shift
  39. local STATIC=${1}
  40. shift
  41. local FAIL_STATIC=${1}
  42. shift
  43. local VARS=${@} # Rest of arguments
  44. # Base command
  45. echo "BASE CMD: ${BASE} ${STATIC}"
  46. # Iterate over variations
  47. for var in ${VARS[@]}; do
  48. cmd ${BASE} ${STATIC} ${var}
  49. if [[ $? -ne 0 ]]; then
  50. echo "CMD FAILED - RUNNING DEBUG ARGS - ${BASE} ${FAIL_STATIC} ${var}"
  51. ${BASE} ${FAIL_STATIC} ${var}
  52. fi
  53. done
  54. }