]> pilppa.com Git - uci.git/commitdiff
Add parsing tests for get, set and show
authorFrédéric Moulins <ffrrrr@gmail.com>
Mon, 25 Aug 2008 21:46:44 +0000 (23:46 +0200)
committerFelix <nbd@openwrt.org>
Mon, 25 Aug 2008 23:16:09 +0000 (01:16 +0200)
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

test/references/get_parsing.data [new file with mode: 0644]
test/references/set_parsing.data [new file with mode: 0644]
test/references/show_parsing.data [new file with mode: 0644]
test/tests.d/020_get
test/tests.d/030_set
test/tests.d/050_show [new file with mode: 0644]
test/tests.sh

diff --git a/test/references/get_parsing.data b/test/references/get_parsing.data
new file mode 100644 (file)
index 0000000..89fffdc
--- /dev/null
@@ -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 (file)
index 0000000..82b7231
--- /dev/null
@@ -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 (file)
index 0000000..82b7231
--- /dev/null
@@ -0,0 +1,2 @@
+config 'type' 'section'
+       option 'opt'    'val'
index 6b6029ae104fdde97c701c96fc1cd9b574a2fbfe..7c365f3dd515842edfa1a37476c8ee2d3cd5cd40 100644 (file)
@@ -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
index 8f695ed944f16880188c5914e882731238e0ea54..137a955f2d05f5a1135233432f8d814da508bdad 100644 (file)
@@ -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 (file)
index 0000000..2c4665e
--- /dev/null
@@ -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"
+}
index 52f138411d3659728c24c38cc73790a65f0acd37..ae064f1090038986e1c398a99b240b781cd88fa0 100644 (file)
@@ -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}/*)