# 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.
#
# RCS: @(#) $Id: CdCmd.test,v 1.1 1998/11/05 19:48:37 hylands Exp $

# Note: This test file must be sourced from the parent directory
#       or else the defs file may not be properly loaded.

if {[string compare test [info procs test]] == 1} then {source defs}

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}}

