From 6701e576409c584d7ba54a44300c8e86e5076724 Mon Sep 17 00:00:00 2001 From: Abel Cheung Date: Tue, 12 Dec 2023 13:57:15 +0800 Subject: [PATCH] test: Add cmake func to automatically set bintype label --- test/CMakeLists.txt | 27 +++++++++++++ test/cmake/cli-option.cmake | 81 +++++++++++++------------------------ test/cmake/read-write.cmake | 17 ++++---- test/cmake/xml.cmake | 5 +-- 4 files changed, 63 insertions(+), 67 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ac6fb66..bb718a1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -40,6 +40,33 @@ function(startswith haystack needle) endif() endfunction() +function(add_bintype_label testname) + foreach(tname ${testname} ${ARGN}) + if(NOT TEST ${tname}) + message(WARNING "Test name ${tname} does not exist") + continue() + endif() + startsWith(${tname} "f_") + if(startswith_match) + set(bintype "info2") + endif() + startsWith(${tname} "d_") + if(startswith_match) + set(bintype "recycledir") + endif() + if(NOT DEFINED bintype) + message(WARNING "Unable to determine bin type from name ${tname}") + continue() + endif() + get_property(tlabels TEST ${tname} PROPERTY LABELS) + list(FIND tlabels ${bintype} pos) + if (pos EQUAL -1) + list(APPEND tlabels ${bintype}) + set_tests_properties(${tname} PROPERTIES LABELS "${tlabels}") + endif() + endforeach() +endfunction() + # # Set fixture properties automatically for a fixed test name pattern. # Fixture dependencies are set up automatically too. diff --git a/test/cmake/cli-option.cmake b/test/cmake/cli-option.cmake index e027de0..1428706 100644 --- a/test/cmake/cli-option.cmake +++ b/test/cmake/cli-option.cmake @@ -5,11 +5,12 @@ function(addBareOptTest name) add_test(NAME d_InvokeOpt${name} COMMAND rifiuti-vista ${ARGV1}) add_test(NAME f_InvokeOpt${name} COMMAND rifiuti ${ARGV1}) - set_tests_properties(d_InvokeOpt${name} PROPERTIES LABELS "recycledir;arg") - set_tests_properties(f_InvokeOpt${name} PROPERTIES LABELS "info2;arg") + set_tests_properties(d_InvokeOpt${name} f_InvokeOpt${name} + PROPERTIES LABELS "arg") + add_bintype_label(d_InvokeOpt${name} f_InvokeOpt${name}) if(NOT DEFINED ARGV1 AND WIN32) - set_tests_properties(d_InvokeOpt${name} PROPERTIES DISABLED True) - set_tests_properties(f_InvokeOpt${name} PROPERTIES DISABLED True) + set_tests_properties(d_InvokeOpt${name} f_InvokeOpt${name} + PROPERTIES DISABLED True) endif() endfunction() @@ -19,17 +20,16 @@ addBareOptTest(ShortHelp2 -? ) addBareOptTest(ShortVer -v ) addBareOptTest(LongHelp --help-all ) addBareOptTest(LongVer --version ) -# if(WIN32) -# addBareOptTest(Live --live ) -# endif() + function(addWithFileOptTest name) add_test(NAME d_WithFileOpt${name} COMMAND rifiuti-vista ${ARGN} ${sample_dir}/dir-sample1) add_test(NAME f_WithFileOpt${name} COMMAND rifiuti ${ARGN} ${sample_dir}/INFO2-sample1) - set_tests_properties(d_WithFileOpt${name} PROPERTIES LABELS "recycledir;arg") - set_tests_properties(f_WithFileOpt${name} PROPERTIES LABELS "info2;arg") + set_tests_properties(d_WithFileOpt${name} f_WithFileOpt${name} + PROPERTIES LABELS "arg") + add_bintype_label(d_WithFileOpt${name} f_WithFileOpt${name}) endfunction() addWithFileOptTest(LongHead --no-heading ) @@ -45,14 +45,11 @@ addWithFileOptTest(ShortXml -x ) function(addBadBareOptTest name) add_test(NAME d_BadBareOpt${name} COMMAND rifiuti-vista ${ARGN}) add_test(NAME f_BadBareOpt${name} COMMAND rifiuti ${ARGN}) - set_tests_properties(d_BadBareOpt${name} - PROPERTIES - LABELS "recycledir;arg;xfail" - PASS_REGULAR_EXPRESSION "Unknown option") - set_tests_properties(f_BadBareOpt${name} + set_tests_properties(d_BadBareOpt${name} f_BadBareOpt${name} PROPERTIES - LABELS "info2;arg;xfail" + LABELS "arg;xfail" PASS_REGULAR_EXPRESSION "Unknown option") + add_bintype_label(d_BadBareOpt${name} f_BadBareOpt${name}) endfunction() addBadBareOptTest(Short -/) @@ -64,14 +61,11 @@ function(addDupOptTest name) rifiuti-vista ${ARGN} ${sample_dir}/dir-sample1) add_test(NAME f_DupOpt${name} COMMAND rifiuti ${ARGN} ${sample_dir}/INFO2-sample1) - set_tests_properties(d_DupOpt${name} - PROPERTIES - LABELS "recycledir;arg;xfail" - PASS_REGULAR_EXPRESSION "Multiple .+ disallowed") - set_tests_properties(f_DupOpt${name} + set_tests_properties(d_DupOpt${name} f_DupOpt${name} PROPERTIES - LABELS "info2;arg;xfail" + LABELS "arg;xfail" PASS_REGULAR_EXPRESSION "Multiple .+ disallowed") + add_bintype_label(d_DupOpt${name} f_DupOpt${name}) endfunction() addDupOptTest(ShortSep -t ":" -t "," ) @@ -103,17 +97,11 @@ add_test(NAME f_NullArgOptTestOut COMMAND rifiuti -o "" ${sample_dir}/INFO2-sample1) add_test(NAME f_NullArgOptTestEnc COMMAND rifiuti -l "" ${sample_dir}/INFO2-sample1) -set_tests_properties( - d_NullArgOptTestOut - PROPERTIES - LABELS "recycledir;arg;xfail" - PASS_REGULAR_EXPRESSION "Empty .+ disallowed") -set_tests_properties( - f_NullArgOptTestOut - f_NullArgOptTestEnc +set_tests_properties(d_NullArgOptTestOut f_NullArgOptTestOut f_NullArgOptTestEnc PROPERTIES - LABELS "info2;arg;xfail" + LABELS "arg;xfail" PASS_REGULAR_EXPRESSION "Empty .+ disallowed") +add_bintype_label(d_NullArgOptTestOut f_NullArgOptTestOut f_NullArgOptTestEnc) function(addBadComboOptTest name) @@ -121,16 +109,11 @@ function(addBadComboOptTest name) rifiuti-vista ${ARGN} ${sample_dir}/dir-sample1) add_test(NAME f_BadComboOptTest${name} COMMAND rifiuti ${ARGN} ${sample_dir}/INFO2-sample1) - set_tests_properties( - d_BadComboOptTest${name} - PROPERTIES - LABELS "recycledir;arg;xfail" - PASS_REGULAR_EXPRESSION "can not be used in XML mode") - set_tests_properties( - f_BadComboOptTest${name} + set_tests_properties(d_BadComboOptTest${name} f_BadComboOptTest${name} PROPERTIES - LABELS "info2;arg;xfail" + LABELS "arg;xfail" PASS_REGULAR_EXPRESSION "can not be used in XML mode") + add_bintype_label(d_BadComboOptTest${name} f_BadComboOptTest${name}) endfunction() addBadComboOptTest(1 -x -t:) @@ -140,16 +123,11 @@ addBadComboOptTest(2 -n -x) function(addMultiInputTest name) add_test(NAME d_MultiInputTest${name} COMMAND rifiuti-vista ${ARGN}) add_test(NAME f_MultiInputTest${name} COMMAND rifiuti ${ARGN}) - set_tests_properties( - d_MultiInputTest${name} + set_tests_properties(d_MultiInputTest${name} f_MultiInputTest${name} PROPERTIES - LABELS "recycledir;arg;xfail" - PASS_REGULAR_EXPRESSION "Must specify exactly one") - set_tests_properties( - f_MultiInputTest${name} - PROPERTIES - LABELS "info2;arg;xfail" + LABELS "arg;xfail" PASS_REGULAR_EXPRESSION "Must specify exactly one") + add_bintype_label(d_MultiInputTest${name} f_MultiInputTest${name}) endfunction() addMultiInputTest(1 a a) @@ -159,16 +137,11 @@ addMultiInputTest(2 foo bar baz) function(addMissingInputTest name) add_test(NAME d_MissingInputTest${name} COMMAND rifiuti-vista ${ARGN}) add_test(NAME f_MissingInputTest${name} COMMAND rifiuti ${ARGN}) - set_tests_properties( - d_MissingInputTest${name} - PROPERTIES - LABELS "recycledir;arg;xfail" - PASS_REGULAR_EXPRESSION "Must specify exactly one") - set_tests_properties( - f_MissingInputTest${name} + set_tests_properties(d_MissingInputTest${name} f_MissingInputTest${name} PROPERTIES - LABELS "info2;arg;xfail" + LABELS "arg;xfail" PASS_REGULAR_EXPRESSION "Must specify exactly one") + add_bintype_label(d_MissingInputTest${name} f_MissingInputTest${name}) endfunction() addMissingInputTest(1 -x) diff --git a/test/cmake/read-write.cmake b/test/cmake/read-write.cmake index 8720980..7927b41 100644 --- a/test/cmake/read-write.cmake +++ b/test/cmake/read-write.cmake @@ -9,14 +9,12 @@ add_test(NAME d_InputNotExist COMMAND rifiuti-vista dUmMy) add_test(NAME f_InputNotExist COMMAND rifiuti dUmMy) -set_tests_properties(d_InputNotExist +set_tests_properties(d_InputNotExist f_InputNotExist PROPERTIES - LABELS "recycledir;xfail" - PASS_REGULAR_EXPRESSION "does not exist") -set_tests_properties(f_InputNotExist - PROPERTIES - LABELS "info2;xfail" + LABELS "xfail" PASS_REGULAR_EXPRESSION "does not exist") +add_bintype_label(d_InputNotExist f_InputNotExist) + # # Special file @@ -28,20 +26,19 @@ set_tests_properties(f_InputNotExist if(WIN32) add_test(NAME d_InputSpecialFile COMMAND rifiuti-vista nul) add_test(NAME f_InputSpecialFile COMMAND rifiuti nul) -set_tests_properties(d_InputSpecialFile PROPERTIES LABELS "recycledir;xfail") -set_tests_properties(f_InputSpecialFile PROPERTIES LABELS "info2;xfail") set_tests_properties(d_InputSpecialFile f_InputSpecialFile PROPERTIES + LABELS "xfail" PASS_REGULAR_EXPRESSION "File is prematurely truncated, or not .+ index") else() add_test(NAME d_InputSpecialFile COMMAND rifiuti-vista /dev/null) add_test(NAME f_InputSpecialFile COMMAND rifiuti /dev/null) -set_tests_properties(d_InputSpecialFile PROPERTIES LABELS "recycledir;xfail") -set_tests_properties(f_InputSpecialFile PROPERTIES LABELS "info2;xfail") set_tests_properties(d_InputSpecialFile f_InputSpecialFile PROPERTIES + LABELS "xfail" PASS_REGULAR_EXPRESSION "not a normal file") endif() +add_bintype_label(d_InputSpecialFile f_InputSpecialFile) # diff --git a/test/cmake/xml.cmake b/test/cmake/xml.cmake index 8df4d7f..30003f9 100644 --- a/test/cmake/xml.cmake +++ b/test/cmake/xml.cmake @@ -17,12 +17,10 @@ function(createXmlTestSet id input) # $ARGN as extra rifiuti args endif() if(IS_DIRECTORY ${inputchk}) set(is_info2 0) - set(add_label "recycledir") set(prog rifiuti-vista) set(prefix "d_Xml${id}") else() set(is_info2 1) - set(add_label "info2") set(prog rifiuti) set(prefix "f_Xml${id}") endif() @@ -59,7 +57,8 @@ function(createXmlTestSet id input) # $ARGN as extra rifiuti args set_tests_properties(${dtdvalid_pfx} PROPERTIES FIXTURES_REQUIRED ${wellform_fxt}) set_tests_properties(${wellform_pfx} ${dtdvalid_pfx} - PROPERTIES LABELS "${add_label};xml") + PROPERTIES LABELS "xml") + add_bintype_label(${wellform_pfx} ${dtdvalid_pfx}) # XML normalization and comparison # xmllint has a long known history of broken --output option,