summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Moulins <ffrrrr@gmail.com>2008-08-25 23:46:44 +0200
committerFelix <nbd@openwrt.org>2008-08-26 01:16:09 +0200
commit179b6f5fced8a0c1028ee56451efa26e40392961 (patch)
tree4b108faae91d264963fa49a91a935cd7a9b2cbed
parent4dc75cbcd4cbd7f5f7924c4b912c2faea0ec432c (diff)
downloaduci-179b6f5fced8a0c1028ee56451efa26e40392961.tar.gz
Add parsing tests for get, set and show
Hello, the result of 'make test' is explicit, even if there is much noise for the same issue I think. Do not miss segmentation faults in the log when testing section index corner cases. fred
-rw-r--r--test/references/get_parsing.data5
-rw-r--r--test/references/set_parsing.data2
-rw-r--r--test/references/show_parsing.data2
-rw-r--r--test/tests.d/020_get26
-rw-r--r--test/tests.d/030_set10
-rw-r--r--test/tests.d/050_show11
-rw-r--r--test/tests.sh6
7 files changed, 62 insertions, 0 deletions
diff --git a/test/references/get_parsing.data b/test/references/get_parsing.data
new file mode 100644
index 0000000..89fffdc
--- /dev/null
+++ b/test/references/get_parsing.data
@@ -0,0 +1,5 @@
+config 'type' 'section'
+ option 'opt' 'val'
+
+config 'unnamed'
+ option 'opt1' 'val1'
diff --git a/test/references/set_parsing.data b/test/references/set_parsing.data
new file mode 100644
index 0000000..82b7231
--- /dev/null
+++ b/test/references/set_parsing.data
@@ -0,0 +1,2 @@
+config 'type' 'section'
+ option 'opt' 'val'
diff --git a/test/references/show_parsing.data b/test/references/show_parsing.data
new file mode 100644
index 0000000..82b7231
--- /dev/null
+++ b/test/references/show_parsing.data
@@ -0,0 +1,2 @@
+config 'type' 'section'
+ option 'opt' 'val'
diff --git a/test/tests.d/020_get b/test/tests.d/020_get
index 6b6029a..7c365f3 100644
--- a/test/tests.d/020_get
+++ b/test/tests.d/020_get
@@ -1,3 +1,29 @@
+test_get_parsing()
+{
+ cp ${REF_DIR}/get_parsing.data ${CONFIG_DIR}/test
+
+ assertFailWithNoReturn "${UCI} get test."
+ assertFailWithNoReturn "${UCI} get test.section."
+ assertFailWithNoReturn "${UCI} get test.section.opt."
+ assertFailWithNoReturn "${UCI} get test.section.opt.val."
+ assertFailWithNoReturn "${UCI} get test.section.opt.val.qsdf.qsd"
+ assertFailWithNoReturn "${UCI} get test.section.opt.valqsqsd"
+}
+
+test_get_section_index_parsing()
+{
+ cp ${REF_DIR}/get_parsing.data ${CONFIG_DIR}/test
+
+ assertFailWithNoReturn "${UCI} get test.@"
+ assertFailWithNoReturn "${UCI} get test.@zer."
+ assertFailWithNoReturn "${UCI} get test.@."
+ assertFailWithNoReturn "${UCI} get test.@zer[1]"
+ assertFailWithNoReturn "${UCI} get test.@.opt"
+ assertFailWithNoReturn "${UCI} get test.@[28]"
+ assertFailWithNoReturn "${UCI} get test.@[1]."
+ assertFailWithNoReturn "${UCI} get test.@[1].val."
+}
+
test_get_option()
{
cp ${REF_DIR}/get.data ${CONFIG_DIR}/test
diff --git a/test/tests.d/030_set b/test/tests.d/030_set
index 8f695ed..137a955 100644
--- a/test/tests.d/030_set
+++ b/test/tests.d/030_set
@@ -1,3 +1,13 @@
+test_set_parsing()
+{
+ cp ${REF_DIR}/set_parsing.data ${CONFIG_DIR}/test
+
+ assertFailWithNoReturn "${UCI} set test.=val"
+ assertFailWithNoReturn "${UCI} set test.section.=val"
+ assertFailWithNoReturn "${UCI} set test.section.opt.=val"
+ assertFailWithNoReturn "${UCI} set test.section.opt.zflk=val"
+}
+
test_set_named_section()
{
touch ${CONFIG_DIR}/set
diff --git a/test/tests.d/050_show b/test/tests.d/050_show
new file mode 100644
index 0000000..2c4665e
--- /dev/null
+++ b/test/tests.d/050_show
@@ -0,0 +1,11 @@
+test_get_parsing()
+{
+ cp ${REF_DIR}/show_parsing.data ${CONFIG_DIR}/test
+
+ assertFailWithNoReturn "${UCI} show test."
+ assertFailWithNoReturn "${UCI} show test.section."
+ assertFailWithNoReturn "${UCI} show test.section.opt."
+ assertFailWithNoReturn "${UCI} show test.section.opt.val."
+ assertFailWithNoReturn "${UCI} show test.section.opt.val.qsdf.qsd"
+ assertFailWithNoReturn "${UCI} show test.section.opt.valqsqsd"
+}
diff --git a/test/tests.sh b/test/tests.sh
index 52f1384..ae064f1 100644
--- a/test/tests.sh
+++ b/test/tests.sh
@@ -40,6 +40,12 @@ assertSameFile() {
echo "----"
}
}
+assertFailWithNoReturn() {
+ local test="$1"
+ value=$( $test )
+ assertFalse "'$test' does not fail" $?
+ assertNull "'$test' returns '$value'" "$value"
+}
EOF
for suite in $(ls ${SCRIPTS_DIR}/*)