Skip to content

Instantly share code, notes, and snippets.

@alexpulver
Last active January 14, 2017 07:35
Show Gist options
  • Save alexpulver/deedd951add38ade5e09cba561864acb to your computer and use it in GitHub Desktop.
Save alexpulver/deedd951add38ade5e09cba561864acb to your computer and use it in GitHub Desktop.
Suggested directory structure for tcltest-based test suites
#!/usr/bin/env bash
_MKDIR=/bin/mkdir
_MV=/bin/mv
if [ ! -e "tests-run" ]; then
echo "Please run bootstrap.sh from Git clone root directory"
exit
fi
$_MKDIR -p database tests/database
$_MV database-DataManager.itcl database/DataManager.itcl
$_MV tests-database-DataManager.test tests/database/DataManager.test
$_MV tests-run tests/run
package require Itcl
namespace import -force itcl::class
class DataManager {
public {
method getPath {} {return "/data"}
}
}
package require tcltest
::tcltest::loadTestedCommands
::tcltest::test getPath {
Check that expected absolute path without a trailing slash is returned.
} -body {
[DataManager #auto] getPath
} -result "/data"
::tcltest::cleanupTests
#!/usr/bin/env tclsh
package require tcltest
package require Tclx
set EXIT_STATUS 0
proc main {} {
set project_root [file dirname [file dirname [file normalize [info script]]]]
set ::env(PROJECT_ROOT) $project_root
configureLoadScript
foreach tests_dir [getTestsDirs [file join $project_root "tests"]] {
::tcltest::testsDirectory $tests_dir
::tcltest::workingDirectory $tests_dir
::tcltest::temporaryDirectory $tests_dir
eval ::tcltest::configure $::argv
::tcltest::runAllTests
}
return $::EXIT_STATUS
}
proc getTestsDirs {root} {
set tests_dirs [list]
for_recursive_glob test_path $root "*.test" {
set test_dir [file dirname $test_path]
if {[lsearch tests_dirs $test_dir] == -1} {
lappend tests_dirs $test_dir
}
}
return $tests_dirs
}
proc configureLoadScript {} {
::tcltest::loadScript {
package require Itcl
package require Tclx
namespace import -force itcl::*
for_recursive_glob library_path $::env(PROJECT_ROOT) "*.itcl" {
source $library_path
}
}
}
proc ::tcltest::cleanupTestsHook {} {
# This hook is executed after each call to ::tcltest::runAllTests for a
# specific directory. ::EXIT_STATUS can be 1 or 0. We want to make sure
# that ::EXIT_STATUS is not reset to 0 after it was set to 1.
if {$::EXIT_STATUS} {
return
} else {
set ::EXIT_STATUS [expr $::tcltest::numTests(Failed) > 0]
}
}
exit [main]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment