subcommand 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Makefile +29 -0
- data/VERSION +1 -1
- data/lib/subcommand.rb +39 -15
- data/tests/Makefile +2 -0
- data/tests/README +313 -0
- data/tests/aggregate-results.sh +34 -0
- data/tests/recreate.sh +33 -0
- data/tests/rtest2.sh +127 -0
- data/tests/t0001-main.sh +51 -0
- data/tests/t0002-subcomm.sh +21 -0
- data/tests/t0003-inv_comm.sh +53 -0
- data/tests/t0004-subcomm.sh +25 -0
- data/tests/t0005-alias_goo.sh +28 -0
- data/tests/t0006-goo_opt.sh +25 -0
- data/tests/t0007-bar_baz.sh +44 -0
- data/tests/t0008-boo_zoo.sh +44 -0
- data/tests/test-lib.sh +618 -0
- metadata +17 -2
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
fixed=0
|
4
|
+
success=0
|
5
|
+
failed=0
|
6
|
+
broken=0
|
7
|
+
total=0
|
8
|
+
|
9
|
+
for file
|
10
|
+
do
|
11
|
+
while read type value
|
12
|
+
do
|
13
|
+
case $type in
|
14
|
+
'')
|
15
|
+
continue ;;
|
16
|
+
fixed)
|
17
|
+
fixed=$(($fixed + $value)) ;;
|
18
|
+
success)
|
19
|
+
success=$(($success + $value)) ;;
|
20
|
+
failed)
|
21
|
+
failed=$(($failed + $value)) ;;
|
22
|
+
broken)
|
23
|
+
broken=$(($broken + $value)) ;;
|
24
|
+
total)
|
25
|
+
total=$(($total + $value)) ;;
|
26
|
+
esac
|
27
|
+
done <"$file"
|
28
|
+
done
|
29
|
+
|
30
|
+
printf "%-8s%d\n" fixed $fixed
|
31
|
+
printf "%-8s%d\n" success $success
|
32
|
+
printf "%-8s%d\n" failed $failed
|
33
|
+
printf "%-8s%d\n" broken $broken
|
34
|
+
printf "%-8s%d\n" total $total
|
data/tests/recreate.sh
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#*******************************************************#
|
3
|
+
# recreate.sh
|
4
|
+
# written by Rahul Kumar #
|
5
|
+
# 2009/12/01 #
|
6
|
+
# recreate a failed test - pass the name of the earlier#
|
7
|
+
# test program. In some cases, you may have to rename #
|
8
|
+
# transcript.txt to the testcase since cp -i failes #
|
9
|
+
#*******************************************************#
|
10
|
+
|
11
|
+
# oldfile is the old test cases such as t0001-add.sh
|
12
|
+
oldfile="$1"
|
13
|
+
[ ! -f "$oldfile" ] && { echo "Could not find $oldfile"; exit -1 ; }
|
14
|
+
|
15
|
+
LOADSTR=
|
16
|
+
if grep -q CATEOF "$oldfile"; then
|
17
|
+
sed -n '/<<CATEOF/,/^CATEOF/p' "$oldfile" | grep -v "CATEOF" > data.1
|
18
|
+
LOADSTR='--load data.1'
|
19
|
+
echo found data, saved as data.1
|
20
|
+
wc -l data.1
|
21
|
+
fi
|
22
|
+
str=$( echo "$oldfile" | sed 's/^t[0-9]*-//;s/.sh$//' )
|
23
|
+
echo "Using suffix:$str"
|
24
|
+
read -p "press enter "
|
25
|
+
grep '^>>> ' "$oldfile" | sed 's/^>>> //'
|
26
|
+
read -p "press enter "
|
27
|
+
grep '^>>> ' "$oldfile" | sed 's/^>>> //' | ./rtest2.sh $LOADSTR "$str"
|
28
|
+
|
29
|
+
echo
|
30
|
+
echo renaming old file with O prefix
|
31
|
+
mv "$oldfile" O$oldfile
|
32
|
+
echo "If you don't find a test case, then rename transcript.txt to $oldfile"
|
33
|
+
echo "cp transcript.txt $oldfile"
|
data/tests/rtest2.sh
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#*******************************************************#
|
3
|
+
# rtest2.sh #
|
4
|
+
# written by Rahul Kumar #
|
5
|
+
# December 21, 2009 #
|
6
|
+
# #
|
7
|
+
# generates a test case #
|
8
|
+
#*******************************************************#
|
9
|
+
# @param - test descriptor - short name
|
10
|
+
#+ will be used in test_desc and filename suffix
|
11
|
+
#
|
12
|
+
# If testing for error, and command returns 1
|
13
|
+
#+ place "=== 1" on first line or result
|
14
|
+
|
15
|
+
while [[ $1 = -* ]]; do
|
16
|
+
case "$1" in
|
17
|
+
-L|--load)
|
18
|
+
# load a file containing TODO2.txt data to test against
|
19
|
+
dataset=../$2
|
20
|
+
shift
|
21
|
+
shift
|
22
|
+
;;
|
23
|
+
*)
|
24
|
+
echo "Error: Unknown option: $1" >&2 # rem _
|
25
|
+
exit 1
|
26
|
+
;;
|
27
|
+
esac
|
28
|
+
done
|
29
|
+
|
30
|
+
if [[ -z "$1" ]]; then
|
31
|
+
echo -n "Test Description (short, no spaces): " 1>&2
|
32
|
+
read td
|
33
|
+
else
|
34
|
+
td="$1"
|
35
|
+
fi
|
36
|
+
# for generating a serial number
|
37
|
+
APP="subcommand-test"
|
38
|
+
|
39
|
+
PS1=">>>"
|
40
|
+
out="$(pwd)/transcript.txt"
|
41
|
+
test_description="Testing of $td"
|
42
|
+
filesuffix=$( echo "$td" | sed 's/ /_/g' )
|
43
|
+
|
44
|
+
|
45
|
+
. ./test-lib.sh
|
46
|
+
trap - EXIT
|
47
|
+
if [[ ! -z "$dataset" ]]; then
|
48
|
+
if [[ ! -f "$dataset" ]]; then
|
49
|
+
echo "Can't find file $dataset"
|
50
|
+
exit 1
|
51
|
+
else
|
52
|
+
wc -l "$dataset"
|
53
|
+
fi
|
54
|
+
fi
|
55
|
+
if [[ ! -z "$dataset" ]]; then
|
56
|
+
cp "${dataset}" TODO2.txt
|
57
|
+
pre+=$( echo -e "cat > TODO2.txt <<CATEOF")
|
58
|
+
pre+="\n"
|
59
|
+
pre+=$(cat TODO2.txt)
|
60
|
+
pre+=$( echo -e "\nCATEOF\n" )
|
61
|
+
fi
|
62
|
+
str=""
|
63
|
+
> "$out"
|
64
|
+
|
65
|
+
history -r .rtest2.history
|
66
|
+
## get user input, stop when user enters 'bye'
|
67
|
+
while read -ep ">>> " line
|
68
|
+
do
|
69
|
+
# echo -n ">>> "
|
70
|
+
# read line
|
71
|
+
[ -z "$line" ] && { echo "bye to quit"; continue; }
|
72
|
+
[[ "$line" = "bye" ]] && break;
|
73
|
+
[[ "$line" = "abort" ]] && exit 1;
|
74
|
+
[ -n "$line" ] && history -s "$line"
|
75
|
+
|
76
|
+
## user can execute test_tick in current shell
|
77
|
+
[[ "$line" = *test_tick* ]] && {
|
78
|
+
times=$( expr "$line" : 'test_tick \(.*\)' )
|
79
|
+
# should be multiples of 86400 or at least more than 86400
|
80
|
+
test_tick $times;
|
81
|
+
}
|
82
|
+
|
83
|
+
if grep -q "^list" <<< "$line"; then
|
84
|
+
line=$( echo "$line" | sed 's/^list/t --sort-serial list/')
|
85
|
+
fi
|
86
|
+
if grep -q "^ls" <<< "$line"; then
|
87
|
+
line=$( echo "$line" | sed 's/^ls/t --sort-serial --no-colors list/')
|
88
|
+
fi
|
89
|
+
line=$(echo "$line" | sed 's/--ss /--sort-serial /')
|
90
|
+
line=$(echo "$line" | sed 's/--nc /--no-colors /')
|
91
|
+
#[[ "$line" = "list" ]] && line="t --sort-serial list";
|
92
|
+
#[[ "$line" = "ls" ]] && line="t --sort-serial --no-colors list";
|
93
|
+
line=$(echo "$line" | sed 's~^t ~ruby bin/subcommand ~')
|
94
|
+
echo ">>> $line" >> $out
|
95
|
+
eval "$line" | tee -a "$out"
|
96
|
+
# RK since old version stopped expect on blank line I've placed this marker
|
97
|
+
echo ">>> end" >> $out
|
98
|
+
#echo "" >> $out
|
99
|
+
done
|
100
|
+
|
101
|
+
## generate the test case transcript
|
102
|
+
str="$( cat $out )"
|
103
|
+
> "$out"
|
104
|
+
cat > "$out" <<EOF
|
105
|
+
#!/bin/sh
|
106
|
+
test_description="Testing out $td "
|
107
|
+
. ./test-lib.sh
|
108
|
+
|
109
|
+
|
110
|
+
EOF
|
111
|
+
echo -e "$pre" >> "$out"
|
112
|
+
echo "" >> "$out"
|
113
|
+
echo "test_todo_session \"Testing of $td\" <<EOF" >> "$out"
|
114
|
+
echo "$str" >> "$out"
|
115
|
+
echo "" >> "$out"
|
116
|
+
echo "EOF" >> "$out"
|
117
|
+
echo "test_done" >> "$out"
|
118
|
+
|
119
|
+
# try to create a decent file name
|
120
|
+
serno=$( get_serial_number -a "$APP" -d "../" )
|
121
|
+
serno=$( printf "%04s" "$serno" )
|
122
|
+
filename="../t${serno}-${filesuffix}.sh"
|
123
|
+
echo "trying to copy $out to $filename"
|
124
|
+
chmod +x "$out"
|
125
|
+
cp -i "$out" "$filename" < /dev/tty
|
126
|
+
chmod +x "$filename"
|
127
|
+
echo "Please rename $filename to prevent possible overwriting"
|
data/tests/t0001-main.sh
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
test_description="Testing out main "
|
3
|
+
. ./test-lib.sh
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
test_todo_session "Testing of main" <<EOF
|
9
|
+
>>> ruby bin/subcommand.rb help
|
10
|
+
Usage: subcommand.rb [options] [subcommand [options]]
|
11
|
+
Stupid program that does something
|
12
|
+
|
13
|
+
Global options are:
|
14
|
+
-v, --[no-]verbose Run verbosely
|
15
|
+
|
16
|
+
Commands are:
|
17
|
+
foo : desc for foo
|
18
|
+
baz : desc for baz
|
19
|
+
|
20
|
+
Aliases:
|
21
|
+
goo - foo
|
22
|
+
bar - ["baz"]
|
23
|
+
boo - ["foo", "--force"]
|
24
|
+
zoo - ["foo", "ruby"]
|
25
|
+
|
26
|
+
|
27
|
+
See 'bin/subcommand.rb help COMMAND' for more information on a specific command.
|
28
|
+
>>> end
|
29
|
+
>>> ruby bin/subcommand.rb --help
|
30
|
+
Usage: subcommand.rb [options] [subcommand [options]]
|
31
|
+
Stupid program that does something
|
32
|
+
|
33
|
+
Global options are:
|
34
|
+
-v, --[no-]verbose Run verbosely
|
35
|
+
|
36
|
+
Commands are:
|
37
|
+
foo : desc for foo
|
38
|
+
baz : desc for baz
|
39
|
+
|
40
|
+
Aliases:
|
41
|
+
goo - foo
|
42
|
+
bar - ["baz"]
|
43
|
+
boo - ["foo", "--force"]
|
44
|
+
zoo - ["foo", "ruby"]
|
45
|
+
|
46
|
+
|
47
|
+
See 'bin/subcommand.rb help COMMAND' for more information on a specific command.
|
48
|
+
>>> end
|
49
|
+
|
50
|
+
EOF
|
51
|
+
test_done
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
test_description="Testing out subcomm "
|
3
|
+
. ./test-lib.sh
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
test_todo_session "Testing of subcomm" <<EOF
|
9
|
+
>>> ruby bin/subcommand.rb help foo
|
10
|
+
Usage: foo [options]
|
11
|
+
desc for foo
|
12
|
+
-f, --[no-]force force verbosely
|
13
|
+
>>> end
|
14
|
+
>>> ruby bin/subcommand.rb foo --help
|
15
|
+
Usage: foo [options]
|
16
|
+
desc for foo
|
17
|
+
-f, --[no-]force force verbosely
|
18
|
+
>>> end
|
19
|
+
|
20
|
+
EOF
|
21
|
+
test_done
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
test_description="Testing out inv_comm "
|
3
|
+
. ./test-lib.sh
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
test_todo_session "Testing of inv_comm" <<EOF
|
9
|
+
>>> ruby bin/subcommand.rb help fxxx
|
10
|
+
Invalid command: fxxx.
|
11
|
+
Usage: subcommand.rb [options] [subcommand [options]]
|
12
|
+
Stupid program that does something
|
13
|
+
|
14
|
+
Global options are:
|
15
|
+
-v, --[no-]verbose Run verbosely
|
16
|
+
|
17
|
+
Commands are:
|
18
|
+
foo : desc for foo
|
19
|
+
baz : desc for baz
|
20
|
+
|
21
|
+
Aliases:
|
22
|
+
goo - foo
|
23
|
+
bar - ["baz"]
|
24
|
+
boo - ["foo", "--force"]
|
25
|
+
zoo - ["foo", "ruby"]
|
26
|
+
|
27
|
+
|
28
|
+
See 'bin/subcommand.rb help COMMAND' for more information on a specific command.
|
29
|
+
>>> end
|
30
|
+
>>> ruby bin/subcommand.rb fxxx --help
|
31
|
+
Invalid command: fxxx
|
32
|
+
Usage: subcommand.rb [options] [subcommand [options]]
|
33
|
+
Stupid program that does something
|
34
|
+
|
35
|
+
Global options are:
|
36
|
+
-v, --[no-]verbose Run verbosely
|
37
|
+
|
38
|
+
Commands are:
|
39
|
+
foo : desc for foo
|
40
|
+
baz : desc for baz
|
41
|
+
|
42
|
+
Aliases:
|
43
|
+
goo - foo
|
44
|
+
bar - ["baz"]
|
45
|
+
boo - ["foo", "--force"]
|
46
|
+
zoo - ["foo", "ruby"]
|
47
|
+
|
48
|
+
|
49
|
+
See 'bin/subcommand.rb help COMMAND' for more information on a specific command.
|
50
|
+
>>> end
|
51
|
+
|
52
|
+
EOF
|
53
|
+
test_done
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
test_description="Testing out subcomm "
|
3
|
+
. ./test-lib.sh
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
test_todo_session "Testing of subcomm" <<EOF
|
9
|
+
>>> ruby bin/subcommand.rb baz --quiet "some text"
|
10
|
+
cmd: baz
|
11
|
+
options ......
|
12
|
+
{:quiet=>true}
|
13
|
+
ARGV:
|
14
|
+
["some text"]
|
15
|
+
>>> end
|
16
|
+
>>> ruby bin/subcommand.rb --verbose foo --force file.zzz
|
17
|
+
cmd: foo
|
18
|
+
options ......
|
19
|
+
{:verbose=>true, :force=>true}
|
20
|
+
ARGV:
|
21
|
+
["file.zzz"]
|
22
|
+
>>> end
|
23
|
+
|
24
|
+
EOF
|
25
|
+
test_done
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
test_description="Testing out alias_goo "
|
3
|
+
. ./test-lib.sh
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
test_todo_session "Testing of alias_goo" <<EOF
|
9
|
+
>>> ruby bin/subcommand.rb goo
|
10
|
+
cmd: foo
|
11
|
+
options ......
|
12
|
+
{}
|
13
|
+
ARGV:
|
14
|
+
[]
|
15
|
+
>>> end
|
16
|
+
>>> ruby bin/subcommand.rb help goo
|
17
|
+
Usage: foo [options]
|
18
|
+
desc for foo
|
19
|
+
-f, --[no-]force force verbosely
|
20
|
+
>>> end
|
21
|
+
>>> ruby bin/subcommand.rb goo --help
|
22
|
+
Usage: foo [options]
|
23
|
+
desc for foo
|
24
|
+
-f, --[no-]force force verbosely
|
25
|
+
>>> end
|
26
|
+
|
27
|
+
EOF
|
28
|
+
test_done
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
test_description="Testing out goo_opt "
|
3
|
+
. ./test-lib.sh
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
test_todo_session "Testing of goo_opt" <<EOF
|
9
|
+
>>> ruby bin/subcommand.rb goo -f
|
10
|
+
cmd: foo
|
11
|
+
options ......
|
12
|
+
{:force=>true}
|
13
|
+
ARGV:
|
14
|
+
[]
|
15
|
+
>>> end
|
16
|
+
>>> ruby bin/subcommand.rb foo -f
|
17
|
+
cmd: foo
|
18
|
+
options ......
|
19
|
+
{:force=>true}
|
20
|
+
ARGV:
|
21
|
+
[]
|
22
|
+
>>> end
|
23
|
+
|
24
|
+
EOF
|
25
|
+
test_done
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
test_description="Testing out bar_baz "
|
3
|
+
. ./test-lib.sh
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
test_todo_session "Testing of bar_baz" <<EOF
|
9
|
+
>>> ruby bin/subcommand.rb bar
|
10
|
+
cmd: baz
|
11
|
+
options ......
|
12
|
+
{}
|
13
|
+
ARGV:
|
14
|
+
[]
|
15
|
+
>>> end
|
16
|
+
>>> ruby bin/subcommand.rb baz
|
17
|
+
cmd: baz
|
18
|
+
options ......
|
19
|
+
{}
|
20
|
+
ARGV:
|
21
|
+
[]
|
22
|
+
>>> end
|
23
|
+
>>> ruby bin/subcommand.rb baz --help
|
24
|
+
Usage: baz [options]
|
25
|
+
desc for baz
|
26
|
+
-q, --[no-]quiet quietly run
|
27
|
+
>>> end
|
28
|
+
>>> ruby bin/subcommand.rb baz -q
|
29
|
+
cmd: baz
|
30
|
+
options ......
|
31
|
+
{:quiet=>true}
|
32
|
+
ARGV:
|
33
|
+
[]
|
34
|
+
>>> end
|
35
|
+
>>> ruby bin/subcommand.rb bar -q
|
36
|
+
cmd: baz
|
37
|
+
options ......
|
38
|
+
{:quiet=>true}
|
39
|
+
ARGV:
|
40
|
+
[]
|
41
|
+
>>> end
|
42
|
+
|
43
|
+
EOF
|
44
|
+
test_done
|