From Newsgroup: comp.lang.tcl
On Sun, 21 Dec 2025 13:04:04 -0800, et99 wrote:
On 12/20/2025 9:20 PM, Mark Summerfield wrote:
I want to create a mod-1.tm file that contains some functions.
However, I also want to include some tests.
If I use:
package require mod
I don't want any tests run.
But if I use:
$ tclsh mod-1.tm
or
$ tclsh mod-1.tm arg1 arg2
I want the tests to be run.
How can I do this?
The global argv0 should be different, in the 2 tclsh cases, it should be mod-1.tm while if you are doing the package require mod, in some other file, run as say, tclsh myapp.tcl, then argv0 would be myapp.tcl.
-e
Thank you and Emiliano for your answers. Both your approaches worked.
In the end I've decided to use this:
if {[string match *.tm $::argv0]} {
# this executes if run directly; otherwise ignored
}
I never create my own pkgIndex packages only .tm modules so this is all I need since
my applications always have a suffix of .tcl or .tk (or no suffix).
--- Synchronet 3.21a-Linux NewsLink 1.2