From 179b6f5fced8a0c1028ee56451efa26e40392961 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Moulins?= Date: Mon, 25 Aug 2008 23:46:44 +0200 Subject: [PATCH] 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 --- test/references/get_parsing.data | 5 +++++ test/references/set_parsing.data | 2 ++ test/references/show_parsing.data | 2 ++ test/tests.d/020_get | 26 ++++++++++++++++++++++++++ test/tests.d/030_set | 10 ++++++++++ test/tests.d/050_show | 11 +++++++++++ test/tests.sh | 6 ++++++ 7 files changed, 62 insertions(+) create mode 100644 test/references/get_parsing.data create mode 100644 test/references/set_parsing.data create mode 100644 test/references/show_parsing.data create mode 100644 test/tests.d/050_show 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}/*) -- 2.25.1