diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:23:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 04:23:18 +0000 |
commit | b90161ccd3b318f3314a23cb10c387651ad35831 (patch) | |
tree | a47dc087160299ce02d728cbf031d84af6281537 /tests/yangre | |
parent | Adding upstream version 2.1.30. (diff) | |
download | libyang2-upstream.tar.xz libyang2-upstream.zip |
Adding upstream version 2.1.148.upstream/2.1.148upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/yangre')
-rw-r--r-- | tests/yangre/CMakeLists.txt | 8 | ||||
-rw-r--r-- | tests/yangre/all.tcl | 15 | ||||
-rw-r--r-- | tests/yangre/arg.test | 19 | ||||
-rw-r--r-- | tests/yangre/file.test | 37 | ||||
-rw-r--r-- | tests/yangre/files/empty.txt | 0 | ||||
-rw-r--r-- | tests/yangre/files/empty_str.txt | 2 | ||||
-rw-r--r-- | tests/yangre/files/empty_str_err.txt | 2 | ||||
-rw-r--r-- | tests/yangre/files/one_pattern.txt | 3 | ||||
-rw-r--r-- | tests/yangre/files/two_patterns.txt | 4 | ||||
-rw-r--r-- | tests/yangre/files/two_patterns_err.txt | 4 | ||||
-rw-r--r-- | tests/yangre/files/two_patterns_invert_match.txt | 4 | ||||
-rw-r--r-- | tests/yangre/files/two_patterns_invert_match_err.txt | 4 | ||||
-rw-r--r-- | tests/yangre/invert_match.test | 28 | ||||
-rw-r--r-- | tests/yangre/ly.tcl | 17 | ||||
-rw-r--r-- | tests/yangre/pattern.test | 19 |
15 files changed, 166 insertions, 0 deletions
diff --git a/tests/yangre/CMakeLists.txt b/tests/yangre/CMakeLists.txt new file mode 100644 index 0000000..ce5b39b --- /dev/null +++ b/tests/yangre/CMakeLists.txt @@ -0,0 +1,8 @@ +find_program(PATH_TCLSH NAMES tclsh) +if(NOT PATH_TCLSH) + message(WARNING "'tclsh' not found! The yangre test will not be available.") +else() + add_test(NAME "yangre" COMMAND "tclsh" "${CMAKE_CURRENT_SOURCE_DIR}/all.tcl") + set_property(TEST "yangre" APPEND PROPERTY ENVIRONMENT "TESTS_DIR=${CMAKE_CURRENT_SOURCE_DIR}") + set_property(TEST "yangre" APPEND PROPERTY ENVIRONMENT "YANGRE=${PROJECT_BINARY_DIR}") +endif() diff --git a/tests/yangre/all.tcl b/tests/yangre/all.tcl new file mode 100644 index 0000000..f00563f --- /dev/null +++ b/tests/yangre/all.tcl @@ -0,0 +1,15 @@ +package require tcltest + +# Hook to determine if any of the tests failed. +# Sets a global variable exitCode to 1 if any test fails otherwise it is set to 0. +proc tcltest::cleanupTestsHook {} { + variable numTests + set ::exitCode [expr {$numTests(Failed) > 0}] +} + +if {[info exists ::env(TESTS_DIR)]} { + tcltest::configure -testdir "$env(TESTS_DIR)" +} + +tcltest::runAllTests +exit $exitCode diff --git a/tests/yangre/arg.test b/tests/yangre/arg.test new file mode 100644 index 0000000..821aad1 --- /dev/null +++ b/tests/yangre/arg.test @@ -0,0 +1,19 @@ +source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/ly.tcl" : "ly.tcl"}] + +test arg_empty {Missing arguments} { + ly_cmd_err "" "missing <string> parameter to process" +} {} + +test arg_wrong {Wrong argument} { + ly_cmd_err "-j" "invalid option" +} {} + +test arg_help {Print help} { + ly_cmd "-h" "Usage:" +} {} + +test arg_version {Print version} { + ly_cmd "-v" "yangre" +} {} + +cleanupTests diff --git a/tests/yangre/file.test b/tests/yangre/file.test new file mode 100644 index 0000000..80ea3f6 --- /dev/null +++ b/tests/yangre/file.test @@ -0,0 +1,37 @@ +source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/ly.tcl" : "ly.tcl"}] + +set fdir "$::env(TESTS_DIR)/files" + +test file_empty {file is empty} { + ly_cmd "-f $fdir/empty.txt" +} {} + +test file_empty_str {<string> is empty} { + ly_cmd "-f $fdir/empty_str.txt" +} {} + +test file_empty_str_err {empty <string> is not allowed} { + ly_cmd_err "-f $fdir/empty_str_err.txt" "does not conform" +} {} + +test file_one_pattern {one pattern in the file} { + ly_cmd "-f $fdir/one_pattern.txt" +} {} + +test file_two_patterns {two patterns in the file} { + ly_cmd "-f $fdir/two_patterns.txt" +} {} + +test file_two_patterns_err {two patterns and the <string> is wrong} { + ly_cmd_err "-f $fdir/two_patterns_err.txt" "does not conform" +} {} + +test file_two_patterns_invert_match {one pattern is inverted} { + ly_cmd "-f $fdir/two_patterns_invert_match.txt" +} {} + +test file_two_patterns_invert_match_err {one pattern is inverted and the <string> is wrong} { + ly_cmd_err "-f $fdir/two_patterns_invert_match_err.txt" "does not conform to inverted" +} {} + +cleanupTests diff --git a/tests/yangre/files/empty.txt b/tests/yangre/files/empty.txt new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/yangre/files/empty.txt diff --git a/tests/yangre/files/empty_str.txt b/tests/yangre/files/empty_str.txt new file mode 100644 index 0000000..bf9b1b5 --- /dev/null +++ b/tests/yangre/files/empty_str.txt @@ -0,0 +1,2 @@ +"[0-9a-fA-F]*" + diff --git a/tests/yangre/files/empty_str_err.txt b/tests/yangre/files/empty_str_err.txt new file mode 100644 index 0000000..f48a15d --- /dev/null +++ b/tests/yangre/files/empty_str_err.txt @@ -0,0 +1,2 @@ +"[0-9a-fA-F]+" + diff --git a/tests/yangre/files/one_pattern.txt b/tests/yangre/files/one_pattern.txt new file mode 100644 index 0000000..cf9acc5 --- /dev/null +++ b/tests/yangre/files/one_pattern.txt @@ -0,0 +1,3 @@ +"[0-9a-fA-F]*" + +1F diff --git a/tests/yangre/files/two_patterns.txt b/tests/yangre/files/two_patterns.txt new file mode 100644 index 0000000..7d04b2c --- /dev/null +++ b/tests/yangre/files/two_patterns.txt @@ -0,0 +1,4 @@ +"[0-9a-fA-F]*" +'[a-zA-Z0-9\-_.]*' + +1F diff --git a/tests/yangre/files/two_patterns_err.txt b/tests/yangre/files/two_patterns_err.txt new file mode 100644 index 0000000..78f9878 --- /dev/null +++ b/tests/yangre/files/two_patterns_err.txt @@ -0,0 +1,4 @@ +"[0-9a-fA-F]*" +'[a-zA-Z0-9\-_.]*' + +@!@ diff --git a/tests/yangre/files/two_patterns_invert_match.txt b/tests/yangre/files/two_patterns_invert_match.txt new file mode 100644 index 0000000..ffbd835 --- /dev/null +++ b/tests/yangre/files/two_patterns_invert_match.txt @@ -0,0 +1,4 @@ +"[a-z]*" + '[a-f]*' + +gh diff --git a/tests/yangre/files/two_patterns_invert_match_err.txt b/tests/yangre/files/two_patterns_invert_match_err.txt new file mode 100644 index 0000000..f182aab --- /dev/null +++ b/tests/yangre/files/two_patterns_invert_match_err.txt @@ -0,0 +1,4 @@ +"[a-z]*" + '[a-f]*' + +ab diff --git a/tests/yangre/invert_match.test b/tests/yangre/invert_match.test new file mode 100644 index 0000000..707ca9d --- /dev/null +++ b/tests/yangre/invert_match.test @@ -0,0 +1,28 @@ +source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/ly.tcl" : "ly.tcl"}] + +test invert_match_from_help1 {Test the first pattern from help via invert match} { + ly_cmd_err {-p {"[0-9a-fA-F]*"} -i {1F}} "not conform to inverted" + ly_cmd {-p {"[0-9a-fA-F]*"} -i {GUN}} +} {} + +test invert_match_from_help2 {Test the second pattern from help via invert match} { + ly_cmd_err {-p {'[a-zA-Z0-9\-_.]*'} -i {a-b}} "not conform to inverted" + ly_cmd {-p {'[a-zA-Z0-9\-_.]*'} -i {%@}} +} {} + +test invert_match_from_help3 {Test the third pattern from help via invert match} { + ly_cmd_err {-p {[xX][mM][lL].*} -i {xml-encoding}} "not conform to inverted" + ly_cmd {-p {[xX][mM][lL].*} -i {json}} +} {} + +test invert_match_three_at_once {Test three inverted patterns and once} { + ly_cmd_err {-p {"[0-9a-zA-Z]*"} -i -p {'[a-zA-Z0-9\-_.]*'} -i -p {[xX][mM][lL].*} -i {xml}} "not conform to inverted" + ly_cmd {-p {"[0-9a-zA-Z]*"} -i -p {'[a-zA-Z0-9\-_.]*'} -i -p {[xX][mM][lL].*} -i {%@}} +} {} + +test invert_match_second_is_not {Test three patterns but the second one is not inverted} { + ly_cmd_err {-p {"[0-9a-zA-Z]*"} -i -p {'[a-zA-Z0-9\-_.]*'} -i -p {[xX][mM][lL].*} -i {o_O}} "not conform to inverted" + ly_cmd {-p {"[0-9a-zA-Z]*"} -i -p {'[a-zA-Z0-9\-_.]*'} -p {[xX][mM][lL].*} -i {o_O}} +} {} + +cleanupTests diff --git a/tests/yangre/ly.tcl b/tests/yangre/ly.tcl new file mode 100644 index 0000000..3bb62b5 --- /dev/null +++ b/tests/yangre/ly.tcl @@ -0,0 +1,17 @@ +# @brief The main source of functions and variables for testing yangre. + +package require tcltest +namespace import ::tcltest::test ::tcltest::cleanupTests + +if { ![info exists ::env(TESTS_DIR)] } { + # the script is not run via 'ctest' so paths must be set + set ::env(TESTS_DIR) "./" + set TUT_PATH "../../build" +} else { + # cmake (ctest) already sets ::env variables + set TUT_PATH $::env(YANGRE) +} +set TUT_NAME "yangre" +source "$::env(TESTS_DIR)/../tool_ni.tcl" + +# The script continues by defining variables and functions specific to the yangre tool. diff --git a/tests/yangre/pattern.test b/tests/yangre/pattern.test new file mode 100644 index 0000000..45b7e3b --- /dev/null +++ b/tests/yangre/pattern.test @@ -0,0 +1,19 @@ +source [expr {[info exists ::env(TESTS_DIR)] ? "$env(TESTS_DIR)/ly.tcl" : "ly.tcl"}] + +test pattern_from_help1 {Test the first pattern from help} { + ly_cmd {-p {"[0-9a-fA-F]*"} {1F}} +} {} + +test pattern_from_help2 {Test the second pattern from help} { + ly_cmd {-p {'[a-zA-Z0-9\-_.]*'} {a-b}} +} {} + +test pattern_from_help3 {Test the third pattern from help} { + ly_cmd {-p {[xX][mM][lL].*} {xml-encoding}} +} {} + +test pattern_three_at_once {Test three patterns and once} { + ly_cmd {-p {"[0-9a-zA-Z]*"} -p {'[a-zA-Z0-9\-_.]*'} -p {[xX][mM][lL].*} {xml}} +} {} + +cleanupTests |