Skip to content

Commit

Permalink
test: Add cmake func to automatically set bintype label
Browse files Browse the repository at this point in the history
  • Loading branch information
abelcheung committed Dec 12, 2023
1 parent 9f82642 commit 6701e57
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 67 deletions.
27 changes: 27 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
81 changes: 27 additions & 54 deletions test/cmake/cli-option.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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 )
Expand All @@ -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 -/)
Expand All @@ -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 "," )
Expand Down Expand Up @@ -103,34 +97,23 @@ 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)
add_test(NAME d_BadComboOptTest${name} COMMAND
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:)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
17 changes: 7 additions & 10 deletions test/cmake/read-write.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)


#
Expand Down
5 changes: 2 additions & 3 deletions test/cmake/xml.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 6701e57

Please sign in to comment.