yangre TEST testing yangre via tcl scripts
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 6b6bd72..259ef34 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -46,6 +46,7 @@
add_subdirectory(fuzz)
endif()
add_subdirectory(yanglint)
+ add_subdirectory(yangre)
endif()
if(ENABLE_PERF_TESTS)
add_subdirectory(perf)
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/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.