ad7092b843 2019-09-16 rkeene: #! /usr/bin/env tclsh
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: package require tcltest
ad7092b843 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::testConstraint tcl87 [string match "8.7.*" [info patchlevel]]
10f67b2ced 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::configure -verbose pbse
ad7092b843 2019-09-16 rkeene: tcltest::configure {*}$argv
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: set rootDir "//xvfs:/example"
ad7092b843 2019-09-16 rkeene: set rootDirNative [file join [pwd] example]
ad7092b843 2019-09-16 rkeene: #set rootDir $rootDirNative
ad7092b843 2019-09-16 rkeene: set testFile "${rootDir}/foo"
5583d77f1c 2019-09-14 rkeene:
5583d77f1c 2019-09-14 rkeene: proc glob_verify {args} {
ad7092b843 2019-09-16 rkeene: set rv [glob -nocomplain -directory $::rootDir {*}$args]
ad7092b843 2019-09-16 rkeene: set verify [glob -nocomplain -directory $::rootDirNative {*}$args]
5583d77f1c 2019-09-14 rkeene:
5583d77f1c 2019-09-14 rkeene: if {[llength $rv] != [llength $verify]} {
5583d77f1c 2019-09-14 rkeene: error "VERIFY FAILED: glob ... $args ($rv versus $verify)"
5583d77f1c 2019-09-14 rkeene: }
5583d77f1c 2019-09-14 rkeene:
5583d77f1c 2019-09-14 rkeene: return $rv
5583d77f1c 2019-09-14 rkeene: }
5583d77f1c 2019-09-14 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::customMatch boolean [list apply {{expected actual} {
ad7092b843 2019-09-16 rkeene: if {!!$expected == !!$actual} {
ad7092b843 2019-09-16 rkeene: return true
ad7092b843 2019-09-16 rkeene: } else {
ad7092b843 2019-09-16 rkeene: return false
ad7092b843 2019-09-16 rkeene: }
ad7092b843 2019-09-16 rkeene: }}]
ad7092b843 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-seek-basic "Xvfs Seek Test" -setup {
ad7092b843 2019-09-16 rkeene: set fd [open $testFile]
ad7092b843 2019-09-16 rkeene: } -body {
ad7092b843 2019-09-16 rkeene: seek $fd 0 end
ad7092b843 2019-09-16 rkeene: seek $fd -1 current
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: read $fd 1
ad7092b843 2019-09-16 rkeene: } -cleanup {
ad7092b843 2019-09-16 rkeene: close $fd
ad7092b843 2019-09-16 rkeene: unset fd
ad7092b843 2019-09-16 rkeene: } -result "\n"
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-seek-past-eof "Xvfs Seek Past EOF File Test" -setup {
10f67b2ced 2019-09-16 rkeene: set fd [open $testFile]
10f67b2ced 2019-09-16 rkeene: } -body {
10f67b2ced 2019-09-16 rkeene: seek $fd 1 end
10f67b2ced 2019-09-16 rkeene: } -cleanup {
10f67b2ced 2019-09-16 rkeene: close $fd
10f67b2ced 2019-09-16 rkeene: unset fd
10f67b2ced 2019-09-16 rkeene: } -match glob -returnCodes error -result "*: invalid argument"
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-seek-past-eof "Xvfs Seek Past EOF File Test" -setup {
10f67b2ced 2019-09-16 rkeene: set fd [open $testFile]
10f67b2ced 2019-09-16 rkeene: } -body {
10f67b2ced 2019-09-16 rkeene: seek $fd -10 current
10f67b2ced 2019-09-16 rkeene: } -cleanup {
10f67b2ced 2019-09-16 rkeene: close $fd
10f67b2ced 2019-09-16 rkeene: unset fd
10f67b2ced 2019-09-16 rkeene: } -match glob -returnCodes error -result "*: invalid argument"
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-seek-read-past-eof "Xvfs Seek Then Read Past EOF Test" -setup {
10f67b2ced 2019-09-16 rkeene: set fd [open $testFile]
10f67b2ced 2019-09-16 rkeene: } -body {
10f67b2ced 2019-09-16 rkeene: seek $fd 0 end
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: read $fd 1
10f67b2ced 2019-09-16 rkeene: read $fd 1
10f67b2ced 2019-09-16 rkeene: } -cleanup {
10f67b2ced 2019-09-16 rkeene: close $fd
10f67b2ced 2019-09-16 rkeene: unset fd
10f67b2ced 2019-09-16 rkeene: } -result ""
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-basic-open-write "Xvfs Open For Writing Test" -setup {
10f67b2ced 2019-09-16 rkeene: unset -nocomplain fd
10f67b2ced 2019-09-16 rkeene: } -body {
10f67b2ced 2019-09-16 rkeene: set fd [open $rootDir/new-file w]
10f67b2ced 2019-09-16 rkeene: close $fd
10f67b2ced 2019-09-16 rkeene: } -cleanup {
10f67b2ced 2019-09-16 rkeene: if {[info exists fd]} {
10f67b2ced 2019-09-16 rkeene: close $fd
10f67b2ced 2019-09-16 rkeene: unset fd
10f67b2ced 2019-09-16 rkeene: }
10f67b2ced 2019-09-16 rkeene: catch {
10f67b2ced 2019-09-16 rkeene: file delete $rootDir/new-file
10f67b2ced 2019-09-16 rkeene: }
10f67b2ced 2019-09-16 rkeene: } -match glob -returnCodes error -result "*read*only file*system*"
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-basic-two-files "Xvfs Multiple Open Files Test" -setup {
ad7092b843 2019-09-16 rkeene: set fd1 [open $testFile]
ad7092b843 2019-09-16 rkeene: set fd2 [open $testFile]
ad7092b843 2019-09-16 rkeene: } -body {
ad7092b843 2019-09-16 rkeene: set data1 [read $fd1]
ad7092b843 2019-09-16 rkeene: close $fd1
ad7092b843 2019-09-16 rkeene: set data2 [read $fd2]
ad7092b843 2019-09-16 rkeene: close $fd2
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: expr {$data1 eq $data2}
ad7092b843 2019-09-16 rkeene: } -cleanup {
ad7092b843 2019-09-16 rkeene: unset -nocomplain fd1 fd2 data1 data2
ad7092b843 2019-09-16 rkeene: } -match boolean -result true
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-events "Xvfs Fileevent Test" -setup {
ad7092b843 2019-09-16 rkeene: set fd [open $testFile]
ad7092b843 2019-09-16 rkeene: seek $fd 0 end
ad7092b843 2019-09-16 rkeene: set size [tell $fd]
ad7092b843 2019-09-16 rkeene: seek $fd 0 start
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: set done false
ad7092b843 2019-09-16 rkeene: set calls 0
ad7092b843 2019-09-16 rkeene: set output ""
ad7092b843 2019-09-16 rkeene: } -body {
ad7092b843 2019-09-16 rkeene: fileevent $fd readable [list apply {{fd} {
ad7092b843 2019-09-16 rkeene: set pos [tell $fd]
ad7092b843 2019-09-16 rkeene: set x [read $fd 1]
ad7092b843 2019-09-16 rkeene: if {[string length $x] == 0} {
ad7092b843 2019-09-16 rkeene: set ::done true
ad7092b843 2019-09-16 rkeene: fileevent $fd readable ""
ad7092b843 2019-09-16 rkeene: }
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: lappend ::output $pos
ad7092b843 2019-09-16 rkeene: incr ::calls
ad7092b843 2019-09-16 rkeene: }} $fd]
ad7092b843 2019-09-16 rkeene: vwait done
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: list [expr {$calls == ($size + 1)}] [expr {[lsort -integer $output] eq $output}]
ad7092b843 2019-09-16 rkeene: } -cleanup {
ad7092b843 2019-09-16 rkeene: close $fd
10f67b2ced 2019-09-16 rkeene: update
ad7092b843 2019-09-16 rkeene: unset -nocomplain fd size done calls output
ad7092b843 2019-09-16 rkeene: } -result {1 1}
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-match-almost-root-neg "Xvfs Match Almost Root" -body {
10f67b2ced 2019-09-16 rkeene: file exists ${rootDir}_DOES_NOT_EXIST
10f67b2ced 2019-09-16 rkeene: } -match boolean -result false
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-glob-basic-any "Xvfs Glob Match Any Test" -body {
ad7092b843 2019-09-16 rkeene: llength [glob_verify *]
ad7092b843 2019-09-16 rkeene: } -result 3
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-glob-basic-limited "Xvfs Glob Match Limited Test" -body {
ad7092b843 2019-09-16 rkeene: llength [glob_verify f*]
ad7092b843 2019-09-16 rkeene: } -result 1
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-glob-basic-limited-neg "Xvfs Glob Match Limited Negative Test" -body {
ad7092b843 2019-09-16 rkeene: llength [glob_verify x*]
ad7092b843 2019-09-16 rkeene: } -result 0
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-glob-basic-limited-prefixed "Xvfs Glob Match Limited But With Directory Prefix Test" -body {
ad7092b843 2019-09-16 rkeene: llength [glob_verify ./f*]
ad7092b843 2019-09-16 rkeene: } -result 1
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-glob-basic-limited-and-typed-prefixed "Xvfs Glob Match Limited Path and Type Positive Test" -body {
ad7092b843 2019-09-16 rkeene: llength [glob_verify -type f ./f*]
ad7092b843 2019-09-16 rkeene: } -result 1
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-glob-basic-limited-and-typed-prefixed-neg "Xvfs Glob Match Limited Path and Type Negative Test" -body {
ad7092b843 2019-09-16 rkeene: llength [glob_verify -type d ./f*]
ad7092b843 2019-09-16 rkeene: } -result 0
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-glob-basic-limited-prefixed-other-dir-1 "Xvfs Glob Match Directory Included in Search Test (Count)" -body {
ad7092b843 2019-09-16 rkeene: llength [glob_verify lib/*]
ad7092b843 2019-09-16 rkeene: } -result 1
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-glob-basic-limited-prefixed-other-dir-2 "Xvfs Glob Match Directory Included in Search Test (Value)" -body {
ad7092b843 2019-09-16 rkeene: lindex [glob_verify lib/*] 0
ad7092b843 2019-09-16 rkeene: } -match glob -result "$rootDir/*"
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-access-basic-read "Xvfs acccess Read Basic Test" -body {
10f67b2ced 2019-09-16 rkeene: file readable $testFile
10f67b2ced 2019-09-16 rkeene: } -match boolean -result true
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-access-basic-write "Xvfs acccess Write Basic Test" -body {
10f67b2ced 2019-09-16 rkeene: file writable $testFile
10f67b2ced 2019-09-16 rkeene: } -match boolean -result false
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-access-basic-neg "Xvfs acccess Basic Negative Test" -body {
10f67b2ced 2019-09-16 rkeene: file executable $testFile
10f67b2ced 2019-09-16 rkeene: } -match boolean -result false
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-exists-basic-neg "Xvfs exists Basic Negative Test" -body {
10f67b2ced 2019-09-16 rkeene: file exists $rootDir/does-not-exist
10f67b2ced 2019-09-16 rkeene: } -match boolean -result false
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-stat-basic-file "Xvfs stat Basic File Test" -body {
10f67b2ced 2019-09-16 rkeene: file stat $testFile fileInfo
10f67b2ced 2019-09-16 rkeene: set fileInfo(type)
10f67b2ced 2019-09-16 rkeene: } -cleanup {
10f67b2ced 2019-09-16 rkeene: unset -nocomplain fileInfo
10f67b2ced 2019-09-16 rkeene: } -result file
10f67b2ced 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: tcltest::test xvfs-stat-basic-dir "Xvfs stat Basic Directory Test" -body {
10f67b2ced 2019-09-16 rkeene: file stat $rootDir/lib fileInfo
10f67b2ced 2019-09-16 rkeene: set fileInfo(type)
10f67b2ced 2019-09-16 rkeene: } -cleanup {
10f67b2ced 2019-09-16 rkeene: unset -nocomplain fileInfo
10f67b2ced 2019-09-16 rkeene: } -result directory
e4bde431db 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: # Broken in Tcl 8.6 and earlier
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-glob-advanced-dir-with-pattern "Xvfs Glob Match Pattern and Directory Together" -body {
ad7092b843 2019-09-16 rkeene: llength [glob //xvfs:/example/*]
ad7092b843 2019-09-16 rkeene: } -constraints tcl87 -result 3
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-glob-file-dirname "Xvfs Relies on file dirname" -body {
ad7092b843 2019-09-16 rkeene: lindex [glob -directory [file dirname $testFile] *] 0
ad7092b843 2019-09-16 rkeene: } -constraints tcl87 -match glob -result "$rootDir/*"
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-cwd-1 "Xvfs Can Be cwd" -setup {
ad7092b843 2019-09-16 rkeene: set startDir [pwd]
ad7092b843 2019-09-16 rkeene: } -body {
ad7092b843 2019-09-16 rkeene: cd $rootDir
ad7092b843 2019-09-16 rkeene: pwd
ad7092b843 2019-09-16 rkeene: } -cleanup {
ad7092b843 2019-09-16 rkeene: cd $startDir
ad7092b843 2019-09-16 rkeene: unset startDir
e4bde431db 2019-09-16 rkeene: } -constraints tcl87 -result $rootDir
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-cwd-2 "Xvfs Can Be cwd" -setup {
ad7092b843 2019-09-16 rkeene: set startDir [pwd]
ad7092b843 2019-09-16 rkeene: } -body {
ad7092b843 2019-09-16 rkeene: cd $rootDir
ad7092b843 2019-09-16 rkeene: cd lib
ad7092b843 2019-09-16 rkeene: lindex [glob *] 0
ad7092b843 2019-09-16 rkeene: } -cleanup {
ad7092b843 2019-09-16 rkeene: cd $startDir
ad7092b843 2019-09-16 rkeene: unset startDir
e4bde431db 2019-09-16 rkeene: } -constraints tcl87 -result "hello"
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: # Currently broken
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-package "Xvfs Can Be Package Directory" -setup {
ad7092b843 2019-09-16 rkeene: set startAutoPath $auto_path
ad7092b843 2019-09-16 rkeene: lappend auto_path ${rootDir}/lib
ad7092b843 2019-09-16 rkeene: } -body {
ad7092b843 2019-09-16 rkeene: package require hello
ad7092b843 2019-09-16 rkeene: set auto_path
ad7092b843 2019-09-16 rkeene: } -cleanup {
ad7092b843 2019-09-16 rkeene: set auto_path $startAutoPath
ad7092b843 2019-09-16 rkeene: unset startAutoPath
ad7092b843 2019-09-16 rkeene: } -constraints knownBug -result ""
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: # Output results
ad7092b843 2019-09-16 rkeene: if {$::tcltest::numTests(Failed) != 0} {
ad7092b843 2019-09-16 rkeene: set format "| %20s | %20s | %20s | %20s |"
ad7092b843 2019-09-16 rkeene: puts [string repeat - [string length [format $format - - - -]]]
ad7092b843 2019-09-16 rkeene: puts [format $format "Passed" "Failed" "Skipped" "Total"]
ad7092b843 2019-09-16 rkeene: puts [format $format \
ad7092b843 2019-09-16 rkeene: $::tcltest::numTests(Passed) \
ad7092b843 2019-09-16 rkeene: $::tcltest::numTests(Failed) \
ad7092b843 2019-09-16 rkeene: $::tcltest::numTests(Skipped) \
ad7092b843 2019-09-16 rkeene: $::tcltest::numTests(Total) \
ad7092b843 2019-09-16 rkeene: ]
ad7092b843 2019-09-16 rkeene: puts [string repeat - [string length [format $format - - - -]]]
ad7092b843 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: if {[info exists ::env(XVFS_TEST_EXIT_ON_FAILURE)]} {
10f67b2ced 2019-09-16 rkeene: exit $::env(XVFS_TEST_EXIT_ON_FAILURE)
10f67b2ced 2019-09-16 rkeene: }
ad7092b843 2019-09-16 rkeene: exit 1
fa71466879 2019-09-14 rkeene: }
38bed7cee0 2019-09-13 rkeene:
38bed7cee0 2019-09-13 rkeene: puts "ALL TESTS PASSED"
ad7092b843 2019-09-16 rkeene:
10f67b2ced 2019-09-16 rkeene: if {[info exists ::env(XVFS_TEST_EXIT_ON_SUCCESS)]} {
10f67b2ced 2019-09-16 rkeene: exit $::env(XVFS_TEST_EXIT_ON_SUCCESS)
10f67b2ced 2019-09-16 rkeene: }
ad7092b843 2019-09-16 rkeene: exit 0