Skip to content
Tcl Source Code Artifact [0427fda8a4]
Login

Artifact [0427fda8a4]

Artifact 0427fda8a465b69da9411eca82845cbc7048333d65c807876a02c7f42303fcc2:


# The file tests the tclZlib.c 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-1998 by Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution of
# this file, and for a DISCLAIMER OF ALL WARRANTIES.

if {"::tcltest" ni [namespace children]} {
    package require tcltest 2.1
    namespace import -force ::tcltest::*
}

testConstraint zipfs [expr {[llength [info commands zlib]] && [regexp tcltest [info nameofexecutable]]}]

# Removed in tip430 - zipfs is no longer a static package
#test zipfs-0.0 {zipfs basics} -constraints zipfs -body {
#    load {} zipfs
#} -result {}

set ziproot [zipfs root]
set CWD [pwd]
set tmpdir  [file join $CWD tmp]
file mkdir $tmpdir


test zipfs-0.1 {zipfs basics} -constraints zipfs -body {
    package require zipfs
} -result {2.0}

test zipfs-0.1 {zipfs basics} -constraints zipfs -body {
    expr {${ziproot} in [file volumes]}
} -result 1

if {![string match ${ziproot}* $tcl_library]} {
    ###
    # "make test" does not map tcl_library from the dynamic library on Unix
    #
    # Hack the environment to pretend we did pull tcl_library from a zip
    # archive
    ###
    set tclzip [file join $CWD [::tcl::pkgconfig get zipfile,runtime]]
    if {[file exists $tclzip]} {
        zipfs mount $tclzip /lib/tcl
        set ::tcl_library ${ziproot}lib/tcl/tcl_library
    } else {
        tcltest::skip zipfs-0.*
    }
}

test zipfs-0.2 {zipfs basics} -constraints zipfs -body {
    string match ${ziproot}* $tcl_library
} -result 1

test zipfs-0.3 {zipfs basics: glob} -constraints zipfs -body {
    set pwd [pwd]
    cd $tcl_library
    lsort [glob -dir . http*]
} -cleanup {
    cd $pwd
} -result {./http ./http1.0}

test zipfs-0.4 {zipfs basics: glob} -constraints zipfs -body {
    set pwd [pwd]
    cd $tcl_library
    lsort [glob -dir [pwd] http*]
} -cleanup {
    cd $pwd
} -result [list $tcl_library/http $tcl_library/http1.0]

test zipfs-0.5 {zipfs basics: glob} -constraints zipfs -body {
    lsort [glob -dir $tcl_library http*]
} -result [list $tcl_library/http $tcl_library/http1.0]

test zipfs-0.6 {zipfs basics: glob} -constraints zipfs -body {
    lsort [glob $tcl_library/http*]
} -result [list $tcl_library/http $tcl_library/http1.0]

test zipfs-0.7 {zipfs basics: glob} -constraints zipfs -body {
    lsort [glob -tails -dir $tcl_library http*]
} -result {http http1.0}

test zipfs-0.8 {zipfs basics: glob} -constraints zipfs -body {
    lsort [glob -nocomplain -tails -types d -dir $tcl_library http*]
} -result {http http1.0}

test zipfs-0.9 {zipfs basics: glob} -constraints zipfs -body {
    lsort [glob -nocomplain -tails -types f -dir $tcl_library http*]
} -result {}

test zipfs-0.10 {zipfs basics: join} -constraints zipfs -body {
    file join [zipfs root] bar baz
} -result "[zipfs root]bar/baz"

test zipfs-0.11 {zipfs basics: join} -constraints zipfs -body {
    file normalize [zipfs root]
} -result "[zipfs root]"

test zipfs-0.12 {zipfs basics: join} -constraints zipfs -body {
    file normalize [zipfs root]//bar/baz//qux/../
} -result "[zipfs root]bar/baz"

