cmdr
Check-in [58cb0c6af7]
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Testing validation types, continued.
Timelines: family | ancestors | descendants | both | vtype-testing
Files: files | file ages | folders
SHA1: 58cb0c6af753d54278729a4abb376eda6991ed5d
User & Date: aku 2015-05-11 22:21:10
Context
2015-05-11
22:28
Merged trunk testsuite fixes. check-in: 133579f38a user: aku tags: vtype-testing
22:21
Testing validation types, continued. check-in: 58cb0c6af7 user: aku tags: vtype-testing
2015-05-09
00:08
Started on testsuite for validation types. Template for the common API signatures. check-in: 52969c8c6f user: andreask tags: vtype-testing
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to tests/v_boolean.test.

    11     11   kt local   support cmdr::validate::common
    12     12   kt local   testing cmdr::validate
    13     13   
    14     14   # # ## ### ##### ######## ############# #####################
    15     15   ## Basic API.
    16     16   
    17     17   set vtype cmdr::validate::boolean
           18  +set vtdef no
    18     19   kt source vtype.tcl
    19     20   
    20     21   # # ## ### ##### ######## ############# #####################
    21         -## Specific behaviour
           22  +## Specific behaviour - validation
           23  +
           24  +test vt-${vtype}-validate-2.0 "$vtype validate, fail" -body {
           25  +    $vtype validate P bogus
           26  +} -returnCodes error -result {Expected a boolean for T "P", got "bogus"}
           27  +
           28  +test vt-${vtype}-validate-2.1 "$vtype validate, ok, true" -body {
           29  +    $vtype validate P yes
           30  +} -result 1
           31  +
           32  +test vt-${vtype}-validate-2.2 "$vtype validate, ok, false" -body {
           33  +    $vtype validate P no
           34  +} -result 0
           35  +
           36  +# # ## ### ##### ######## ############# #####################
           37  +## Specific behaviour - completion
    22     38   
    23     39   # # ## ### ##### ######## ############# #####################
    24     40   cleanupTests
    25     41   return

Added tests/v_double.test.

            1  +# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
            2  +# # ## ### ##### ######## ############# #####################
            3  +## Testing the cmdr::validate package (sub: double).
            4  +
            5  +kt check Tcl     8.5
            6  +kt check tcltest 2
            7  +
            8  +kt require support debug
            9  +kt require support debug::caller
           10  +
           11  +kt local   support cmdr::validate::common
           12  +kt local   testing cmdr::validate
           13  +
           14  +# # ## ### ##### ######## ############# #####################
           15  +## Basic API.
           16  +
           17  +set vtype cmdr::validate::double
           18  +set vtdef 0
           19  +kt source vtype.tcl
           20  +
           21  +# # ## ### ##### ######## ############# #####################
           22  +## Specific behaviour - validation
           23  +
           24  +test vt-${vtype}-validate-2.0 "$vtype validate, fail" -body {
           25  +    $vtype validate P bogus
           26  +} -returnCodes error -result {Expected a double for T "P", got "bogus"}
           27  +
           28  +test vt-${vtype}-validate-2.1 "$vtype validate, fail, strict" -body {
           29  +    $vtype validate P {}
           30  +} -returnCodes error -result {Expected a double for T "P", got ""}
           31  +
           32  +test vt-${vtype}-validate-2.2 "$vtype validate, ok" -body {
           33  +    $vtype validate P 33.33
           34  +} -result 33.33
           35  +
           36  +test vt-${vtype}-validate-2.3 "$vtype validate, ok, int" -body {
           37  +    $vtype validate P 10
           38  +} -result 10
           39  +
           40  +test vt-${vtype}-validate-2.4 "$vtype validate, ok, negative" -body {
           41  +    $vtype validate P -2.5
           42  +} -result -2.5
           43  +
           44  +# # ## ### ##### ######## ############# #####################
           45  +cleanupTests
           46  +return

