#
# Test for Sterno package loading.
#
# Copyright (c) 1997-1998 Mark Diekhans
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: pkgtest.test,v 1.5 1998/02/13 18:31:02 markd Exp $
#

if {[info procs test] != "test"} then {source testlib.tcl}
catch {namespace delete ::Sterno}
set pkgDir [file join [pwd] [file join .. unix]]

# Don't run this test if the package doesn't exists
set pkgFile [file join $pkgDir sterno.tcl]
if {![file exists $pkgFile]} {
    puts stderr "*** package file does not exist: $pkgFile"
    puts stderr "*** please do a make; test skipped"
    return
}

set auto_path [concat $pkgDir $auto_path]

Test package-1.0 {loading of package} {
    set c1 [::Sterno::defClass {} {}]
} 1 {invalid command name "::Sterno::defClass"}

TestReg package-1.1 {loading of package} {
    package require Sterno
    set c1 [::Sterno::defClass {} {}]
} 0 {^::Sterno::Classes::class[0-9]+::___call$}

Test package-1.2 {loading of package} {
    $c1 delete
} 0 {}


Test package-2.0 {package version} {
    # Grab version number out of pkgIndex for comparison to that in the code.
    # into the code.
    set sternoVersion {}
    set fh [open $pkgFile]
    while {[gets $fh line] >= 0} {
        if [string match {package *} $line] {
            set sternoVersion [lindex [split $line] 3]
            break
        }
    }
    if [eof $fh] {
        close $fh
        error "package command not found in $pkgFile"
    }
    close $fh

    if {[string compare $::Sterno::version $sternoVersion] != 0} {
        error "Version mismatch (check Makefile.in and sterno.tcl;\
                maybe regenerate pkgIndex.tcl"
    } {
        concat OK
    }
} 0 OK
