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:
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:
ad7092b843 2019-09-16 rkeene: tcltest::testConstraint tcl87 [string match "8.7.*" [info patchlevel]]
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: tcltest::test xvfs-basic-seek "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"
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
ad7092b843 2019-09-16 rkeene: unset -nocomplain fd size done calls output
ad7092b843 2019-09-16 rkeene: } -result {1 1}
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/*"
ad7092b843 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
ad7092b843 2019-09-16 rkeene: } -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
ad7092b843 2019-09-16 rkeene: } -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:
ad7092b843 2019-09-16 rkeene: exit 1
fa71466879 2019-09-14 rkeene: }
fa71466879 2019-09-14 rkeene:
fa71466879 2019-09-14 rkeene: puts "ALL TESTS PASSED"
ad7092b843 2019-09-16 rkeene:
ad7092b843 2019-09-16 rkeene: exit 0