#
# file.test
#
# Tests for deprecated TclX file commands: mkdir, rmdir, unlink, frename.
#---------------------------------------------------------------------------
# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies.  Karl Lehenbauer and
# Mark Diekhans make no representations about the suitability of this
# software for any purpose.  It is provided "as is" without express or
# implied warranty.
#------------------------------------------------------------------------------
# $Id: file.test,v 1.1.1.1 1999/06/28 20:35:29 damon Exp $
#------------------------------------------------------------------------------
#

if [cequal [info procs Test] {}] {source testlib.tcl}
eval $SAVED_UNKNOWN

TestRemove MKDIR1.TMP MKDIR2.TMP MKDIR3.TMP UNLINK1.TMP UNLINK2.TMP \
        UNLINK3.TMP FRENAME1.TMP FRENAME2.TMP

Test file-compat-1.1 {mkdir tests} {
    catch {rmdir {MKDIR1.TMP MKDIR2.TMP}}
    mkdir {MKDIR1.TMP MKDIR2.TMP}
    set result [list [file isdirectory MKDIR1.TMP] \
                     [file isdirectory MKDIR2.TMP]]
    catch {rmdir {MKDIR1.TMP MKDIR2.TMP}}
    set result
} 0 {1 1}

Test file-compat-1.2 {mkdir tests} {
    catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
    mkdir -path MKDIR1.TMP/a/b/c
    set result [file isdirectory MKDIR1.TMP/a/b/c] 
    catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
    set result
} 0 1

Test file-compat-1.3 {mkdir tests} {
    catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
    mkdir -path MKDIR1.TMP/a/b/c
    mkdir -path MKDIR1.TMP/a/b/c
    set result [file isdirectory MKDIR1.TMP/a/b/c] 
    catch {rmdir {MKDIR1.TMP/a/b/c MKDIR1.TMP/a/b MKDIR1.TMP/a MKDIR1.TMP}}
    set result
} 0 1

Test file-compat-1.4 {mkdir tests} {
    catch {mkdir MKDIR1.TMP}
    set result [list [catch {mkdir MKDIR1.TMP} msg] [string tolower $msg]]
    catch {rmdir MKDIR1.TMP}
    set result
} 0 {1 {creating directory "mkdir1.tmp" failed: file already exists}}

Test file-compat-1.5 {mkdir tests} {
    catch {mkdir MKDIR1.TMP}
    close [open MKDIR1.TMP/notAdir w]
    set result [list [catch {mkdir -path MKDIR1.TMP/notAdir} msg] \
        [string tolower $msg]]
    unlink MKDIR1.TMP/notAdir
    catch {rmdir MKDIR1.TMP}
    set result
} 0 {1 {creating directory "mkdir1.tmp/notadir" failed: file already exists}}

Test file-compat-2.1 {rmdir tests} {
    catch {mkdir {MKDIR1.TMP MKDIR2.TMP}}
    rmdir {MKDIR1.TMP MKDIR2.TMP}
    list [file isdirectory MKDIR1.TMP] [file isdirectory MKDIR2.TMP]
} 0 {0 0}

Test file-compat-2.2 {rmdir tests} {
    catch {rmdir MKDIR1.TMP}
    list [catch {rmdir MKDIR1.TMP} msg] [string tolower $msg]
} 0 {1 {can't remove "mkdir1.tmp": no such file or directory}}

Test file-compat-2.3 {rmdir tests} {
    catch {rmdir MKDIR1.TMP}
    list [catch {rmdir MKDIR1.TMP} msg] [string tolower $msg]
} 0 {1 {can't remove "mkdir1.tmp": no such file or directory}}

Test file-compat-2.4 {rmdir tests} {
    close [open MKDIR3.TMP w]
    list [catch {rmdir MKDIR3.TMP} msg] [string tolower $msg]
} 0 {1 {mkdir3.tmp: not a directory}}

Test file-compat-2.5 {rmdir tests} {
    catch {rmdir MKDIR1.TMP}
    rmdir -nocomplain MKDIR1.TMP
} 0 {}

Test file-compat-3.1 {unlink tests} {
    set fh [open UNLINK1.TMP w]
    puts $fh "Hello, world"
    close $fh
    unlink UNLINK1.TMP
    file exists UNLINK1.TMP
} 0 0

Test file-compat-3.2 {unlink tests} {
    list [catch {unlink UNLINK1.TMP} msg] [string tolower $msg]
} 0 {1 {can't remove "unlink1.tmp": no such file or directory}}

Test file-compat-3.4 {unlink tests} {
    set fh [open UNLINK1.TMP w]
    puts $fh "Hello, world"
    close $fh
    unlink -nocomplain {../src/FOOWAPFOO UNLINK1.TMP}
    file exists UNLINK1.TMP
} 0 0

Test file-compat-3.4 {unlink tests} {
    mkdir UNLINK2.TMP
    link -sym UNLINK2.TMP UNLINK3.TMP
    unlink UNLINK3.TMP
    catch {file readlink UNLINK3.TMP}
} 0 1 {unixOnly}

Test file-compat-3.5 {unlink tests} {
    link -sym UNLINK100.TMP UNLINK3.TMP
    unlink UNLINK3.TMP
    catch {file readlink UNLINK3.TMP}
} 0 1 {unixOnly}

Test file-compat-4.1 {frename tests} {
    close [open FRENAME1.TMP w]
    set result [file exists FRENAME1.TMP]
    lappend result [file exists FRENAME2.TMP]
    frename FRENAME1.TMP FRENAME2.TMP
    lappend result [file exists FRENAME1.TMP]
    lappend result [file exists FRENAME2.TMP]
    set result
} 0 {1 0 0 1}

Test file-compat-4.4 {frename tests} {
    TestRemove FRENAME3.TMP
    list [catch {frename FRENAME3.TMP FRENAME4.TMP} msg] [string tolower $msg]
} 0 {1 {error renaming "frename3.tmp": no such file or directory}}

TestRemove MKDIR1.TMP MKDIR2.TMP MKDIR3.TMP UNLINK1.TMP UNLINK2.TMP \
        UNLINK3.TMP FRENAME1.TMP FRENAME2.TMP

rename unknown {}

 


