# vfsFtp.test                                                   -*- tcl -*-
#
#	Commands covered:  vfs::ftp::Mount and friends.
#
# 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) 2001 by Vince Darley.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

if {[lsearch [namespace children] ::tcltest] < 0} {
    package require tcltest 2
    namespace import ::tcltest::*
}

testConstraint ftp [expr {![catch {package require vfs::ftp}]
			  &&
			  [clock format [clock seconds] -format %Y] < 2019}]

if {[testConstraint ftp]} {
    puts stdout "These tests require an internet connection, and might"
    puts stdout "take a long time to complete."
} elseif {[clock format [clock seconds] -format %Y] >= 2019} {
    puts stdout "It's [clock format [clock seconds] -format %Y]. FTP is dead."
}

test vfsFtp-1.1 {mount and cd} -constraints {ftp} -setup {
    set cwd [pwd]
} -body {
    vfs::ftp::Mount ftp://ftp.ucsd.edu/pub/alpha/ local
    cd local
    cd tcl
    set result [file tail [pwd]]
    vfs::unmount local
    set result
} -cleanup {
    cd $pwd
} -result {tcl}

test vfsFtp-1.2 {mount and glob} -constraints {ftp} -setup {
    vfs::ftp::Mount ftp://ftp.ucsd.edu/pub/alpha/ local
} -body {
    glob -nocomplain -directory local/tcl vfsTest.tcl
} -cleanup {
    vfs::unmount local
} -result {vfsTest.tcl}

test vfsFtp-1.3 {mount and source} -constraints {ftp} -setup {
    vfs::ftp::Mount ftp://ftp.ucsd.edu/pub/alpha/ local
} -body {
    set f [open local/tcl/vfsTest.tcl r]
    set data [read $f]
    close $f
    set data
} -cleanup {
    vfs::unmount local
} -result {This was returned from a remote file}

# cleanup
::tcltest::cleanupTests
return
