Changeset 675


Ignore:
Timestamp:
May 19, 2013, 5:53:53 PM (8 years ago)
Author:
zerodeux
Message:

Basic but full test coverage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pussh/test

    r674 r675  
    22
    33# This is a trivial test harness : command to run, expected exit status,
    4 # expected stdout (extended regex), expected stderr (extended regex).
     4# expected stdout (extended regex), expected stderr (extended regex), and
     5# a custom optional test (a shell fragment).
    56# Only non-empty fields are checked.
    67# Use .test-* files for input, they will be cleaned out for you.
     
    1011  out="$3"
    1112  err="$4"
     13  more="$5"
    1214
    1315  eval "$cmd" >.test-stdout 2>.test-stderr
     
    2931  fi
    3032
     33  if [ -n "$more" ] && ! eval "$more"; then
     34    echo "FAIL: $cmd: '$more' custom test failed"
     35    let failed=$failed+1
     36  fi
     37
    3138  rm -f .test-*
    3239}
     
    3542
    3643assert "$pussh"           1 '' 'missing command'
    37 assert "$pussh --help"    0 '^Usage:' ''
    38 assert "$pussh --version" 0 '^pussh [0-9]' ''
     44assert "$pussh --help"    0 '^Usage:'
     45assert "$pussh --version" 0 '^pussh [0-9]'
    3946
    4047# Basic usage (-h/--hosts, -q/--quiet)
    41 assert "$pussh -h      localhost echo _TEST_"    0 '^localhost: _TEST_' ''
    42 assert "$pussh --hosts localhost echo _TEST_"    0 '^localhost: _TEST_' ''
    43 assert "$pussh -q      -h localhost echo _TEST_" 0 '^_TEST_' ''
    44 assert "$pussh --quiet -h localhost echo _TEST_" 0 '^_TEST_' ''
     48assert "$pussh -h      localhost echo _TEST_"    0 '^localhost: _TEST_'
     49assert "$pussh --hosts localhost echo _TEST_"    0 '^localhost: _TEST_'
     50assert "$pussh -q      -h localhost echo _TEST_" 0 '^_TEST_'
     51assert "$pussh --quiet -h localhost echo _TEST_" 0 '^_TEST_'
    4552
    4653# -r/--rate
    47 assert "$pussh -q -h localhost -r     100 echo _TEST_" 0 '^_TEST_' ''
    48 assert "$pussh -q -h localhost --rate 100 echo _TEST_" 0 '^_TEST_' ''
     54assert "$pussh -q -h localhost -r     100 echo _TEST_" 0 '^_TEST_'
     55assert "$pussh -q -h localhost --rate 100 echo _TEST_" 0 '^_TEST_'
    4956
    5057# -s/--ssh-opt
    51 assert "$pussh -q -h localhost -s        '-p22' echo _TEST_" 0 '^_TEST_' ''
    52 assert "$pussh -q -h localhost --ssh-opt '-p22' echo _TEST_" 0 '^_TEST_' ''
     58assert "$pussh -q -h localhost -s        '-p22' echo _TEST_" 0 '^_TEST_'
     59assert "$pussh -q -h localhost --ssh-opt '-p22' echo _TEST_" 0 '^_TEST_'
    5360
    5461# -l/--login
    55 assert "$pussh -q -h localhost -l      $LOGNAME echo _TEST_" 0 '^_TEST_' ''
    56 assert "$pussh -q -h localhost --login $LOGNAME echo _TEST_" 0 '^_TEST_' ''
     62assert "$pussh -q -h localhost -l      $LOGNAME echo _TEST_" 0 '^_TEST_'
     63assert "$pussh -q -h localhost --login $LOGNAME echo _TEST_" 0 '^_TEST_'
    5764
    5865# -n/--dry-run
    59 assert "$pussh -q -h localhost -n        echo _TEST_" 0 '^\[test\] localhost' ''
    60 assert "$pussh -q -h localhost --dry-run echo _TEST_" 0 '^\[test\] localhost' ''
     66assert "$pussh -q -h localhost -n        echo _TEST_" 0 '^\[test\] localhost'
     67assert "$pussh -q -h localhost --dry-run echo _TEST_" 0 '^\[test\] localhost'
    6168
    6269# -h/--hosts (multiple hosts)
    63 assert "$pussh -h localhost,127.0.0.1 echo _TEST_"      0 '^(localhost|127\.0\.0\.1): _TEST_' ''
    64 assert "$pussh -h localhost -h 127.0.0.1 echo _TEST_"   0 '^(localhost|127\.0\.0\.1): _TEST_' ''
     70assert "$pussh -h localhost,127.0.0.1 echo _TEST_"      0 '^(localhost|127\.0\.0\.1): _TEST_'
     71assert "$pussh -h localhost -h 127.0.0.1 echo _TEST_"   0 '^(localhost|127\.0\.0\.1): _TEST_'
    6572
    6673# -f/--from-file
    67 assert "echo localhost | $pussh -q -f          - echo _TEST_" 0 '^_TEST_' ''
    68 assert "echo localhost | $pussh -q --from-file - echo _TEST_" 0 '^_TEST_' ''
     74assert "echo localhost | $pussh -q -f          - echo _TEST_" 0 '^_TEST_'
     75assert "echo localhost | $pussh -q --from-file - echo _TEST_" 0 '^_TEST_'
    6976echo localhost 127.0.0.1 >.test-in
    70 assert "$pussh -f .test-in echo _TEST_" 0 '^(localhost|127\.0\.0\.1): _TEST_' ''
     77assert "$pussh -f .test-in echo _TEST_" 0 '^(localhost|127\.0\.0\.1): _TEST_'
    7178
    7279# -u/--upload
    73 assert "$pussh -q -h localhost -u       /bin/echo arg1 arg2" 0 '^arg1 arg2' ''
    74 assert "$pussh -q -h localhost --upload /bin/echo arg1 arg2" 0 '^arg1 arg2' ''
     80assert "$pussh -q -h localhost -u       /bin/echo arg1 arg2" 0 '^arg1 arg2'
     81assert "$pussh -q -h localhost --upload /bin/echo arg1 arg2" 0 '^arg1 arg2'
    7582
    7683# -i/--input
    7784echo _TEST_ >.test-in
    78 assert "$pussh -q -h localhost -i      .test-in cat" 0 '^_TEST_' ''
     85assert "$pussh -q -h localhost -i      .test-in cat" 0 '^_TEST_'
    7986echo _TEST_ >.test-in
    80 assert "$pussh -q -h localhost --input .test-in cat" 0 '^_TEST_' ''
     87assert "$pussh -q -h localhost --input .test-in cat" 0 '^_TEST_'
    8188echo _TEST_ >.test-in-localhost
    8289echo _TEST_ >.test-in-127.0.0.1
    83 assert "$pussh -h localhost,127.0.0.1 -i .test-in-%h cat"           0 '^(localhost|127\.0\.0\.1): _TEST_' ''
    84 assert "$pussh -q -h localhost -i 'echo _TEST_|' cat"               0 '_TEST_' ''
    85 assert "$pussh -q -h localhost,127.0.0.1 -i 'echo %h= _TEST_|' cat" 0 '^(localhost|127\.0\.0\.1)= _TEST_' ''
     90assert "$pussh -h localhost,127.0.0.1 -i .test-in-%h cat"           0 '^(localhost|127\.0\.0\.1): _TEST_'
     91assert "$pussh -q -h localhost -i 'echo _TEST_|' cat"               0 '_TEST_'
     92assert "$pussh -q -h localhost,127.0.0.1 -i 'echo %h= _TEST_|' cat" 0 '^(localhost|127\.0\.0\.1)= _TEST_'
    8693
    87 # -o
    88 #assert "$pussh -q -h localhost -o .test-out cat" 0 '^_TEST_' ''
     94# -o/--output
     95assert "$pussh -q -h localhost -o       .test-out echo _TEST_" 0 '' '' 'grep -qE ^_TEST_ .test-out'
     96assert "$pussh -q -h localhost --output .test-out echo _TEST_" 0 '' '' 'grep -qE ^_TEST_ .test-out'
     97assert "$pussh -q -h localhost,127.0.0.1 -o .test-out-%h echo _TEST_" 0 '' '' \
     98  'grep -qE ^_TEST_ .test-out-localhost && grep -qE ^_TEST_ .test-out-127.0.0.1'
     99assert "$pussh -q -h localhost -o '|cat >.test-out' echo _TEST_" 0 '' '' 'grep -qE ^_TEST_ .test-out'
     100assert "$pussh -q -h localhost,127.0.0.1 -o '|cat >.test-out-%h' echo _TEST_" 0 '' '' \
     101  'grep -qE ^_TEST_ .test-out-localhost && grep -qE ^_TEST_ .test-out-127.0.0.1'
    89102
    90103exit $failed
Note: See TracChangeset for help on using the changeset viewer.