test zipfs-1.3 {zipfs errors} -constraints zipfs -returnCodes error -body {
    zipfs mount a b c d e f
} -result {wrong # args: should be "zipfs mount ?zipfile? ?mountpoint? ?password?"}

test zipfs-1.4 {zipfs errors} -constraints zipfs -returnCodes error -body {
    zipfs unmount a b c d e f
} -result {wrong # args: should be "zipfs unmount zipfile"}

test zipfs-1.5 {zipfs errors} -constraints zipfs -returnCodes error -body {
    zipfs mkkey a b c d e f
} -result {wrong # args: should be "zipfs mkkey password"}

test zipfs-1.6 {zipfs errors} -constraints zipfs -returnCodes error -body {
    zipfs mkimg a b c d e f
} -result {wrong # args: should be "zipfs mkimg outfile indir ?strip? ?password? ?infile?"}

test zipfs-1.7 {zipfs errors} -constraints zipfs -returnCodes error -body {
    zipfs mkzip a b c d e f
} -result {wrong # args: should be "zipfs mkzip outfile indir ?strip? ?password?"}

test zipfs-1.8 {zipfs errors} -constraints zipfs -returnCodes error -body {
    zipfs exists a b c d e f
} -result {wrong # args: should be "zipfs exists filename"}

test zipfs-1.9 {zipfs errors} -constraints zipfs -returnCodes error -body {
    zipfs info a b c d e f
} -result {wrong # args: should be "zipfs info filename"}

test zipfs-1.10 {zipfs errors} -constraints zipfs -returnCodes error -body {
    zipfs list a b c d e f
} -result {wrong # args: should be "zipfs list ?(-glob|-regexp)? ?pattern?"}

file mkdir tmp

test zipfs-2.1 {zipfs mkzip empty archive} -constraints zipfs -returnCodes error -body {
    zipfs mkzip [file join $tmpdir empty.zip] $tcl_library/xxxx
} -result {empty archive}

###
# The 2.2 series of tests operate within
# a zipfile created a temporary directory
###
set zipfile [file join $tmpdir abc.zip]
if {[file exists $zipfile]} {
   file delete $zipfile
}

test zipfs-2.2.0 {zipfs mkzip} -constraints zipfs -body {
    cd $tcl_library/encoding
    zipfs mkzip $zipfile .
    zipfs mount $zipfile ${ziproot}abc
    zipfs list -glob ${ziproot}abc/cp850.*
} -cleanup {
    cd $CWD
} -result "[zipfs root]abc/cp850.enc"

skip [concat [skip] zipfs-2.2.*]


if {![zipfs exists /abc/cp850.enc]} {
    tcltest::skip zipfs-2.2.*
}

test zipfs-2.2.1 {zipfs info} -constraints zipfs -body {
    set r [zipfs info ${ziproot}abc/cp850.enc]
    lrange $r 0 2
} -result [list $zipfile 1090 527] ;# NOTE: Only the first 3 results are stable

test zipfs-2.2.3 {zipfs data} -constraints zipfs -body {
    set zipfd [open ${ziproot}/abc/cp850.enc]	;# FIXME: leave open - see later test
    read $zipfd
} -result {# Encoding file: cp850, single-byte
S
003F 0 1
00
0000000100020003000400050006000700080009000A000B000C000D000E000F
0010001100120013001400150016001700180019001A001B001C001D001E001F
0020002100220023002400250026002700280029002A002B002C002D002E002F
0030003100320033003400350036003700380039003A003B003C003D003E003F
0040004100420043004400450046004700480049004A004B004C004D004E004F
0050005100520053005400550056005700580059005A005B005C005D005E005F
0060006100620063006400650066006700680069006A006B006C006D006E006F
0070007100720073007400750076007700780079007A007B007C007D007E007F
00C700FC00E900E200E400E000E500E700EA00EB00E800EF00EE00EC00C400C5
00C900E600C600F400F600F200FB00F900FF00D600DC00F800A300D800D70192
00E100ED00F300FA00F100D100AA00BA00BF00AE00AC00BD00BC00A100AB00BB
2591259225932502252400C100C200C000A9256325512557255D00A200A52510
25142534252C251C2500253C00E300C3255A25542569256625602550256C00A4
00F000D000CA00CB00C8013100CD00CE00CF2518250C2588258400A600CC2580
00D300DF00D400D200F500D500B500FE00DE00DA00DB00D900FD00DD00AF00B4
00AD00B1201700BE00B600A700F700B800B000A800B700B900B300B225A000A0
} ;# FIXME: result depends on content of encodings dir

test zipfs-2.2.4 {zipfs exists} -constraints zipfs -body {
    zipfs exists /abc/cp850.enc
} -result 1

test zipfs-2.2.5 {zipfs unmount while busy} -constraints zipfs -body {
    zipfs unmount $zipfile
} -returnCodes error -result {filesystem is busy}

test zipfs-2.2.6 {zipfs unmount} -constraints zipfs -body {
    close $zipfd
    zipfs unmount $zipfile
    zipfs exists /abc/cp850.enc
} -result 0

catch {file delete -force $tmpdir}

::tcltest::cleanupTests
return

# Local Variables:
# mode: tcl
# End: