Browse Source

runtests.tcl: default tcltest -tmpdir to a self-cleaning system-temp dir

makeFile/makeDirectory output previously landed in the working directory -
aborted core exec.test runs littered src/tests with untracked helper files
(cat, echo, gorp.file ...). Unless -tcltestoptions supplies -tmpdir, a
fresh directory from 'file tempdir' (TMPDIR/TEMP/TMP + pid fallback for
tcl 8.6) is configured and deleted before exit; a hard-aborted run now
leaves litter in the OS temp area rather than the source tree.
Takes effect in single-process mode; multi-process mode still does not
forward tcltest options to child processes (pre-existing todo).
Contract documented in src/tests/AGENTS.md.

Assisted-by: harness=claude; primary-model=claude-fable-5; api-location=anthropic.com
master
Julian Noble 6 days ago
parent
commit
6d8228c2f8
  1. 1
      src/tests/AGENTS.md
  2. 25
      src/tests/runtests.tcl

1
src/tests/AGENTS.md

@ -15,6 +15,7 @@ Top-level test harness and source-tree tests for ShellSpy/Punk. Tests here exerc
- `runtests.tcl` is the primary source-tree test entry point; sublevel `all.tcl` files are a legacy pattern and are not required.
- Tests use `tcltest` unless a child AGENTS.md documents a different local harness.
- `runtests.tcl` excludes `AGENTS.md` and `*.tcl` helper files when discovering `.test` files.
- `runtests.tcl` defaults tcltest `-tmpdir` (the `makeFile`/`makeDirectory` location) to a fresh directory under the system temp area, deleted before exit, so test helper files never land in the source tree (aborted core exec.test runs previously littered `src/tests`). A `-tmpdir` supplied via `-tcltestoptions` overrides this. Applies to single-process mode; multi-process mode does not yet forward tcltest options to child processes.
- The single-process testinterp runs `package prefer latest` so alpha-versioned dev modules (`999999.0a1.0`) are preferred over stable bootsupport/vendored copies on unversioned `package require`.
- The testinterp module path includes `src/vendormodules` (and `src/vendormodules_tcl<major>` when present) so vendored dependencies such as `voo` resolve in tests.
- Tests should run against source modules and libraries from `src/`, not installed packages or root-level build outputs.

25
src/tests/runtests.tcl

@ -414,6 +414,27 @@ if {[llength $file_globs] == 0} {
dict set tcltestoptions -file $file_globs
#Default tcltest's -tmpdir (makeFile/makeDirectory location) to a fresh directory under the system temp area.
#Without this, tcltest helpers land in the working directory - aborted runs of e.g core exec.test littered
#src/tests with untracked helper files (cat, echo, gorp.file ...). A user-supplied -tmpdir via -tcltestoptions wins.
#Cleaned up (file delete -force) before exit; an aborted run leaves it in the OS temp area rather than the source tree.
set runtests_tmpdir ""
if {![dict exists $opt_tcltestoptions -tmpdir]} {
if {[catch {file tempdir} runtests_tmpdir]} {
#'file tempdir' requires tcl 8.7+ - fall back to env temp + pid subdir for 8.6
set runtests_tmpdir ""
foreach evar {TMPDIR TEMP TMP} {
if {[info exists ::env($evar)] && [file isdirectory $::env($evar)]} {
set runtests_tmpdir [file join $::env($evar) runtests_tmp_[pid]]
file mkdir $runtests_tmpdir
break
}
}
}
if {$runtests_tmpdir ne ""} {
dict set tcltestoptions -tmpdir $runtests_tmpdir
}
}
#puts "tcltestoptions: $tcltestoptions"
#puts "file_globs: $file_globs"
@ -801,6 +822,10 @@ if {!$report_json_only} {
puts stdout ""
}
if {$runtests_tmpdir ne "" && [file isdirectory $runtests_tmpdir]} {
catch {file delete -force $runtests_tmpdir}
}
if {$opt_strict_exit} {
if {[dict get $tallydict failed] > 0 || [llength [dict get $tallydict files_with_fails]] > 0} {
exit 1

Loading…
Cancel
Save