# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4 package require tcltest 2 namespace import tcltest::* source ../macports_test_autoconf.tcl package require macports 1.0 test method_wrap { Method wrap unit test. } -setup { proc test_proc {a} { if { $a == 1} { return -code error $a -errorcode 7 } else { return $a } } } -body { macports_util::method_wrap test_proc if {[test_proc 1] != 7} { return "FAIL: no wrap around method" } if {[test_proc arg] ne "arg"} { return "FAIL: no wrap around method" } return "Method wrap successful." } -result "Method wrap successful." test ldindex { Ldindex unit test. } -body { set list {0 1 2 3} if {[ldindex list 1] != 1} { return "FAIL: element not poped" } if {$list != {0 2 3}} { return "FAIL: wrong list remaining" } if {[catch {ldindex list 4}] != 1} { return "FAIL: error not detected" } if {[ldindex list] != {0 2 3}} { return "FAIL: not all elements poped" } if {$list ne ""} { return "FAIL: list not emptied" } return "ldindex successful." } -result "ldindex successful." test lpop { Lpop unit test. } -body { set list {0 1 2} if {[lpop list] != 2} { return "FAIL: element not poped" } if {$list != {0 1}} { return "FAIL: wrong element poped" } return "lpop successful." } -result "lpop successful." test lpush { Lpush unit test. } -body { set list {0 1} if {[lpush list 2] != {0 1 2}} { return "FAIL: element not appended" } if {[lpush list 3 4] != {0 1 2 3 4}} { return "FAIL: multiple elements not appended" } if {[lpush list1 0] != 0} { return "FAIL: list not created" } return "lpop successful." } -result "lpop successful." test lshift { Lshift unit test. } -body { set list {0 1 2} set list1 {} if {[lshift list] != 0} { return "FAIL: wrong element poped" } if {$list != {1 2}} { return "FAIL: wrong list remaining" } if {[lshift list1] ne ""} { return "FAIL: empty list not detected" } return "lshift successful." } -result "lshift successful." test lunshift { Lunshift unit test. } -body { set list {3 4} if {[lunshift list 2] != {2 3 4}} { return "FAIL: element not inserted" } if {[lunshift list 0 1] != {0 1 2 3 4}} { return "FAIL: multiple elements not inserted" } if {[lunshift list2 0] != 0} { return "FAIL: list not created" } return "lunshift successful." } -result "lunshift successful." test throw { Throw unit test. } -setup { proc test_proc {arg} { catch {throw $arg} res return $res } } -body { if {[test_proc {7 msg info}] != "error: 7 msg info"} { return "FAIL: wrong error returneed" } if {[catch {test_proc ""}] != 0} { return "FAIL: wrong value returned" } return "throw successful." } -result "throw successful." test try { Try unit test. } -setup { proc test_proc {} {try {return 7} catch * {return 6}} proc test_proc2 {} {try {error "msg" "info" 3} catch * {return 6}} } -body { if {[test_proc] != 7} { return "FAIL: try clause not working" } if {[test_proc2] != 6} { reutrn "FAIL: catch clause not working" } if {[catch {try}] != 1} { return "FAIL: no args err not detected" } return "try successful." } -result "try successful." cleanupTests