From 2915c7e0c86cf99491ca4a973ef4c4dd06a8055c Mon Sep 17 00:00:00 2001 From: Jeff Lawson Date: Mon, 4 Feb 2019 13:54:54 -0600 Subject: [PATCH] Convert tests to tcltest and integrate into Travis (#5) * convert some tests to tcltest * exit with non-zero value if any test fails --- .travis.yml | 2 +- Makefile.in | 2 +- tests/all.tcl | 38 ++++++++++++++++++++++++++++++++++++++ tests/escape.tcl | 6 ------ tests/escape.test | 19 +++++++++++++++++++ tests/version.tcl | 9 --------- tests/version.test | 11 +++++++++++ tests/versionInfo.tcl | 13 ------------- tests/versionInfo.test | 37 +++++++++++++++++++++++++++++++++++++ 9 files changed, 107 insertions(+), 30 deletions(-) create mode 100755 tests/all.tcl delete mode 100755 tests/escape.tcl create mode 100755 tests/escape.test delete mode 100755 tests/version.tcl create mode 100755 tests/version.test delete mode 100755 tests/versionInfo.tcl create mode 100755 tests/versionInfo.test diff --git a/.travis.yml b/.travis.yml index ca02919..d028b2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/Makefile.in b/Makefile.in index 9d6a700..65bee80 100755 --- a/Makefile.in +++ b/Makefile.in @@ -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) diff --git a/tests/all.tcl b/tests/all.tcl new file mode 100755 index 0000000..f883027 --- /dev/null +++ b/tests/all.tcl @@ -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 =====" +} + diff --git a/tests/escape.tcl b/tests/escape.tcl deleted file mode 100755 index b4bb6d4..0000000 --- a/tests/escape.tcl +++ /dev/null @@ -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]" diff --git a/tests/escape.test b/tests/escape.test new file mode 100755 index 0000000..30ab794 --- /dev/null +++ b/tests/escape.test @@ -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 + + diff --git a/tests/version.tcl b/tests/version.tcl deleted file mode 100755 index 91f0826..0000000 --- a/tests/version.tcl +++ /dev/null @@ -1,9 +0,0 @@ -package require TclCurl - -puts "[curl::version]" - - - - - - diff --git a/tests/version.test b/tests/version.test new file mode 100755 index 0000000..b6726f7 --- /dev/null +++ b/tests/version.test @@ -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 diff --git a/tests/versionInfo.tcl b/tests/versionInfo.tcl deleted file mode 100755 index 547392b..0000000 --- a/tests/versionInfo.tcl +++ /dev/null @@ -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]" - - diff --git a/tests/versionInfo.test b/tests/versionInfo.test new file mode 100755 index 0000000..1e59113 --- /dev/null +++ b/tests/versionInfo.test @@ -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