Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: c1dc0b184b86335a92a0cc8e068bf90ec52c88af1c2b375e8d547f8777458e9b
Ticket: 7abc1460c04b46880ae4e950befea5a5b45133d6
tcltest: under Tk, runAllTests exits with status 0 before reporting errors
User & Date: jan.nijtmans on 2026-11-20 15:42:50
Changes

  1. assignee changed to: "jan.nijtmans"
  2. closedate changed to: "2461365.1547541665"
  3. closer changed to: "jan.nijtmans"
  4. comment changed to:
    Under Tk, <tt>cleanupTests</tt> exits so that a test file run as the main script (<tt>wish foo.test</tt>) does not wait in the event loop. But <tt>runAllTests</tt> also calls <tt>cleanupTests 1</tt> after the last test file, and when the all file is the main script, this exits too, with status 0, before <tt>runAllTests</tt> lists the test files that exited with errors and before it returns its result. So under Tk, <tt>if {[tcltest::runAllTests]} {exit 1}</tt> never exits with 1, and "Test files exiting with errors" is never printed.
    
    all.tcl:
    <pre>
    package require Tk
    package require tcltest
    tcltest::configure -testdir [file dirname [file normalize [info script]]] {*}$argv
    if {[tcltest::runAllTests]} {
        exit 1
    }
    </pre>
    fail.test:
    <pre>
    package require tcltest
    namespace import tcltest::*
    test fail-1.1 {a failing test} -body {expr 1} -result 2
    cleanupTests
    </pre>
    <tt>wish all.tcl</tt> prints <tt>Failed 1</tt> but exits with status 0, with Tcl 8.6.18 and with the current main, with <tt>-singleproc</tt> 0 and 1.
    
    This makes the CI of Tk report success when tests fail at startup.
    
    Suggested fix: do not exit in <tt>cleanupTests</tt> when it is called from <tt>runAllTests</tt>. At the end of <tt>runAllTests</tt>, where the exit is needed (under Tk, with the all file as the main script), exit with status 1 if there were failures or test file errors, and 0 otherwise; elsewhere return the result as documented. Scripts which do not check the result keep working, but such runs then end with a non-zero status when tests fail.
    
  5. icomment:
    Merged to [fc10972b81621cc4|trunk], core-9-0-branch and core-8-6-branch
    
    Many thanks!
    
  6. login: "jan.nijtmans"
  7. mimetype: "text/x-fossil-wiki"
  8. resolution changed to: "Fixed"
  9. status changed to: "Closed"