local.enhance-test-script.patch 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. Description: Enhance the test script
  2. Author: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
  3. Forwarded: No
  4. Last-Update: 2014-07-22
  5. Handle alternate paths for the test data, handle alternate
  6. compressions.
  7. --- a/test.sh
  8. +++ b/test.sh
  9. @@ -2,14 +2,45 @@
  10. FAILURES=0
  11. -mkdir -p test_out
  12. +DIR="${1:-.}"
  13. +BGPDUMP="${2:-./bgpdump}"
  14. +
  15. +if [ ! -d "$DIR" ] ; then
  16. + echo "Not a directory: $DIR"
  17. + exit 2
  18. +fi
  19. +
  20. +if [ -x "$(which gzcat)" ] ; then
  21. + ZCAT=gzcat
  22. +elif [ -x "$(which zcat)" ] ; then
  23. + ZCAT=zcat
  24. +else
  25. + echo "Have neither zcat or gzcat"
  26. + exit 2
  27. +fi
  28. +
  29. +mkdir -p "$DIR/test_out"
  30. echo "Running Regression Tests..."
  31. -for mrt in `ls test_data`; do
  32. - /bin/echo -n " testing $mrt..."
  33. - OUT=$mrt.bgp.gz
  34. - ./bgpdump -vm test_data/$mrt > test_out/$OUT
  35. - gzip -cd test_expect/$OUT | diff -q test_out/$OUT -
  36. +for mrt in $(find "$DIR/test_data/" -maxdepth 1 -type f -printf '%f\n' | grep -E '\.(gz|bz2|xz)' | sort) ; do
  37. + echo -n " testing $mrt..."
  38. + OUT=$mrt.bgp
  39. + "$BGPDUMP" -vm "$DIR/test_data/$mrt" > "$DIR/test_out/$OUT"
  40. + if [ -f "$DIR/test_expect/$OUT.gz" ] ; then
  41. + EXT=gz
  42. + CAT="$ZCAT"
  43. + elif [ -f "$DIR/test_expect/$OUT.bz2" ] ; then
  44. + EXT=bz2
  45. + CAT='bzcat'
  46. + elif [ -f "$DIR/test_expect/$OUT.xz" ] ; then
  47. + EXT=xz
  48. + CAT='xzcat'
  49. + else
  50. + echo "Have no expect data"
  51. + exit 2
  52. + fi
  53. +
  54. + "$CAT" "$DIR/test_expect/$OUT.$EXT" | diff -q "$DIR/test_out/$OUT" -
  55. if [ $? = 0 ]; then
  56. echo "success"
  57. else
  58. @@ -18,14 +49,14 @@
  59. done
  60. if [ ! -z "$BGPDUMP_TEST_UATTR" ] ; then
  61. -for mrt in $(ls test_data) ; do
  62. +for mrt in $(find "$DIR/test_data/" -maxdepth 1 -type f -printf '%f\n' | grep -E '\.(gz|bz2|xz)' | sort) ; do
  63. printf " testing -u %s..." "$mrt"
  64. OUT="$mrt.bgp.gz"
  65. # The pipe into sed removes the last field added by -u on table dump
  66. # and announcement (update files) lines, and allows us to chekc
  67. # everything else is the same without adding new test_expect files
  68. # to the repository.
  69. - ./bgpdump -u -vm test_data/$mrt | sed '/|A\|B|/ s/|[^|]*|$/|/' > test_out/$OUT
  70. + "$BGPDUMP" -u -vm test_data/$mrt | sed '/|A\|B|/ s/|[^|]*|$/|/' > test_out/$OUT
  71. gzip -cd test_expect/$OUT | diff -q test_out/$OUT -
  72. if [ $? = 0 ]; then
  73. echo "success"