1 |
commit: 07aaa67d8fb33731ef8fbe1020cbb67f19968812 |
2 |
Author: Matthias Schwarzott <zzam <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Jun 8 11:43:54 2011 +0000 |
4 |
Commit: Matthias Schwarzott <zzam <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Jun 8 13:47:57 2011 +0000 |
6 |
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/udev-gentoo-scripts.git;a=commit;h=07aaa67d |
7 |
|
8 |
Use shtest2 for testing |
9 |
|
10 |
Improve testcases a bit |
11 |
|
12 |
--- |
13 |
Makefile | 3 +- |
14 |
test-kv.sh | 55 -------------------------------- |
15 |
test/test_KV_to_int.sh | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ |
16 |
3 files changed, 82 insertions(+), 57 deletions(-) |
17 |
|
18 |
diff --git a/Makefile b/Makefile |
19 |
index 802c764..d308682 100644 |
20 |
--- a/Makefile |
21 |
+++ b/Makefile |
22 |
@@ -48,8 +48,7 @@ check-git-repository: |
23 |
git diff --cached --quiet || { echo 'STOP, you have uncommitted changes in the index' ; false ; } |
24 |
|
25 |
test: |
26 |
- @echo "Running tests" |
27 |
- @./test-kv.sh |
28 |
+ @cd test; ./run_test.sh |
29 |
|
30 |
dist: check-git-repository test |
31 |
git archive --format=tar --prefix=$(DESTNAME)/ HEAD | bzip2 > $(DESTNAME).tar.bz2 |
32 |
|
33 |
diff --git a/test-kv.sh b/test-kv.sh |
34 |
deleted file mode 100755 |
35 |
index e58064f..0000000 |
36 |
--- a/test-kv.sh |
37 |
+++ /dev/null |
38 |
@@ -1,55 +0,0 @@ |
39 |
-#!/bin/bash |
40 |
- |
41 |
-source helpers/shell-compat-KV.sh |
42 |
- |
43 |
-errcnt=0 |
44 |
- |
45 |
-test_kv() |
46 |
-{ |
47 |
- local input="$1" actual= expected="$2" |
48 |
- actual=$(KV_to_int "$input" 2>/dev/null) |
49 |
- if [[ "$actual" = "$expected" ]]; then |
50 |
- echo "ok: KV_to_int $input" |
51 |
- else |
52 |
- echo "fail: KV_to_int input=$input, expected=$expected, actual=$actual" |
53 |
- errcnt=$(($errcnt+1)) |
54 |
- fi |
55 |
-} |
56 |
- |
57 |
-echo "Testing KV_to_int" |
58 |
- |
59 |
-# two digit ones |
60 |
-test_kv 2.6 132608 |
61 |
-test_kv 3.0 196608 |
62 |
-test_kv 3.1 196864 |
63 |
- |
64 |
-# normal three digit numbers |
65 |
-test_kv 2.6.0 132608 |
66 |
-test_kv 2.6.1 132609 |
67 |
-test_kv 2.6.2 132610 |
68 |
-test_kv 2.6.35 132643 |
69 |
-test_kv 3.0.1 196609 |
70 |
- |
71 |
-# four digit numbers |
72 |
-test_kv 2.6.35.1 132643 |
73 |
-test_kv 2.6.35.995 132643 |
74 |
- |
75 |
-# with suffix |
76 |
-test_kv 2.6.35+1suf 132643 |
77 |
-test_kv 2.6.35-2suf 132643 |
78 |
-test_kv 2.6.35%3suf 132643 |
79 |
-test_kv 2.6.35x4suf 132643 |
80 |
- |
81 |
-test_kv 3.0+1suf 196608 |
82 |
-test_kv 3.0-2suf 196608 |
83 |
-test_kv 3.0%3suf 196608 |
84 |
-test_kv 3.0x4suf 196608 |
85 |
- |
86 |
-if [[ "$errcnt" = 0 ]]; then |
87 |
- echo "Test success" |
88 |
- exit 0 |
89 |
-else |
90 |
- echo "Tests failed: $errcnt" |
91 |
- exit 1 |
92 |
-fi |
93 |
- |
94 |
|
95 |
diff --git a/test/test_KV_to_int.sh b/test/test_KV_to_int.sh |
96 |
new file mode 100755 |
97 |
index 0000000..917f243 |
98 |
--- /dev/null |
99 |
+++ b/test/test_KV_to_int.sh |
100 |
@@ -0,0 +1,81 @@ |
101 |
+#!/bin/sh |
102 |
+ |
103 |
+oneTimeSetUp() |
104 |
+{ |
105 |
+ unset -f KV_to_int |
106 |
+ . ../helpers/shell-compat-KV.sh |
107 |
+} |
108 |
+ |
109 |
+check_kv() |
110 |
+{ |
111 |
+ local input="$1" actual= expected="$2" |
112 |
+ actual=$(KV_to_int "$input" 2>/dev/null) |
113 |
+ assertEquals "$?" "0" |
114 |
+ assertEquals "$expected" "$actual" |
115 |
+} |
116 |
+ |
117 |
+expect_fail_kv() |
118 |
+{ |
119 |
+ local input="$1" actual= |
120 |
+ actual=$(KV_to_int "$input" 2>&1) |
121 |
+ assertEquals "$?" "1" |
122 |
+ assertEquals "" "$actual" |
123 |
+} |
124 |
+ |
125 |
+testTooOld() |
126 |
+{ |
127 |
+ expect_fail_kv 2.1.0 |
128 |
+ expect_fail_kv 2.1.1 |
129 |
+ expect_fail_kv 2.1.2 |
130 |
+} |
131 |
+ |
132 |
+testOneDigit() |
133 |
+{ |
134 |
+ check_kv 3 196608 |
135 |
+} |
136 |
+ |
137 |
+testTwoDigit() |
138 |
+{ |
139 |
+ check_kv 2.6 132608 |
140 |
+ check_kv 3.0 196608 |
141 |
+ check_kv 3.1 196864 |
142 |
+} |
143 |
+ |
144 |
+testThreeDigit() |
145 |
+{ |
146 |
+ check_kv 2.6.0 132608 |
147 |
+ check_kv 2.6.1 132609 |
148 |
+ check_kv 2.6.2 132610 |
149 |
+ check_kv 2.6.35 132643 |
150 |
+ check_kv 3.0.1 196609 |
151 |
+} |
152 |
+ |
153 |
+testFourDigit() |
154 |
+{ |
155 |
+ check_kv 2.6.35.1 132643 |
156 |
+ check_kv 2.6.35.995 132643 |
157 |
+} |
158 |
+ |
159 |
+testSuffixNormal() |
160 |
+{ |
161 |
+ check_kv 2.6.35-2suf 132643 |
162 |
+ check_kv 3.0-2suf 196608 |
163 |
+} |
164 |
+ |
165 |
+testSuffixSpecial() |
166 |
+{ |
167 |
+ check_kv 2.6.35.1+1suf 132643 |
168 |
+ check_kv 2.6.35.1%3suf 132643 |
169 |
+ check_kv 2.6.35.1x4suf 132643 |
170 |
+ |
171 |
+ check_kv 2.6.35+1suf 132643 |
172 |
+ check_kv 2.6.35%3suf 132643 |
173 |
+ check_kv 2.6.35x4suf 132643 |
174 |
+ |
175 |
+ check_kv 3.0+1suf 196608 |
176 |
+ check_kv 3.0%3suf 196608 |
177 |
+ check_kv 3.0x4suf 196608 |
178 |
+} |
179 |
+ |
180 |
+. ./shunit2 |
181 |
+ |