URI:
       tests.sh - sfeed_tests - sfeed tests and RSS and Atom files
  HTML git clone git://git.codemadness.org/sfeed_tests
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tests.sh (11366B)
       ---
            1 #!/bin/sh
            2 # script for running tests/coverage/etc. Tuned for my system.
            3 
            4 sfeed="${SFEED:-$HOME/p/sfeed/sfeed}"
            5 
            6 program1="${PROGRAM1:-/tmp/sfeed/sfeed}"
            7 program2="${PROGRAM2:-$HOME/p/sfeed/sfeed}"
            8 
            9 # force non-builtin printf, requires support for non-POSIX \x.
           10 alias printf='/bin/printf'
           11 
           12 # fixup: expand to same amount of fields, if fields are added (TABS).
           13 # this is useful if the format changes and fields are added.
           14 fixup() {
           15         awk '
           16         BEGIN { OFS = FS = "\t"; }
           17         {
           18                 for (i = 1; i <= 8; i++) {
           19                         if (i > 1)
           20                                 printf("\t");
           21                         printf("%s", $i);
           22                 }
           23                 printf("\n");
           24         }'
           25 }
           26 
           27 record_sfeed() {
           28         $sfeed < "$1" | fixup > "$2"
           29 }
           30 
           31 # run all tests, record and store all results as expected output.
           32 record() {
           33         count=0
           34         for t in input/*/; do
           35                 for d in "$t"*/; do
           36                         for f in "$d"*; do
           37                                 test -f "$f" || continue
           38 
           39                                 dest="expected/${f#input/}"
           40                                 mkdir -p "$(dirname "$dest")"
           41                                 record_sfeed "$f" "$dest"
           42                                 count=$((count+1))
           43                         done
           44                 done
           45         done
           46         echo "$count results recorded."
           47 }
           48 
           49 # show all results.
           50 show() {
           51         for t in input/*/; do
           52                 for d in "$t"*/; do
           53                         for f in "$d"*.xml; do
           54                                 test -f "$f" || continue
           55                                 dest="expected/${f#input/}"
           56                                 test -f "$dest" || continue
           57 
           58                                 $sfeed < "$f" | fixup > /tmp/t
           59 
           60                                 echo "Input XML:"
           61                                 cat "$f"
           62                                 echo ""
           63                                 echo "Expected ($dest):"
           64                                 cat "$dest"
           65                                 echo ""
           66                                 echo "Result:"
           67                                 cat /tmp/t
           68                                 echo ""
           69                                 echo "Diff:"
           70                                 diff -u "$dest" /tmp/t
           71                         done
           72                 done
           73         done
           74 }
           75 
           76 # run and show only if the expected result differs.
           77 run() {
           78         status=0
           79         count=0
           80         for t in input/*/; do
           81                 for d in "$t"*/; do
           82                         for f in "$d"*.xml; do
           83                                 test -f "$f" || continue
           84                                 dest="expected/${f#input/}"
           85                                 test -f "$dest" || continue
           86 
           87                                 $sfeed < "$f" | fixup > /tmp/t
           88                                 if ! cmp -s "$dest" /tmp/t; then
           89                                         status=1
           90                                         echo ""
           91                                         echo "$f differs"
           92                                         echo "Input XML:"
           93                                         cat "$f"
           94                                         echo ""
           95                                         echo "Expected ($dest):"
           96                                         cat "$dest"
           97                                         echo ""
           98                                         echo "Result:"
           99                                         cat /tmp/t
          100                                         echo ""
          101                                         echo "Diff:"
          102                                         diff -u "$dest" /tmp/t
          103                                 fi
          104                                 count=$((count+1))
          105                         done
          106                 done
          107         done
          108         echo "$count results run."
          109         exit $status
          110 }
          111 
          112 # run and compare with program versions (don't compare to recorded expected results).
          113 run2() {
          114         echo "$program1 vs $program2"
          115 
          116         status=0
          117         count=0
          118         baseurl=""
          119 #        baseurl="incorrect"
          120 #        baseurl="https://codemadness.org/" # TEST baseurl
          121 
          122 #        for param in "" "http://a/" "https://a/" "gopher://a/" "http://a:8080/path/"; do
          123         for t in input/*/; do
          124                 for d in "$t"*/; do
          125                         for f in "$d"*.xml; do
          126                                 test -f "$f" || continue
          127 
          128                                 $program1 $baseurl < "$f" | fixup > /tmp/t1
          129                                 $program2 $baseurl < "$f" | fixup > /tmp/t2
          130                                 if ! cmp -s /tmp/t1 /tmp/t2; then
          131                                         status=1
          132                                         echo ""
          133                                         echo "$f differs"
          134                                         echo "Input XML:"
          135                                         cat "$f"
          136                                         echo ""
          137                                         echo "Expected:"
          138                                         cat /tmp/t1
          139                                         echo ""
          140                                         echo "Result:"
          141                                         cat /tmp/t2
          142                                         echo ""
          143                                         echo "Diff:"
          144                                         diff -u /tmp/t1 /tmp/t2
          145                                 fi
          146                                 count=$((count+1))
          147                         done
          148                 done
          149         done
          150         echo "$count results run."
          151         exit $status
          152 }
          153 
          154 # run program on input for code coverage purposes.
          155 # contains some specific tests (passing parameters, etc).
          156 coverage() {
          157         testprogram="$HOME/p/sfeed/sfeed"
          158 
          159         for baseurl in "" "https://codemadness.org/"; do
          160         for t in input/*/; do
          161                 for d in "$t"*/; do
          162                         for f in "$d"*.xml; do
          163                                 test -f "$f" || continue
          164 
          165                                 $testprogram $baseurl < "$f" >/dev/null 2>/dev/null
          166                         done
          167                 done
          168         done
          169         done
          170 
          171         # some very specific-tests.
          172         echo "" | $testprogram "" >/dev/null 2>/dev/null
          173         echo "" | $testprogram "http://127.0.0.1:-1" >/dev/null 2>/dev/null
          174         echo "" | $testprogram "http://127.0.0.1:65536" >/dev/null 2>/dev/null
          175         echo "" | $testprogram "http://127.0.0.1:12345678" >/dev/null 2>/dev/null
          176         echo "" | $testprogram "http://[" >/dev/null 2>/dev/null
          177         echo "" | $testprogram "http://[]" >/dev/null 2>/dev/null
          178         echo "" | $testprogram "codemadness.org" >/dev/null 2>/dev/null
          179         echo "" | $testprogram "https://codemadness.org" >/dev/null 2>/dev/null
          180         echo "" | $testprogram "ftp://user:password@[2001:db8::7]:2121/rfc/rfc1808.txt?q=bla#abc@def" >/dev/null 2>/dev/null
          181         echo "" | $testprogram "mailto:tests@codemadness.org" >/dev/null 2>/dev/null
          182 
          183         # too long URI fields.
codemadness.org:70 /git/sfeed_tests/file/tests.sh.gph:194: line too long