Added tests/v_identity.test.

            1  +# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
            2  +# # ## ### ##### ######## ############# #####################
            3  +## Testing the cmdr::validate package (sub: identity).
            4  +
            5  +kt check Tcl     8.5
            6  +kt check tcltest 2
            7  +
            8  +kt require support debug
            9  +kt require support debug::caller
           10  +
           11  +kt local   support cmdr::validate::common
           12  +kt local   testing cmdr::validate
           13  +
           14  +# # ## ### ##### ######## ############# #####################
           15  +## Basic API.
           16  +
           17  +set vtype cmdr::validate::identity
           18  +set vtdef {}
           19  +kt source vtype.tcl
           20  +
           21  +# # ## ### ##### ######## ############# #####################
           22  +## Specific behaviour
           23  +
           24  +# # ## ### ##### ######## ############# #####################
           25  +cleanupTests
           26  +return

Added tests/v_integer.test.

            1  +# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
            2  +# # ## ### ##### ######## ############# #####################
            3  +## Testing the cmdr::validate package (sub: integer).
            4  +
            5  +kt check Tcl     8.5
            6  +kt check tcltest 2
            7  +
            8  +kt require support debug
            9  +kt require support debug::caller
           10  +
           11  +kt local   support cmdr::validate::common
           12  +kt local   testing cmdr::validate
           13  +
           14  +# # ## ### ##### ######## ############# #####################
           15  +## Basic API.
           16  +
           17  +set vtype cmdr::validate::integer
           18  +set vtdef 0
           19  +kt source vtype.tcl
           20  +
           21  +# # ## ### ##### ######## ############# #####################
           22  +## Specific behaviour - validation
           23  +
           24  +test vt-${vtype}-validate-2.0 "$vtype validate, fail" -body {
           25  +    $vtype validate P bogus
           26  +} -returnCodes error -result {Expected an integer for T "P", got "bogus"}
           27  +
           28  +test vt-${vtype}-validate-2.1 "$vtype validate, fail, strict" -body {
           29  +    $vtype validate P {}
           30  +} -returnCodes error -result {Expected an integer for T "P", got ""}
           31  +
           32  +test vt-${vtype}-validate-2.2 "$vtype validate, ok, decimal" -body {
           33  +    $vtype validate P 33
           34  +} -result 33
           35  +
           36  +test vt-${vtype}-validate-2.3 "$vtype validate, ok, octal" -body {
           37  +    $vtype validate P 010
           38  +} -result 8
           39  +
           40  +test vt-${vtype}-validate-2.4 "$vtype validate, ok, hex" -body {
           41  +    $vtype validate P 0xff
           42  +} -result 255
           43  +
           44  +test vt-${vtype}-validate-2.5 "$vtype validate, ok, negative" -body {
           45  +    $vtype validate P -2
           46  +} -result -2
           47  +
           48  +# # ## ### ##### ######## ############# #####################
           49  +cleanupTests
           50  +return

Added tests/v_percent.test.

            1  +# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
            2  +# # ## ### ##### ######## ############# #####################
            3  +## Testing the cmdr::validate package (sub: percent).
            4  +
            5  +kt check Tcl     8.5
            6  +kt check tcltest 2
            7  +
            8  +kt require support debug
            9  +kt require support debug::caller
           10  +
           11  +kt local   support cmdr::validate::common
           12  +kt local   testing cmdr::validate
           13  +
           14  +# # ## ### ##### ######## ############# #####################
           15  +## Basic API.
           16  +
           17  +set vtype cmdr::validate::percent
           18  +set vtdef 0
           19  +kt source vtype.tcl
           20  +
           21  +# # ## ### ##### ######## ############# #####################
           22  +## Specific behaviour - validation
           23  +
           24  +test vt-${vtype}-validate-2.0 "$vtype validate, fail" -body {
           25  +    $vtype validate P bogus
           26  +} -returnCodes error -result {Expected a percentage for T "P", got "bogus"}
           27  +
           28  +test vt-${vtype}-validate-2.1 "$vtype validate, fail, strict" -body {
           29  +    $vtype validate P {}
           30  +} -returnCodes error -result {Expected a percentage for T "P", got ""}
           31  +
           32  +test vt-${vtype}-validate-2.2 "$vtype validate, fail range, up" -body {
           33  +    $vtype validate P 101
           34  +} -returnCodes error -result {Expected a percentage for T "P", got "101"}
           35  +
           36  +test vt-${vtype}-validate-2.3 "$vtype validate, fail range, low" -body {
           37  +    $vtype validate P -0.5
           38  +} -returnCodes error -result {Expected a percentage for T "P", got "-0.5"}
           39  +
           40  +test vt-${vtype}-validate-2.4 "$vtype validate, ok" -body {
           41  +    $vtype validate P 33
           42  +} -result 33
           43  +
           44  +test vt-${vtype}-validate-2.5 "$vtype validate, ok, fractional" -body {
           45  +    $vtype validate P 50.3
           46  +} -result 50.3
           47  +
           48  +# # ## ### ##### ######## ############# #####################
           49  +## Specific behaviour
           50  +
           51  +# # ## ### ##### ######## ############# #####################
           52  +cleanupTests
           53  +return

Added tests/v_rdir.test.

            1  +# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
            2  +# # ## ### ##### ######## ############# #####################
            3  +## Testing the cmdr::validate package (sub: rdirectory).
            4  +
            5  +kt check Tcl     8.5
            6  +kt check tcltest 2
            7  +
            8  +kt require support debug
            9  +kt require support debug::caller
           10  +
           11  +kt local   support cmdr::validate::common
           12  +kt local   testing cmdr::validate
           13  +
           14  +# # ## ### ##### ######## ############# #####################
           15  +## Basic API.
           16  +
           17  +set vtype cmdr::validate::rdirectory
           18  +set vtdef {}
           19  +kt source vtype.tcl
           20  +
           21  +# # ## ### ##### ######## ############# #####################
           22  +## Specific behaviour
           23  +
           24  +# # ## ### ##### ######## ############# #####################
           25  +cleanupTests
           26  +return

Added tests/v_rfile.test.

            1  +# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
            2  +# # ## ### ##### ######## ############# #####################
            3  +## Testing the cmdr::validate package (sub: rfile).
            4  +
            5  +kt check Tcl     8.5
            6  +kt check tcltest 2
            7  +
            8  +kt require support debug
            9  +kt require support debug::caller
           10  +
           11  +kt local   support cmdr::validate::common
           12  +kt local   testing cmdr::validate
           13  +
           14  +# # ## ### ##### ######## ############# #####################
           15  +## Basic API.
           16  +
           17  +set vtype cmdr::validate::rfile
           18  +set vtdef {}
           19  +kt source vtype.tcl
           20  +
           21  +# # ## ### ##### ######## ############# #####################
           22  +## Specific behaviour
           23  +
           24  +# # ## ### ##### ######## ############# #####################
           25  +cleanupTests
           26  +return

Added tests/v_rwdir.test.

            1  +# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
            2  +# # ## ### ##### ######## ############# #####################
            3  +## Testing the cmdr::validate package (sub: rwdirectory).
            4  +
            5  +kt check Tcl     8.5
            6  +kt check tcltest 2
            7  +
            8  +kt require support debug
            9  +kt require support debug::caller
           10  +
           11  +kt local   support cmdr::validate::common
           12  +kt local   testing cmdr::validate
           13  +
           14  +# # ## ### ##### ######## ############# #####################
           15  +## Basic API.
           16  +
           17  +set vtype cmdr::validate::rwdirectory
           18  +set vtdef {}
           19  +kt source vtype.tcl
           20  +
           21  +# # ## ### ##### ######## ############# #####################
           22  +## Specific behaviour
           23  +
           24  +# # ## ### ##### ######## ############# #####################
           25  +cleanupTests
           26  +return

Added tests/v_rwfile.test.

            1  +# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
            2  +# # ## ### ##### ######## ############# #####################
            3  +## Testing the cmdr::validate package (sub: rwfile).
            4  +
            5  +kt check Tcl     8.5
            6  +kt check tcltest 2
            7  +
            8  +kt require support debug
            9  +kt require support debug::caller
           10  +
           11  +kt local   support cmdr::validate::common
           12  +kt local   testing cmdr::validate
           13  +
           14  +# # ## ### ##### ######## ############# #####################
           15  +## Basic API.
           16  +
           17  +set vtype cmdr::validate::rwfile
           18  +set vtdef {}
           19  +kt source vtype.tcl
           20  +
           21  +# # ## ### ##### ######## ############# #####################
           22  +## Specific behaviour
           23  +
           24  +# # ## ### ##### ######## ############# #####################
           25  +cleanupTests
           26  +return

