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