pkgreq.test   [plain text]


#!/usr/bin/env tclsh
#
# pkgreq.test --
#
# Test loading of all tcl packages installed in /System/Library/Tcl
#

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest 2.2
}

if {[catch {tcltest::testConstraint notLoadable}]} {
    tcltest::testConstraint notLoadable 0
}
tcltest::testConstraint req85 [expr {![catch {package present Tcl 8.5-}]}]
tcltest::testConstraint req86 [expr {![catch {package present Tcl 8.6-}]}]

proc constraint {pkg} {
    # packages not intended for direct loading or known not to be present
    if {[regexp {^(dom::c|page::((analysis|compiler|transform)::.*|(gen::peg|writer)::(me|mecpu)|(reader|util::norm)::(peg|lemon))|xotcl::.*::(ldap|.*gdbm)|(doctools::(toc|idx)|pt::peg)::(import|export)::.*)$} $pkg]} {
	return notLoadable
    }
    # packages requiring tcl 8.5 or later
    if {[regexp {^(chatwidget|canvas::(mvg|snap)|char|configuration|controlwidget|diagram(|::.*)|gpx|huddle|yaml|imap4|json(|::.*)|JSONRPC|namespacex|ntext|paths|pt::.*|rest|S3|sqlite3|struct::graph::op|tablelist_tile|tcl::randomseed|text::write|vfs::webdav|xsxp|xyplot)$} $pkg]} {
	return req85
    }
    # packages requiring tcl 8.6 or later
    if {[regexp {^(coroutine(|::auto)|menubar(|::.*)|tcl::(chan|transform)::.*)$} $pkg]} {
        return req86
    }
    return {}
}

# get all package names
set pkgs [exec find -L /System/Library/Tcl \
	! -path "*/Tcl/[expr {[tcltest::testConstraint req85] ? "8.4" : "8.5"}]/*" \
	-name pkgIndex.tcl -print0 | \
	xargs -0 awk {/^[ \t]*package ifneeded/ && $3 !~ /^\$/ {print $3}} | \
	sort -fu]

foreach pkg $pkgs {
    tcltest::test pkgreq-$pkg "\[package require $pkg\]" \
	-constraints [constraint $pkg] -setup {interp create i} \
	-body {interp eval i "package require $pkg"} \
	-cleanup {interp delete i} -match regexp -result {^[\d\.]+$}
}

tcltest::cleanupTests