Added tests/v_wfile.test.

            1  +# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
            2  +# # ## ### ##### ######## ############# #####################
            3  +## Testing the cmdr::validate package (sub: wfile).
            4  +
            5  +kt check Tcl     8.5
            6  +kt check tcltest 2
            7  +
            8  +kt require support debug
            9  +kt require support debug::caller
           10  +
           11  +kt local   support cmdr::validate::common
           12  +kt local   testing cmdr::validate
           13  +
           14  +# # ## ### ##### ######## ############# #####################
           15  +## Basic API.
           16  +
           17  +set vtype cmdr::validate::wfile
           18  +set vtdef {}
           19  +kt source vtype.tcl
           20  +
           21  +# # ## ### ##### ######## ############# #####################
           22  +## Specific behaviour
           23  +
           24  +# # ## ### ##### ######## ############# #####################
           25  +cleanupTests
           26  +return

Changes to tests/vtype.tcl.

     6      6   # ensemble command of the validation type. This file only tests the
     7      7   # standard part of the API for the type, i.e. the command
     8      8   # signatures. The actual validation, completion, etc. must be tested
     9      9   # by the caller, as that changes from type to type.
    10     10   #
    11     11   # File API variables
    12     12   #
    13         -# - "vtype"  - command for the validation type.
    14         -# - "vtparm" - name of the parameter variable used by all VT API commands.
    15         -# - "vtval"  - name of the value variable used by the all VT API commands except "default".
           13  +# - "vtype"  - Command for the validation type.
           14  +# - "vtdef"  - Default value of the validation type.
           15  +# - "vtparm" - Name of the parameter variable used by all VT API commands.
           16  +# - "vtval"  - Name of the value variable used by the all VT API commands except "default".
    16     17   #
    17     18   # The last two can be left unspecified, and will default to "p" and "x", respectively.
           19  +# The first two must be defined.
    18     20   
    19     21   if {![info exists vtparm]} { set vtparm p }
    20     22   if {![info exists vtval]}  { set vtval  x }
    21     23   
    22     24   if {![info exists vtype]} {
    23     25       # TODO: kt ... - Abort testsuite
    24     26   }
           27  +
           28  +if {![info exists vtdef]} {
           29  +    # TODO: kt ... - Abort testsuite
           30  +}
           31  +
           32  +# # ## ### ##### ######## ############# #####################
           33  +## Pseudo/Fake parameter object to satisfy a validation type.
           34  +## More specifically the command used inside to generate failure
           35  +## messages.
           36  +
           37  +namespace eval P {
           38  +    namespace export type the-name
           39  +    namespace ensemble create
           40  +    proc type     {} { return T }
           41  +    proc the-name {} { return P }
           42  +}
    25     43   
    26     44   # # ## ### ##### ######## ############# #####################
    27     45   ## default
    28     46   
    29     47   test vt-${vtype}-default-1.0 "$vtype default, wrong args, not enough" -body {
    30     48       $vtype default
    31     49   } -returnCodes error -result "wrong # args: should be \"$vtype default $vtparm\""
    32     50   
    33     51   test vt-${vtype}-default-1.1 "$vtype default, wrong args, too many" -body {
    34     52       $vtype default P X
    35     53   } -returnCodes error -result "wrong # args: should be \"$vtype default $vtparm\""
           54  +
           55  +test vt-${vtype}-default-2.0 "$vtype default, value" -body {
           56  +    $vtype default P
           57  +} -result $vtdef
    36     58   
    37     59   # # ## ### ##### ######## ############# #####################
    38     60   ## validate
    39     61   
    40     62   test vt-${vtype}-validate-1.0 "$vtype validate, wrong args, not enough" -body {
    41     63       $vtype validate
    42     64   } -returnCodes error -result "wrong # args: should be \"$vtype validate $vtparm $vtval\""