Convert tests to tcltest and integrate into Travis (#5)

* convert some tests to tcltest

* exit with non-zero value if any test fails
This commit is contained in:
Jeff Lawson 2019-02-04 13:54:54 -06:00 committed by GitHub
parent cd15f4d7af
commit 2915c7e0c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 107 additions and 30 deletions

View File

@ -17,4 +17,4 @@ script:
- if [ -f /usr/local/opt/tcl-tk/lib/tclConfig.sh ]; then ./configure --with-tcl=/usr/local/opt/tcl-tk/lib --prefix=/usr/local; else ./configure; fi
- make
- sudo make install
- make test

View File

@ -239,7 +239,7 @@ install-doc: doc
done
test: binaries libraries
$(TCLSH) `@CYGPATH@ $(srcdir)/tests/all.tcl` $(TESTFLAGS)
cd $(srcdir)/tests && $(TCLSH) `@CYGPATH@ ./all.tcl` $(TESTFLAGS)
shell: binaries libraries
@$(TCLSH) $(SCRIPT)

38
tests/all.tcl Executable file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env tclsh
package require tcltest
::tcltest::configure -testdir [file dirname [file normalize [info script]]]
# The following will be upleveled and run whenever a test calls
# ::tcltest::loadTestedCommands
::tcltest::configure -load {
namespace import ::tcltest::*
}
::tcltest::skipFiles [list]
# Hook to determine if any of the tests failed. Then we can exit with
# proper exit code: 0=all passed, 1=one or more failed
proc tcltest::cleanupTestsHook {} {
variable numTests
set ::exitCode [expr {$numTests(Failed) > 0}]
}
# Allow command line arguments to be passed to the configure command
# This supports only running a single test or a single test file
::tcltest::configure {*}$argv
::tcltest::runAllTests
if {$exitCode == 1} {
puts "====== FAIL ====="
exit $exitCode
} else {
puts "====== SUCCESS ====="
}

View File

@ -1,6 +0,0 @@
package require TclCurl
set escaped [curl::escape {What about this?}]
puts "String to escape: What about this? - $escaped"
puts "And the reverse: [curl::unescape $escaped]"

19
tests/escape.test Executable file
View File

@ -0,0 +1,19 @@
#!/usr/local/bin/tclsh
package require TclCurl
package require tcltest
namespace import ::tcltest::*
test 1.01 {: Test escape} -body {
set escaped [curl::escape {What about this?}]
return $escaped
} -result {What%20about%20this%3F}
test 1.02 {: Test unescape} -body {
return [curl::unescape $escaped]
} -result {What about this?}
cleanupTests

View File

@ -1,9 +0,0 @@
package require TclCurl
puts "[curl::version]"

11
tests/version.test Executable file
View File

@ -0,0 +1,11 @@
package require TclCurl
package require tcltest
namespace import ::tcltest::*
test 1.01 {: Test that curl::version returns something} -body {
set result [curl::version]
return $result
} -match regexp -result {^TclCurl Version \d+\.\d+\.\d+ \(libcurl/\d+\.\d+\.\d+ .*?\)$}
cleanupTests

View File

@ -1,13 +0,0 @@
package require TclCurl
puts "Version [curl::versioninfo -version]"
puts "Version (num): [curl::versioninfo -versionnum]"
puts "Host: [curl::versioninfo -host]"
puts "Features: [curl::versioninfo -features]"
puts "SSL version: [curl::versioninfo -sslversion]"
puts "SSL version (num): [curl::versioninfo -sslversionnum]"
puts "libz version: [curl::versioninfo -libzversion]"
puts "Protocols [curl::versioninfo -protocols]"

37
tests/versionInfo.test Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/tclsh
package require TclCurl
package require tcltest
namespace import ::tcltest::*
test 1.01 {: Test that -version returns something} -body {
return [curl::versioninfo -version]
} -match regexp -result {^\d+\.\d+\.\d+$}
test 1.02 {: Test that -versionnum returns something} -body {
return [curl::versioninfo -versionnum]
} -match regexp -result {^[0-9A-F]+$}
test 1.03 {: Test that -features returns something} -body {
return [curl::versioninfo -features]
} -match regexp -result {^([A-Z0-9]+ ?)+$}
test 1.04 {: Test that -sslversion returns something} -body {
return [curl::versioninfo -sslversion]
} -match regexp -result {^(OpenSSL|GnuTLS|LibreSSL)/\d+\.\d+\.\d+\w*$}
test 1.05 {: Test that -sslversionnum returns something} -body {
return [curl::versioninfo -sslversionnum]
} -match regexp -result {^\d+$}
test 1.06 {: Test that -libzversion returns something} -body {
return [curl::versioninfo -libzversion]
} -match regexp -result {^\d+\.\d+\.\d+$}
test 1.07 {: Test that -protocols returns something} -body {
return [curl::versioninfo -protocols]
} -match regexp -result {^([a-z0-9]+ ?)+$}
cleanupTests