/tests/plugin_test/test.sh

https://github.com/phan/phan · Shell · 55 lines · 42 code · 7 blank · 6 comment · 8 complexity · 71cf1f7371786dad2b595dce33102660 MD5 · raw file

  1. #!/usr/bin/env bash
  2. EXPECTED_PATH=expected/all_output.expected
  3. ACTUAL_PATH=all_output.actual
  4. if [ ! -d expected ]; then
  5. echo "Error: must run this script from tests/plugin_test folder" 1>&2
  6. exit 1
  7. fi
  8. echo "Generating test cases"
  9. for path in $(echo expected/*.php*.expected | LC_ALL=C sort); do cat $path; done > $EXPECTED_PATH
  10. if [[ $? != 0 ]]; then
  11. echo "Failed to concatenate test cases" 1>&2
  12. exit 1
  13. fi
  14. echo "Running phan in '$PWD' ..."
  15. rm $ACTUAL_PATH -f || exit 1
  16. # We use the polyfill parser because it behaves consistently in all php versions.
  17. ../../phan --force-polyfill-parser --memory-limit 1G | tee $ACTUAL_PATH
  18. sed -i -e 's,\<closure_[0-9a-f]\{12\}\>,closure_%s,g' \
  19. -e "s,[^\\']*plugin_test[/\\\\],,g" \
  20. -e 's,\(PhanTypeErrorInInternalCall.*\)integer given,\1int given,g' \
  21. $ACTUAL_PATH $EXPECTED_PATH
  22. sed -i 's,missing closing parenthesis,missing ),g' $ACTUAL_PATH
  23. # diff returns a non-zero exit code if files differ or are missing
  24. # This outputs the difference between actual and expected output.
  25. echo
  26. echo "Comparing the output:"
  27. # Normalize PHP_VERSION_ID
  28. # and remove/replace php 8.0 warnings
  29. sed -i -e 's/^\(src.020_bool.php.*of type\) [0-9]\+ \(evaluated\)/\1 int \2/g' \
  30. -e 's@src/157_polyfill_compilation_warning.php:3 PhanNativePHPSyntaxCheckPlugin Saw error or notice for php --syntax-check: "Parse error: Unterminated comment starting line 3"@src/157_polyfill_compilation_warning.php:3 PhanSyntaxCompileWarning Saw a warning while parsing: Unterminated comment starting line 3@g' \
  31. -e '/__autoload() is no longer supported, use spl_autoload_register/d' \
  32. -e 's/PhanTypeMismatchArgumentInternalReal/PhanTypeMismatchArgumentInternalProbablyReal/g' \
  33. -e 's/string \$haystack, int|string \$needle, int \$offset = 0/string \$haystack, int|string \$needle, int \$offset = unknown/g' \
  34. -e 's/\\\(Exception\|Error\)|\\Stringable|\\Throwable/\\\1|\\Throwable/g' \
  35. -e 's/strlen(): Argument #1 (\$string) must be of type string/strlen() expects parameter 1 to be string/g' \
  36. $ACTUAL_PATH
  37. if type colordiff >/dev/null; then
  38. DIFF=colordiff
  39. else
  40. DIFF=diff
  41. fi
  42. $DIFF $EXPECTED_PATH $ACTUAL_PATH
  43. EXIT_CODE=$?
  44. if [ "$EXIT_CODE" == 0 ]; then
  45. echo "Files $EXPECTED_PATH and output $ACTUAL_PATH are identical"
  46. rm $ACTUAL_PATH
  47. fi
  48. exit $EXIT_CODE