head	1.5;
access;
symbols
	core-8-0-6-branch:1.4.0.2
	core-8-0-6-base:1.4
	core-8-0-5:1.3.2.1
	dev-8-1-stubs-branch:1.1.4.3.0.2
	dev-stubs-branch:1.3.0.4
	scriptics-tclpro-1-2:1.3
	scriptics-tclpro-1-2-b2:1.3
	core-8-1-merge-2/10/99:1.3
	core-8-0-5-branch:1.3.0.2
	core-8-0-5-base:1.3
	scriptics-tclpro-1-2-b1:1.3
	scriptics-tclpro-1-2-a1:1.3
	core-8-1-b1:1.1.4.3
	core-8-0-4:1.2
	core-8-1-a2:1.1.4.1
	core-8-0-2:1.1
	core-8-0-3:1.2;
locks; strict;
comment	@# @;


1.5
date	99.04.16.01.51.36;	author stanton;	state dead;
branches;
next	1.4;

1.4
date	99.04.16.01.25.55;	author stanton;	state Exp;
branches;
next	1.3;

1.3
date	98.12.04.04.19.12;	author hershey;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	98.09.14.18.23.45;	author stanton;	state Exp;
branches;
next	1.1;

1.1
date	98.04.01.09.58.22;	author rjohnson;	state Exp;
branches
	1.1.4.1;
next	;

1.1.4.1
date	98.09.29.00.25.49;	author stanton;	state Exp;
branches;
next	1.1.4.2;

1.1.4.2
date	98.09.30.02.18.34;	author stanton;	state Exp;
branches;
next	1.1.4.3;

1.1.4.3
date	98.12.10.03.43.54;	author stanton;	state Exp;
branches;
next	1.1.4.4;

1.1.4.4
date	99.03.11.18.50.46;	author hershey;	state dead;
branches;
next	;

1.3.2.1
date	99.03.22.06.43.05;	author jingham;	state Exp;
branches;
next	;


desc
@@


