# This file is a Tcl script to test the bgerror command.
#
# Copyright © 1997 Sun Microsystems, Inc.
# Copyright © 1998-1999 Scriptics Corporation.
# All rights reserved.

# NOTE
#
# Some testing of the default error dialog would be needed too, but that's
# not easy at all to emulate.

#
# TESTFILE INITIALIZATION
#

package require tcltest 2.2; # needed in mode -singleproc 0

# Load the main script main.tcl, which takes care of:
# - setup for the application and the root window
# - importing commands from the tcltest namespace
# - loading of the testutils mechanism along with its utility procs
# - loading of Tk specific test constraints (additionally to constraints
#   provided by the package tcltest)
source [file join [tcltest::configure -testdir] main.tcl]

# Ensure a pristine initial window state
resetWindows

#
# TESTS
#

test bgerror-1.1 {bgerror / tkerror compat} -setup {
    set errRes {}
    proc tkerror {err} {
	global errRes;
	set errRes $err;
    }
} -body {
    after 0 {error err1}
    vwait errRes;
    return $errRes;
} -cleanup {
    catch {rename tkerror {}}
} -result {err1}

test bgerror-1.2 {bgerror / tkerror compat / accumulation} -setup {
    set errRes {}
    proc tkerror {err} {
	global errRes;
	lappend errRes $err;
    }
} -body {
    after 0 {error err1}
    after 0 {error err2}
    after 0 {error err3}
    update
    return $errRes;
} -cleanup {
    catch {rename tkerror {}}
} -result {err1 err2 err3}

test bgerror-1.3 {bgerror / tkerror compat / accumulation / break} -setup {
    set errRes {}
    proc tkerror {err} {
	global errRes;
	lappend errRes $err;
	return -code break "skip!";
    }
} -body {
    after 0 {error err1}
    after 0 {error err2}
    after 0 {error err3}
    update
    return $errRes;
} -cleanup {
    catch {rename tkerror {}}
} -result {err1}

#
# TESTFILE CLEANUP
#

cleanupTests
