Browse Source

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
Frédéric Moulins 15 years ago
parent
commit
179b6f5fce

+ 5 - 0
test/references/get_parsing.data

@@ -0,0 +1,5 @@
+config 'type' 'section'
+	option 'opt'	'val'
+
+config 'unnamed'
+	option 'opt1'	'val1'

+ 2 - 0
test/references/set_parsing.data

@@ -0,0 +1,2 @@
+config 'type' 'section'
+	option 'opt'	'val'

+ 2 - 0
test/references/show_parsing.data

@@ -0,0 +1,2 @@
+config 'type' 'section'
+	option 'opt'	'val'

+ 26 - 0
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

+ 10 - 0
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

+ 11 - 0
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"
+}

+ 6 - 0
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}/*)