1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
##########################################################################
# TEPAM - Tcl's Enhanced Procedure and Argument Manager
##########################################################################
#
# proc_call_arg_valid.test
# This file is part of the enhanced procedure and argument manager's regression
# test. It validates the declaration and call of the procedure sub commands.
#
# Copyright (C) 2009, 2010 Andreas Drollinger
#
# Id: proc_call_arg_valid.test
##########################################################################
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
##########################################################################
source [file join \
[file dirname [file dirname [file join [pwd] [info script]]]] \
devtools testutilities.tcl]
testsNeedTcl 8.5
testsNeedTcltest 1.0
catch {namespace delete ::tepam}
testing {
useLocal tepam.tcl tepam
}
# Tests is an extension of the test command. It adds the option -variations that allows \
# specifying a list values. For each of these values the test command is executed, replacing all '%1'
# of the original test command string by the altered value.
proc tests {name description args} {
set VariationList(0) {""}; # Default variation list 0, in case no variations are required
for {set NbrVariationLists 0} {1} {incr NbrVariationLists} {
set VariationListPos [lsearch -exact $args -variations]
if {$VariationListPos<0} break
set VariationList($NbrVariationLists) [lindex $args [expr $VariationListPos+1]]
set args [lreplace $args $VariationListPos [expr $VariationListPos+1]]
}
for {set TestNbr 0} {$TestNbr<[llength $VariationList(0)]} {incr TestNbr} {
set TestExec "test \"$name\.$TestNbr\" \"$description.$TestNbr\""
foreach Arg $args {
set NewArg $Arg
for {set vl 0} {$vl<$NbrVariationLists} {incr vl} {
regsub -all "%[expr $vl+1]" $NewArg [lindex $VariationList($vl) $TestNbr] NewArg
}
append TestExec " \{$NewArg\}"
}
uplevel 1 $TestExec
}
}
######## Validation through choice lists ########
tepam::procedure Value_Is_Pair {
-args {
{-int -type integer -optional -choices {2 4 6 8 10}}
{-double -type double -optional -choices {2.0 4.0 6.0 8.0 10.0}}
{-m_int -type integer -optional -multiple -choices {2 4 6 8 10}}
{-m_double -type double -optional -multiple -choices {2.0 4.0 6.0 8.0 10.0}}
}
} {
}
# Choice list based argument check
# Simple parameters
tests tepam-argval.choic1.int1 "tepam, Choice list based argument check - simple parameters" \
-variations {2 4 8 10} \
-body {Value_Is_Pair -int %1} \
-result "" -output ""
tests tepam-argval.choic1.int2 "tepam, Choice list based argument check - simple parameters" \
-variations {0 1 3 9 11} \
-body {Value_Is_Pair -int %1} \
-returnCodes error -result "*Argument 'int' has to be one of the following elements:*" -output "" -match glob
tests tepam-argval.choic1.double1 "tepam, Choice list based argument check - simple parameters" \
-variations {2.0 4.0 8.0 10.0} \
-body {Value_Is_Pair -double %1} \
-result "" -output ""
tests tepam-argval.choic1.double2 "tepam, Choice list based argument check - simple parameters" \
-variations {0 0.5 1 3 9 9.5 11} \
-body {Value_Is_Pair -double %1} \
-returnCodes error -result "*Argument 'double' has to be one of the following elements:*" -output "" -match glob
# Multiple parameters
tests tepam-argval.choic2.int1 "tepam, Choice list based argument check - multiple parameters" \
-variations {2 4 8 10} \
-body {Value_Is_Pair -m_int %1 -m_int %1} \
-result "" -output ""
tests tepam-argval.choic2.int2 "tepam, Choice list based argument check - multiple parameters" \
-variations {0 1 3 9 11} \
-body {Value_Is_Pair -m_int %1 -m_int %1} \
-returnCodes error -result "*Argument 'm_int' has to be one of the following elements:*" -output "" -match glob
tests tepam-argval.choic2.double1 "tepam, Choice list based argument check - multiple parameters" \
-variations {2.0 4.0 8.0 10.0} \
-body {Value_Is_Pair -m_double %1 -m_double %1} \
-result "" -output ""
tests tepam-argval.choic2.double2 "tepam, Choice list based argument check - multiple parameters" \
-variations {0 0.5 1 3 9 9.5 11} \
-body {Value_Is_Pair -m_double %1 -m_double %1} \
-returnCodes error -result "*Argument 'm_double' has to be one of the following elements:*" -output "" -match glob
######## Validation through ranges ########
tepam::procedure Value_Is_Medium {
-args {
{-int -type integer -optional -range {4 6}}
{-double -type double -optional -range {4 6}}
{-m_int -type integer -optional -multiple -range {4 6}}
{-m_double -type double -optional -multiple -range {4 6}}
}
} {
}
# Range based argument check
# Simple parameters
tests tepam-argval.range1.int1 "tepam, Range based argument check - simple parameters" \
-variations {4 5 6} \
-body {Value_Is_Medium -int %1} \
-result "" -output ""
tests tepam-argval.range1.int2 "tepam, Range based argument check - simple parameters" \
-variations {1 0 7 8} \
-body {Value_Is_Medium -int %1} \
-returnCodes error -result "*Argument 'int' has to be between*" -output "" -match glob
tests tepam-argval.range1.double1 "tepam, Range based argument check - simple parameters" \
-variations {4 5 6} \
-body {Value_Is_Medium -double %1} \
-result "" -output ""
tests tepam-argval.range1.double2 "tepam, Range based argument check - simple parameters" \
-variations {1 1.9 6.1 7 8} \
-body {Value_Is_Medium -double %1} \
-returnCodes error -result "*Argument 'double' has to be between*" -output "" -match glob
# Multiple parameters
tests tepam-argval.range2.int1 "tepam, Range based argument check - multiple parameters" \
-variations {4 5 6} \
-body {Value_Is_Medium -m_int %1 -m_int %1} \
-result "" -output ""
tests tepam-argval.range2.int2 "tepam, Range based argument check - multiple parameters" \
-variations {1 0 7 8} \
-body {Value_Is_Medium -m_int %1 -m_int %1} \
-returnCodes error -result "*Argument 'm_int' has to be between*" -output "" -match glob
tests tepam-argval.range2.double1 "tepam, Range based argument check - multiple parameters" \
-variations {4 5 6} \
-body {Value_Is_Medium -m_double %1 -m_double %1} \
-result "" -output ""
tests tepam-argval.range2.double2 "tepam, Range based argument check - multiple parameters" \
-variations {1 1.9 6.1 7 8} \
-body {Value_Is_Medium -m_double %1 -m_double %1} \
-returnCodes error -result "*Argument 'm_double' has to be between*" -output "" -match glob
######## User specified argument validation, validation command ########
proc StringLength_Is_3 {Value} {
return [expr [string length $Value]==3]
}
tepam::procedure AllTypeProcedure {
-args {
{-string_size_3 -type string -optional -validatecommand "StringLength_Is_3 %P"}
{-integer_size_3 -type integer -optional -validatecommand "StringLength_Is_3 %P"}
{-nonvalid -optional -validatecommand "expr 0"}
{-valid -optional -validatecommand "expr 1"}
{-m_string_size_3 -type string -optional -multiple -validatecommand "StringLength_Is_3 %P"}
{-m_integer_size_3 -type integer -optional -multiple -validatecommand "StringLength_Is_3 %P"}
{-m_nonvalid -optional -multiple -validatecommand "expr 0"}
{-m_valid -optional -multiple -validatecommand "expr 1"}
}
} {
}
# Validation command based argument check
# Simple parameters
tests tepam-argval.user1.1 "tepam, User command based argument check - simple parameters" \
-variations {ab abcd} \
-body {AllTypeProcedure -string_size_3 %1} \
-returnCodes error -result "*Argument * is invalid.*" -output "" -match glob
tests tepam-argval.user1.2 "tepam, User command based argument check - simple parameters" \
-variations {abc 123} \
-body {AllTypeProcedure -string_size_3 %1} \
-result "" -output ""
tests tepam-argval.user1.3 "tepam, User command based argument check - simple parameters" \
-variations {12 1234} \
-body {AllTypeProcedure -integer_size_3 %1} \
-returnCodes error -result "*Argument * is invalid.*" -output "" -match glob
tests tepam-argval.user1.4 "tepam, User command based argument check - simple parameters" \
-variations {123} \
-body {AllTypeProcedure -integer_size_3 %1} \
-result "" -output ""
tests tepam-argval.user1.5 "tepam, User command based argument check - simple parameters" \
-variations {1a3} \
-body {AllTypeProcedure -integer_size_3 %1} \
-returnCodes error -result "*requires type 'integer'*" -output "" -match glob
tests tepam-argval.user1.6 "tepam, User command based argument check - simple parameters" \
-variations {abc 123} \
-body {AllTypeProcedure -nonvalid %1} \
-returnCodes error -result "*Argument * is invalid.*" -output "" -match glob
tests tepam-argval.user1.7 "tepam, User command based argument check - simple parameters" \
-variations {abc 123} \
-body {AllTypeProcedure -valid %1} \
-result "" -output ""
# Multiple parameters"
tests tepam-argval.user2.1 "tepam, User command based argument check - simple parameters" \
-variations {ab abcd} \
-body {AllTypeProcedure -m_string_size_3 %1 -m_string_size_3 %1} \
-returnCodes error -result "*Argument * is invalid.*" -output "" -match glob
tests tepam-argval.user2.2 "tepam, User command based argument check - simple parameters" \
-variations {abc 123} \
-body {AllTypeProcedure -m_string_size_3 %1 -m_string_size_3 %1} \
-result "" -output ""
tests tepam-argval.user2.3 "tepam, User command based argument check - simple parameters" \
-variations {12 1234} \
-body {AllTypeProcedure -m_integer_size_3 %1 -m_integer_size_3 %1} \
-returnCodes error -result "*Argument * is invalid.*" -output "" -match glob
tests tepam-argval.user2.4 "tepam, User command based argument check - simple parameters" \
-variations {123} \
-body {AllTypeProcedure -m_integer_size_3 %1 -m_integer_size_3 %1} \
-result "" -output ""
tests tepam-argval.user2.5 "tepam, User command based argument check - simple parameters" \
-variations {1a3} \
-body {AllTypeProcedure -m_integer_size_3 %1 -m_integer_size_3 %1} \
-returnCodes error -result "*requires type 'integer'*" -output "" -match glob
tests tepam-argval.user2.6 "tepam, User command based argument check - simple parameters" \
-variations {abc 123} \
-body {AllTypeProcedure -m_nonvalid %1 -m_nonvalid %1} \
-returnCodes error -result "*Argument * is invalid.*" -output "" -match glob
tests tepam-argval.user2.7 "tepam, User command based argument check - simple parameters" \
-variations {abc 123} \
-body {AllTypeProcedure -m_valid %1 -m_valid %1} \
-result "" -output ""
######## That's all ########
::tcltest::cleanupTests
return
##########################################################################
# Id: proc_call_arg_valid.test
# Modifications:
#
# Revision 1.2 2013/10/14 droll
# * Adapted the expected error message to the changes made inside tepam.tcl
#
# Revision 1.1 2010/02/11 21:50:55 droll
# * TEPAM module checkin
##########################################################################
|