aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2020-11-08 09:31:26 +1000
committerSteve Bennett <steveb@workware.net.au>2020-11-08 10:17:57 +1000
commit4b865fed1ad29c97c1b21757d953886758b22796 (patch)
tree809c9f5f10713cc01d42e45f0269c53559948b5b
parent8e1a22bac49a3acb1ee757ca34ed16b27bb7cd17 (diff)
downloadjimtcl-4b865fed1ad29c97c1b21757d953886758b22796.zip
jimtcl-4b865fed1ad29c97c1b21757d953886758b22796.tar.gz
jimtcl-4b865fed1ad29c97c1b21757d953886758b22796.tar.bz2
build: Fix build and tests for out-of-tree build
Loadable modules and tests Fixes #179 Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--Makefile.in3
-rw-r--r--auto.def2
-rw-r--r--tcltest.tcl24
-rw-r--r--tests/Makefile.in4
-rw-r--r--tests/error.test4
-rw-r--r--tests/errors.tcl2
-rw-r--r--tests/infoframe.test4
-rw-r--r--tests/runall.tcl8
-rw-r--r--tests/stacktrace.test16
-rw-r--r--tests/testing.tcl13
10 files changed, 46 insertions, 34 deletions
diff --git a/Makefile.in b/Makefile.in
index 1f77b86..0433882 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -44,6 +44,7 @@ LIBS += @LIBS@
exec_prefix ?= @exec_prefix@
prefix ?= @prefix@
docdir = @docdir@
+srcdir := @srcdir@
CC += -Wall $(OPTIM) -I.
CXX += -Wall $(OPTIM) -I.
@@ -130,7 +131,7 @@ uninstall:
@endif
test check: $(JIMSH)
- cd @srcdir@/tests; $(DEF_LD_PATH) $(MAKE) jimsh=@builddir@/jimsh TOPSRCDIR=..
+ $(DEF_LD_PATH) $(MAKE) -C tests jimsh=@builddir@/jimsh
$(OBJS) jimsh.o initjimsh.o: Makefile $(wildcard *.h)
diff --git a/auto.def b/auto.def
index 3c8f272..49990b9 100644
--- a/auto.def
+++ b/auto.def
@@ -558,7 +558,7 @@ foreach mod $extinfo(module-c) {
set obj [file rootname $src].o
lappend objs $obj
lappend lines "\t\$(ECHO)\t\"\tCC\t$obj\""
- lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(SHOBJ_CFLAGS) -c -o $obj $src"
+ lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(SHOBJ_CFLAGS) -c -o $obj \$(srcdir)/$src"
}
lappend lines "\t\$(ECHO)\t\"\tLDSO\t\$@\""
lappend lines "\t\$(Q)\$(CC) \$(CFLAGS) \$(LDFLAGS) \$(SHOBJ_LDFLAGS) -o \$@ $objs \$(SH_LIBJIM) $libs"
diff --git a/tcltest.tcl b/tcltest.tcl
index 3e14844..f93a35b 100644
--- a/tcltest.tcl
+++ b/tcltest.tcl
@@ -10,6 +10,7 @@ set testinfo(numskip) 0
set testinfo(numtests) 0
set testinfo(reported) 0
set testinfo(failed) {}
+set testinfo(source) [file tail $::argv0]
# -verbose or $testverbose show OK/ERR of individual tests
if {[lsearch $argv "-verbose"] >= 0 || [info exists env(testverbose)]} {
@@ -68,7 +69,7 @@ proc testCmdConstraints {args} {
}
proc skiptest {{msg {}}} {
- puts [format "%16s: --- skipped$msg" $::argv0]
+ puts [format "%16s: --- skipped$msg" $::testinfo(source)]
exit 0
}
@@ -168,7 +169,7 @@ proc package-or-skip {name} {
if {[catch {
package require $name
}]} {
- puts [format "%16s: --- skipped" $::argv0]
+ puts [format "%16s: --- skipped" $::testinfo(source)]
exit 0
}
}
@@ -194,6 +195,21 @@ proc bytestring {x} {
return $x
}
+# Takes a stacktrace and applies [file tail] to the filenames.
+# This allows stacktrace tests to be run from a directory other than the source directory.
+proc basename-stacktrace {stacktrace} {
+ set result {}
+ foreach {p f l} $stacktrace {
+ lappend result $p [file tail $f] $l
+ }
+ return $result
+}
+
+# Takes a list of {filename line} and returns {basename line}
+proc basename-source {list} {
+ list [file tail [lindex $list 0]] [lindex $list 1]
+}
+
# Note: We don't support -output or -errorOutput yet
proc test {id descr args} {
set default [dict create -returnCodes {ok return} -match exact -result {} -constraints {} -body {} -setup {} -cleanup {}]
@@ -311,9 +327,9 @@ proc testreport {} {
incr ::testinfo(reported)
if {$::testinfo(verbose)} {
- puts -nonewline "\n$::argv0"
+ puts -nonewline "\n$::testinfo(source)"
} else {
- puts -nonewline [format "%16s" $::argv0]
+ puts -nonewline [format "%16s" $::testinfo(source)]
}
puts [format ": Total %5d Passed %5d Skipped %5d Failed %5d" \
$::testinfo(numtests) $::testinfo(numpass) $::testinfo(numskip) $::testinfo(numfail)]
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 0567ff0..e89f2fb 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -4,10 +4,10 @@ tclsh ?= tclsh
DEF_LD_PATH := @LD_LIBRARY_PATH@="@builddir@:$(@LD_LIBRARY_PATH@)"
test:
- @$(DEF_LD_PATH) $(jimsh) runall.tcl
+ @$(DEF_LD_PATH) $(jimsh) @abs_top_srcdir@/tests/runall.tcl
tcl:
- @rc=0; for i in *.test; do $(tclsh) -encoding utf-8 $$i || rc=$?; done; exit $$rc
+ @rc=0; for i in @abs_top_srcdir@/tests/*.test; do $(tclsh) -encoding utf-8 $$i || rc=$?; done; exit $$rc
clean:
rm -f gorp.file2 gorp.file sleepx test1 exec.tmp1
diff --git a/tests/error.test b/tests/error.test
index 65dd506..312155b 100644
--- a/tests/error.test
+++ b/tests/error.test
@@ -15,7 +15,7 @@ test error-1.1 "Rethrow caught error" {
set rc [catch {b} msg]
#puts stderr "error-1.1\n[errorInfo $msg]\n"
- list $rc $msg [info stacktrace]
+ list $rc $msg [basename-stacktrace [info stacktrace]]
} {1 {error thrown from a} {{} error.test 4 a error.test 8 b error.test 15}}
proc c {} {
@@ -44,7 +44,7 @@ test error-1.2 "Modify stacktrace" {
# Now rethrow with the new stack
set rc [catch {error $msg $newst} msg]
#puts [errorInfo $msg]
- info stacktrace
+ basename-stacktrace [info stacktrace]
} {{} error.test 4 a error.test 22 c error.test 26 e error.test 34}
# Package should be able to invoke exit, which should exit if not caught
diff --git a/tests/errors.tcl b/tests/errors.tcl
index 0992c59..37aff21 100644
--- a/tests/errors.tcl
+++ b/tests/errors.tcl
@@ -21,7 +21,7 @@ proc error_generator {type} {
package require dummy
}
source {
- source dummy.tcl
+ source [file dirname [info script]]/dummy.tcl
}
badpackage {
package require bogus
diff --git a/tests/infoframe.test b/tests/infoframe.test
index f1619f5..0bfd7a9 100644
--- a/tests/infoframe.test
+++ b/tests/infoframe.test
@@ -2,9 +2,9 @@ source [file dirname [info script]]/testing.tcl
needs constraint jim
proc a {n} {
if {$n eq "trace"} {
- stacktrace
+ basename-stacktrace [stacktrace]
} else {
- info frame $n
+ basename-stacktrace [info frame $n]
}
}
diff --git a/tests/runall.tcl b/tests/runall.tcl
index 57f6399..2b49526 100644
--- a/tests/runall.tcl
+++ b/tests/runall.tcl
@@ -5,12 +5,14 @@
lappend auto_path .
+set testdir [file dirname [info script]]
+
# In case interp is a module
catch {package require interp}
if {[info commands interp] eq ""} {
set rc 1
- foreach script [lsort [glob *.test]] {
+ foreach script [lsort [glob $testdir/*.test]] {
if {[catch {
exec [info nameofexecutable] $script >@stdout 2>@stderr
set rc 0
@@ -21,10 +23,10 @@ if {[info commands interp] eq ""} {
exit $rc
} else {
array set total {pass 0 fail 0 skip 0 tests 0}
- foreach script [lsort [glob *.test]] {
+ foreach script [lsort [glob $testdir/*.test]] {
set ::argv0 $script
- if {$script eq "signal.test"} {
+ if {[file tail $script] eq "signal.test"} {
# special case, can't run this in a child interpeter
catch -exit {
source $script
diff --git a/tests/stacktrace.test b/tests/stacktrace.test
index 847297b..cafbcfc 100644
--- a/tests/stacktrace.test
+++ b/tests/stacktrace.test
@@ -16,9 +16,9 @@ proc main {} {
test err-$id1.$id2 "Stacktrace on error type $type, method $method" {
set rc [catch {error_caller $type $method} msg]
#puts "\n-----------------\n$type, $method\n[errorInfo $msg]\n\n"
- if {$::SHOW_EXPECTED} { puts stderr "\terr-$id1.$id2 {[list $rc $msg [info stacktrace]]}" }
+ if {$::SHOW_EXPECTED} { puts stderr "\terr-$id1.$id2 {[list $rc $msg [basename-stacektrace [info stacktrace]]]}" }
- list $rc $msg [info stacktrace]
+ list $rc $msg [basename-stacktrace [info stacktrace]]
} $exp
}
}
@@ -29,9 +29,9 @@ proc main {} {
test err-10.1 "Stacktrace on error from unknown (badcmd, call)" {
set rc [catch {error_caller badcmd call} msg]
#puts stderr "err-10.1\n[errorInfo $msg]\n"
- #puts stderr "\terr-10.1 {[list $rc $msg [info stacktrace]]}"
+ #puts stderr "\terr-10.1 {[list $rc $msg [basename-stacktrace [info stacktrace]]]}"
- list $rc $msg [info stacktrace]
+ list $rc $msg [basename-stacktrace [info stacktrace]]
} {1 {from unknown} {{} stacktrace.test 26 {} errors.tcl 6 error_generator errors.tcl 44 error_caller stacktrace.test 30}}
rename unknown ""
@@ -51,17 +51,17 @@ proc main {} {
set g {four}
test source-1.1 "Basic line numbers" {
- info source $a
+ basename-source [info source $a]
} {stacktrace.test 39}
test source-1.2 "Line numbers after command with escaped newlines" {
- info source $c
+ basename-source [info source $c]
} {stacktrace.test 43}
test source-1.3 "Line numbers after string with newlines" {
- info source $e
+ basename-source [info source $e]
} {stacktrace.test 47}
test source-1.4 "Line numbers after string with escaped newlines" {
- info source $g
+ basename-source [info source $g]
} {stacktrace.test 51}
}
diff --git a/tests/testing.tcl b/tests/testing.tcl
index 95c0fe3..6702f83 100644
--- a/tests/testing.tcl
+++ b/tests/testing.tcl
@@ -1,12 +1,5 @@
# Find and load the Jim tcltest wrapper
-if {[catch {info version}]} {
- # Tcl
- source [file dirname [info script]]/../tcltest.tcl
-} else {
- # Jim
- if {[exists env(TOPSRCDIR)]} {
- set auto_path [list $env(TOPSRCDIR) {*}$auto_path]
- }
+source [file dirname [info script]]/../tcltest.tcl
- package require tcltest
-}
+# If jimsh is not installed we may also need to include top_srcdir for Tcl modules (.. from this script)
+set auto_path [list [file dirname [info script]]/.. {*}$auto_path]