1.5
log
@* Merged 8.1 branch into the main trunk
@
text
@# This file contains support code for the Tcl test suite.  It is
# normally sourced by the individual files in the test suite before
# they run their tests.  This improved approach to testing was designed
# and initially implemented by Mary Ann May-Pumphrey of Sun Microsystems.
#
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
# Copyright (c) 1998 by Scriptics Corporation
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @@(#) $Id: defs,v 1.4 1999/04/16 01:25:55 stanton Exp $

if {![info exists VERBOSE]} {
    set VERBOSE 0
}
if {![info exists TESTS]} {
    set TESTS {}
}

tk appname tktest
wm title . tktest

# Check configuration information that will determine which tests
# to run.  To do this, create an array testConfig.  Each element
# has a 0 or 1 value, and the following elements are defined:
#	unixOnly -	1 means this is a UNIX platform, so it's OK
#			to run tests that only work under UNIX.
#	macOnly -	1 means this is a Mac platform, so it's OK
#			to run tests that only work on Macs.
#	pcOnly -	1 means this is a PC platform, so it's OK to
#			run tests that only work on PCs.
#	unixOrPc -	1 means this is a UNIX or PC platform.
#	macOrPc -	1 means this is a Mac or PC platform.
#	macOrUnix -	1 means this is a Mac or UNIX platform.
#	nonPortable -	1 means this the tests are being running in
#			the master Tcl/Tk development environment;
#			Some tests are inherently non-portable because
#			they depend on things like word length, file system
#			configuration, window manager, etc.  These tests
#			are only run in the main Tcl development directory
#			where the configuration is well known.  The presence
#			of the file "doAllTests" in this directory indicates
#			that it is safe to run non-portable tests.
#	fonts -		1 means that this platform uses fonts with
#			well-know geometries, so it is safe to run
#			tests that depend on particular font sizes.

catch {unset testConfig}

set testConfig(unixOnly) 	[expr {$tcl_platform(platform) == "unix"}]
set testConfig(macOnly) 	[expr {$tcl_platform(platform) == "macintosh"}]
set testConfig(pcOnly)		[expr {$tcl_platform(platform) == "windows"}]

set testConfig(unix)		$testConfig(unixOnly)
set testConfig(mac)		$testConfig(macOnly)
set testConfig(pc)		$testConfig(pcOnly)

set testConfig(unixOrPc) [expr {$testConfig(unixOnly) || $testConfig(pcOnly)}]
set testConfig(macOrPc) [expr {$testConfig(macOnly) || $testConfig(pcOnly)}]
set testConfig(macOrUnix) [expr {$testConfig(macOnly) || $testConfig(unixOnly)}]

set testConfig(nonPortable) 	[expr {[file exists doAllTests] || [file exists DOALLT~1]}]

set testConfig(nt)		[expr {$tcl_platform(os) == "Windows NT"}]
set testConfig(95)		[expr {$tcl_platform(os) == "Windows 95"}]
set testConfig(win32s)		[expr {$tcl_platform(os) == "Win32s"}]

# The following config switches are used to mark tests that should work,
# but have been temporarily disabled on certain platforms because they don't.

set testConfig(tempNotPc) 	[expr {!$testConfig(pc)}]
set testConfig(tempNotMac) 	[expr {!$testConfig(mac)}]
set testConfig(tempNotUnix)	[expr {!$testConfig(unix)}]

# The following config switches are used to mark tests that crash on
# certain platforms, so that they can be reactivated again when the
# underlying problem is fixed.

set testConfig(pcCrash) 	[expr {!$testConfig(pc)}]
set testConfig(win32sCrash) 	[expr {!$testConfig(win32s)}]
set testConfig(macCrash) 	[expr {!$testConfig(mac)}]
set testConfig(unixCrash) 	[expr {!$testConfig(unix)}]

set testConfig(fonts) 1
catch {destroy .e}
entry .e -width 0 -font {Helvetica -12} -bd 1
.e insert end "a.bcd"
if {([winfo reqwidth .e] != 37) || ([winfo reqheight .e] != 20)} {
    set testConfig(fonts) 0
}
destroy .e .t
text .t -width 80 -height 20 -font {Times -14} -bd 1
pack .t
.t insert end "This is\na dot."
update
set x [list [.t bbox 1.3] [.t bbox 2.5]]
destroy .t
if {[string match {{22 3 6 15} {31 18 [34] 15}} $x] == 0} {
    set testConfig(fonts) 0
}

if {$testConfig(nonPortable) == 0} {
    puts stdout "(will skip non-portable tests)"
}
if {$testConfig(fonts) == 0} {
    puts stdout "(will skip font-sensitive tests: this system has unexpected font geometries)"
}

trace variable testConfig r safeFetch

proc safeFetch {n1 n2 op} {
    global testConfig 

    if {($n2 != {}) && ([info exists testConfig($n2)] == 0)} {
	set testConfig($n2) 0
    }
}

# If there is no "memory" command (because memory debugging isn't
# enabled), generate a dummy command that does nothing.

if {[info commands memory] == ""} {
    proc memory args {}
}

proc print_verbose {name description script code answer} {
    puts stdout "\n"
    puts stdout "==== $name $description"
    puts stdout "==== Contents of test case:"
    puts stdout "$script"
    if {$code != 0} {
	if {$code == 1} {
	    puts stdout "==== Test generated error:"
	    puts stdout $answer
	} elseif {$code == 2} {
	    puts stdout "==== Test generated return exception;  result was:"
	    puts stdout $answer
	} elseif {$code == 3} {
	    puts stdout "==== Test generated break exception"
	} elseif {$code == 4} {
	    puts stdout "==== Test generated continue exception"
	} else {
	    puts stdout "==== Test generated exception $code;  message was:"
	    puts stdout $answer
	}
    } else {
	puts stdout "==== Result was:"
	puts stdout "$answer"
    }
}

# test --
# This procedure runs a test and prints an error message if the
# test fails.  If VERBOSE has been set, it also prints a message
# even if the test succeeds.  The test will be skipped if it
# doesn't match the TESTS variable, or if one of the elements
# of "constraints" turns out not to be true.
#
# Arguments:
# name -		Name of test, in the form foo-1.2.
# description -		Short textual description of the test, to
#			help humans understand what it does.
# constraints -		A list of one or more keywords, each of
#			which must be the name of an element in
#			the array "testConfig".  If any of these
#			elements is zero, the test is skipped.
#			This argument may be omitted.
# script -		Script to run to carry out the test.  It must
#			return a result that can be checked for
#			correctness.
# answer -		Expected result from script.

proc test {name description script answer args} {
    global VERBOSE TESTS testConfig
    if {[string compare $TESTS ""] != 0} {
	set ok 0
	foreach test $TESTS {
	    if {[string match $test $name]} {
		set ok 1
		break
	    }
        }
	if {!$ok} {
	    return
	}
    }
    set i [llength $args]
    if {$i == 0} {
	# Empty body
    } elseif {$i == 1} {
	# "constraints" argument exists;  shuffle arguments down, then
	# make sure that the constraints are satisfied.

	set constraints $script
	set script $answer
	set answer [lindex $args 0]
	set doTest 0
	if {[string match {*[$\[]*} $constraints] != 0} {
	    # full expression, e.g. {$foo > [info tclversion]}

	    catch {set doTest [uplevel #0 expr $constraints]}
	} elseif {[regexp {[^.a-zA-Z0-9 ]+} $constraints] != 0} {
	    # something like {a || b} should be turned into 
	    # $testConfig(a) || $testConfig(b).

 	    regsub -all {[.a-zA-Z0-9]+} $constraints {$testConfig(&)} c
	    catch {set doTest [eval expr $c]}
	} else {
	    # just simple constraints such as {unixOnly fonts}.

	    set doTest 1
	    foreach constraint $constraints {
		if {![info exists testConfig($constraint)]
			|| !$testConfig($constraint)} {
		    set doTest 0
		    break
		}
	    }
	}
	if {$doTest == 0} {
	    if {$VERBOSE} {
		puts stdout "++++ $name SKIPPED: $constraints"
	    }
	    return	
	}
    } else {
	error "wrong # args: must be \"test name description ?constraints? script answer\""
    }
    memory tag $name
    set code [catch {uplevel $script} result]
    if {$code != 0} {
	print_verbose $name $description $script $code $result
    } elseif {[string compare $result $answer] == 0} { 
	if {$VERBOSE} {
	    if {$VERBOSE > 0} {
		print_verbose $name $description $script $code $result
	    }
	    if {$VERBOSE != -2} {
		puts stdout "++++ $name PASSED"
	    }
	}
    } else { 
	print_verbose $name $description $script $code $result 
	puts stdout "---- Result should have been:"
	puts stdout "$answer"
	puts stdout "---- $name FAILED" 
    }
    if {[string compare $::tcl_platform(platform) macintosh] == 0} {
        # Force the text to be drawn even if the tests are not updating.
        update idletasks
    }
}

proc dotests {file args} {
    global TESTS
    set savedTests $TESTS
    set TESTS $args
    source $file
    set TESTS $savedTests
}

# If the main window isn't already mapped (e.g. because the tests are
# being run automatically) , specify a precise size for it so that the
# user won't have to position it manually.

if {![winfo ismapped .]} {
    wm geometry . +0+0
    update
}

# The following code can be used to perform tests involving a second
# process running in the background.

# Locate tktest executable

set tktest [info nameofexecutable]
if {$tktest == "{}"} {
    set tktest {}
    puts stdout "Unable to find tktest executable, skipping multiple process tests."
}

# Create background process

proc setupbg args {
    global tktest fd bgData
    if {$tktest == ""} {
        error "you're not running tktest so setupbg should not have been called"
    }
    if {[info exists fd] && ($fd != "")} {
	cleanupbg
    }
    set fd [open "|[list $tktest -geometry +0+0 -name tktest] $args" r+]
    puts $fd "puts foo; flush stdout"
    flush $fd
    if {[gets $fd data] < 0} {
        error "unexpected EOF from \"$tktest\""
    }
    if {[string compare $data foo]} {
        error "unexpected output from background process \"$data\""
    }
    fileevent $fd readable bgReady
}

# Send a command to the background process, catching errors and
# flushing I/O channels
proc dobg {command} {
    global fd bgData bgDone
    puts $fd "catch [list $command] msg; update; puts \$msg; puts **DONE**; flush stdout"
    flush $fd
    set bgDone 0
    set bgData {}
    tkwait variable bgDone
    set bgData
}

# Data arrived from background process.  Check for special marker
# indicating end of data for this command, and make data available
# to dobg procedure.
proc bgReady {} {
    global fd bgData bgDone
    set x [gets $fd]
    if {[eof $fd]} {
	fileevent $fd readable {}
	set bgDone 1
    } elseif {$x == "**DONE**"} {
	set bgDone 1
    } else {
	append bgData $x
    }
}

# Exit the background process, and close the pipes
proc cleanupbg {} {
    global fd
    catch {
	puts $fd "exit"
	close $fd
    }
    set fd ""
}

# Clean up focus after using generate event, which
# can leave the window manager with the wrong impression
# about who thinks they have the focus. (BW)

proc fixfocus {} {
    catch {destroy .focus}
    toplevel .focus
    wm geometry .focus +0+0
    entry .focus.e
    .focus.e insert 0 "fixfocus"
    pack .focus.e
    update
    focus -force .focus.e
    destroy .focus
}

proc makeFile {contents name} {
    set fd [open $name w]
    fconfigure $fd -translation lf
    if {[string index $contents [expr {[string length $contents] - 1}]] == "\n"} {
	puts -nonewline $fd $contents
    } else {
	puts $fd $contents
    }
    close $fd
}

proc removeFile {name} {
    file delete -- $name
}
@


1.4
log
@* Merged changes from 8.0.5:
    - Updated for Mac release
@
text
@d12 1
a12 1
# RCS: @@(#) $Id: defs,v 1.3 1998/12/04 04:19:12 hershey Exp $
@


1.3
log
@Update all and defs to work with nightly test environment.
Both files now pass the checker!
@
text
@d12 1
a12 1
# RCS: @@(#) $Id: defs,v 1.2 1998/09/14 18:23:45 stanton Exp $
d248 4
@


1.3.2.1
log
@On the Macintosh, call update idletasks at the end of each test.  Since the test results are written into a text widget, if you don't do an update, the results will lag behind the tests, which can be confusing.
@
text
@d12 1
a12 1
# RCS: @@(#) $Id: defs,v 1.3 1998/12/04 04:19:12 hershey Exp $
a247 4
    }
    if {[string compare $::tcl_platform(platform) macintosh] == 0} {
        # Force the text to be drawn even if the tests are not updating.
        update idletasks
@


1.2
log
@Replaced SCCS strings, fixed binary files
@
text
@d7 1
d12 1
a12 1
# RCS: @@(#) $Id$
d14 1
a14 1
if ![info exists VERBOSE] {
d17 1
a17 1
if ![info exists TESTS] {
d59 3
a61 3
set testConfig(unixOrPc) [expr $testConfig(unixOnly) || $testConfig(pcOnly)]
set testConfig(macOrPc) [expr $testConfig(macOnly) || $testConfig(pcOnly)]
set testConfig(macOrUnix) [expr $testConfig(macOnly) || $testConfig(unixOnly)]
d63 1
a63 1
set testConfig(nonPortable) 	[expr [file exists doAllTests] || [file exists DOALLT~1]]
d72 3
a74 3
set testConfig(tempNotPc) 	[expr !$testConfig(pc)]
set testConfig(tempNotMac) 	[expr !$testConfig(mac)]
set testConfig(tempNotUnix)	[expr !$testConfig(unix)]
d80 4
a83 4
set testConfig(pcCrash) 	[expr !$testConfig(pc)]
set testConfig(win32sCrash) 	[expr !$testConfig(win32s)]
set testConfig(macCrash) 	[expr !$testConfig(mac)]
set testConfig(unixCrash) 	[expr !$testConfig(unix)]
d104 1
a104 1
    puts "(will skip non-portable tests)"
d107 1
a107 1
    puts "(will skip font-sensitive tests: this system has unexpected font geometries)"
d235 1
a235 1
	if {$VERBOSE} then {
d276 1
a276 1
    puts "Unable to find tktest executable, skipping multiple process tests."
d281 1
a281 1
proc setupbg {{args ""}} {
d295 1
a295 1
    if [string compare $data foo] {
d319 1
a319 1
    if [eof $fd] {
d358 1
a358 1
    if {[string index $contents [expr [string length $contents] - 1]] == "\n"} {
@


1.1
log
@Initial revision
@
text
@d11 1
a11 1
# SCCS: @@(#) defs 1.39 97/08/06 15:32:02
@


1.1.4.1
log
@initial tk8.1a2 version
@
text
@d11 1
a11 1
# SCCS: @@(#) defs 1.43 98/01/13 17:21:10
a43 4
#       knownBug -      The test is known to fail and the bug is not yet
#                       fixed. The test will be run only if the file
#                       "doBuggyTests" exists (intended for Tcl dev. group
#                       internal use only).
a62 1
set testConfig(knownBug)	[expr [file exists doBuggyTests] || [file exists doBuggyT]]
d91 1
a91 2
destroy .e
catch {destroy .t}
a366 18
}

#
# Construct a string that consists of the requested sequence of bytes,
# as opposed to a string of properly formed UTF-8 characters.  
# This allows the tester to 
# 1. Create denormalized or improperly formed strings to pass to C procedures 
#    that are supposed to accept strings with embedded NULL bytes.
# 2. Confirm that a string result has a certain pattern of bytes, for instance
#    to confirm that "\xe0\0" in a Tcl script is stored internally in 
#    UTF-8 as the sequence of bytes "\xc3\xa0\xc0\x80".
#
# Generally, it's a bad idea to examine the bytes in a Tcl string or to
# construct improperly formed strings in this manner, because it involves
# exposing that Tcl uses UTF-8 internally.

proc bytestring {string} {
    testencoding toutf $string identity
@


1.1.4.2
log
@Merged 8.0.3 changes into 8.1
@
text
@d11 1
a11 1
# RCS: @@(#) $Id: defs,v 1.2 1998/09/14 18:23:45 stanton Exp $
@


1.1.4.3
log
@merge 8.0 changes
@
text
@a6 1
# Copyright (c) 1998 by Scriptics Corporation
d11 1
a11 1
# RCS: @@(#) $Id: defs,v 1.1.4.2 1998/09/30 02:18:34 stanton Exp $
d13 1
a13 1
if {![info exists VERBOSE]} {
d16 1
a16 1
if {![info exists TESTS]} {
d62 3
a64 3
set testConfig(unixOrPc) [expr {$testConfig(unixOnly) || $testConfig(pcOnly)}]
set testConfig(macOrPc) [expr {$testConfig(macOnly) || $testConfig(pcOnly)}]
set testConfig(macOrUnix) [expr {$testConfig(macOnly) || $testConfig(unixOnly)}]
d66 2
a67 2
set testConfig(knownBug)	[expr {[file exists doBuggyTests] || [file exists doBuggyT]}]
set testConfig(nonPortable) 	[expr {[file exists doAllTests] || [file exists DOALLT~1]}]
d76 3
a78 3
set testConfig(tempNotPc) 	[expr {!$testConfig(pc)}]
set testConfig(tempNotMac) 	[expr {!$testConfig(mac)}]
set testConfig(tempNotUnix)	[expr {!$testConfig(unix)}]
d84 4
a87 4
set testConfig(pcCrash) 	[expr {!$testConfig(pc)}]
set testConfig(win32sCrash) 	[expr {!$testConfig(win32s)}]
set testConfig(macCrash) 	[expr {!$testConfig(mac)}]
set testConfig(unixCrash) 	[expr {!$testConfig(unix)}]
d109 1
a109 1
    puts stdout "(will skip non-portable tests)"
d112 1
a112 1
    puts stdout "(will skip font-sensitive tests: this system has unexpected font geometries)"
d240 1
a240 1
	if {$VERBOSE} {
d281 1
a281 1
    puts stdout "Unable to find tktest executable, skipping multiple process tests."
d286 1
a286 1
proc setupbg args {
d300 1
a300 1
    if {[string compare $data foo]} {
d324 1
a324 1
    if {[eof $fd]} {
d363 1
a363 1
    if {[string index $contents [expr {[string length $contents] - 1}]] == "\n"} {
@


1.1.4.4
log
@Updated the testsuite to use "test" namespace and commandline args
to control verbose  level and which tests get run.  Tests now work from
any working dir.
@
text
@d12 1
a12 1
# RCS: @@(#) $Id: defs,v 1.1.4.3 1998/12/10 03:43:54 stanton Exp $
@


