# The file tests the CdCmd.java file.
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1996-1997 by Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# SCCS: @(#) CdCmd.test 1.38 97/11/13 18:50:09

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import -force ::tcltest::*
}

# FIXME: These tests are part of cmdAH.test in the regular
# Tcl distro. This A-H stuff needs to be split up into
# more focused sections of added to the Jacl suite as-is.

test CdCmd-1.1 {cmdProc} {
    list [catch {cd foo bar} msg] $msg
} {1 {wrong # args: should be "cd ?dirName?"}}
test CdCmd-1.2 {cmdProc} {
    file delete -force foo
    file mkdir foo
    cd foo
    set result [file tail [pwd]]
    cd ..
    file delete foo
    set result
} foo
test CdCmd-1.3 {cmdProc} {
    global env
    set oldpwd [pwd]
    set temp $env(HOME)
    set env(HOME) $oldpwd
    file delete -force foo
    file mkdir foo
    cd foo
    cd ~
    set result [string match [pwd] $oldpwd]
    file delete foo
    set env(HOME) $temp
    set result
} 1
test CdCmd-1.4 {cmdProc} {
    global env
    set oldpwd [pwd]
    set temp $env(HOME)
    set env(HOME) $oldpwd
    file delete -force foo
    file mkdir foo
    cd foo
    cd
    set result [string match [pwd] $oldpwd]
    file delete foo
    set env(HOME) $temp
    set result
} 1
test CdCmd-1.5 {cmdProc} {
    list [catch {cd ~~} msg] $msg
} {1 {user "~" doesn't exist}}
test CdCmd-1.6 {cmdProc} {
    list [catch {cd _foobar} msg] $msg
} {1 {couldn't change working directory to "_foobar": no such file or directory}}

# cleanup
::tcltest::cleanupTests
return
