/test/sample/run.sh

http://txt2tags.googlecode.com/ · Shell · 84 lines · 63 code · 9 blank · 12 comment · 5 complexity · 1559925416971813b1705a5c1446bbb1 MD5 · raw file

  1. #!/bin/bash
  2. # 2010-08-06 Aurelio Jargas
  3. #
  4. # Quick tests to spot changes in samples.
  5. # NOT integrated into main test suite, you must run it alone.
  6. #
  7. # Just add the new target sample to SVN-ROOT/samples/ and it will be tested.
  8. #
  9. # Tip: regenerate affected samples:
  10. # cd ../../ && for t in TARGETS; do txt2tags -t $t samples/sample.t2t; done
  11. cd $(dirname "$0")
  12. errors=0
  13. svn_root='../..'
  14. txt2tags="$svn_root/txt2tags --no-rc"
  15. samples_path=$svn_root/samples
  16. input=$samples_path/sample.t2t
  17. # This filters removes information that may change between conversions,
  18. # as macro expansions (date)
  19. filter() {
  20. sed '
  21. # remove date from header
  22. s,[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9],DATE,
  23. # lout escapes / with "/" in headers
  24. s,[0-9][0-9]"/"[0-9][0-9]"/"[0-9][0-9][0-9][0-9],DATE,
  25. # avoids macro expansion differences
  26. s/today is [0-9]\{8\}/today is TODAY/
  27. s/which gives: ..-..-..../which gives: TODAY/
  28. # man escapes - with \-
  29. s/which gives: ..\\-..\\-..../which gives: TODAY/
  30. # avoids image/link path changes (2nd for Lout)
  31. s|../../samples/||g
  32. s|.."/".."/"samples"/"||g
  33. # remove version
  34. /generated by/ s/txt2tags [0-9.b]\{1,\} /txt2tags /
  35. # remove cmdline
  36. /cmdline: / s/txt2tags .*/txt2tags/
  37. ' $1
  38. }
  39. for template in $samples_path/sample*
  40. do
  41. output=$(basename "$template")
  42. target=$(basename "$template" | cut -d . -f 2)
  43. test "$target" = 't2t' && continue # ignore sample.t2t
  44. if test $(basename "$template") = 'sample-slides-80x25.art'
  45. then
  46. $txt2tags -t $target -i $input -o $output --slides
  47. else
  48. $txt2tags -t $target -i $input -o $output
  49. fi
  50. diff -u <(filter $template) <(filter $output) > $output.diff
  51. if test -s $output.diff
  52. then
  53. errors=1
  54. echo $target >> tmp
  55. else
  56. rm $output.diff
  57. rm $output
  58. fi
  59. done
  60. if test $errors -eq 0
  61. then
  62. echo
  63. echo "All samples are OK"
  64. else
  65. echo
  66. echo "Found errors here:"
  67. ls -1 sample*
  68. echo
  69. echo "Failed targets:" $(cat tmp)
  70. rm tmp
  71. fi