Skip to content
Tcl Source Code View Ticket
Login

View Ticket

filename-14.23.2 and filename-14.24 broken on Windows with -singleproc 1

Closed / Fixed8c63606802922ce324debc0ce6659e2792affcc0Created 1 year agoUpdated 267 days ago
Descriptionmarkdown2025-07-30 14:04:38

Running the test suite on Windows with -singleproc 1 results in two failures that do not show up in -singleproc 0 runs. This is not the usual failure resulting from the failure of command to clean up after themselves but rather what I consider fundamentally broken attempts to test Unix filename parsing on Windows and vice versa using testsetplatform.

(The REPRESENTATION line below comes from added debug code).

The -singleproc 0 case:

$ make -s test TESTFLAGS="-f fileName.test -singleproc 0 -verbose e"
...
fileName.test
REPRESENTATION:value is a pure string with a refcount of 1, object pointer at 0x8ac980, string representation "/"

Tests ended at Wed Jul 30 18:59:37 +0530 2025
all.tcl:        Total   300     Passed  276     Skipped 24      Failed  0

The -singleproc 1 run reports two failures:

$ make -s test TESTFLAGS="-f fileName.test -singleproc 1 -verbose e"
...
fileName.test
REPRESENTATION:value is a path with a refcount of 14, object pointer at 0x1379570, internal representation 0x3da18d0:0x0, string representation "/"

==== filename-14.23.2 slash globbing FAILED
---- Result was:
C:/
---- Result should have been (exact matching):
/
==== filename-14.23.2 FAILED

==== filename-14.24 slash globbing FAILED
---- Result was:
C:/
---- Result should have been (exact matching):
/
==== filename-14.24 FAILED

Tests ended at Wed Jul 30 18:59:49 +0530 2025
all.tcl:        Total   300     Passed  274     Skipped 24      Failed  2

Tcl is actually returning the correct result. The expected result that is constructed as -result [file normalize /] is also theoretically correct. The reason for failure is subtle but the REPRESENTATION lines above provide the hint.

The fileName.test suite attempts to test file name parsing for platforms other than the host platform. So on Windows for example, it also tries to test for correct parsing as per Unix conventions. It does this through the use of the rather dubious (imo) tcltest command testsetplatform which modifies the internal global tclPlatform into thinking it is Unix. The tests then alternate between testing Unix conventions and Windows conventions by each test calling testsetplatform unix or testsetplatform windows.

The problem is that the Tcl path manipulation code caches the normalized form of a path. At some point in the -singleproc 1 case, the literal / has its internal representation changed to type path which holds the normalized path as per Unix. When the Windows version of the test runs, it calls testsetplatform windows but file normalize / never looks at tclPlatform because it sees the / literal having a cached normalized form and returns it, not realizing that cached form was constructed as per Unix conventions. The -singleproc 0 case does not see this failure because as shown by the REPRESENTATION lines, the / literal is not cached.

The test cases can be fixed by ensuring / does not have an internal rep, e.g. file normalize [string index x/ 1] or similar.

The bigger issue to me is that attempting to emulate another platform file name parsing on a different platform is wrong headed unless it is specifically a feature of the language (which it is not) and the language implementation is written to handle it correctly (which it is not either). As fileName.test itself warns, any attempts at cd, or other file system operations when testsetplatform is in use will result in undefined behaviour and crashes. Furthermore, the caching feature of the path Tcl_Obj internal representation makes this rather fragile.

So, I would like to expunge the uses of testsetplatform from fileName.test. Since the Tcl implementation is not written for this cross-platform switching, the test suite should not try to fool it either. Test Unix on Unix, WIndows on Windows.

Thoughts from anyone who's read to the end :-) ?

Referenced by2
  • 0dc705217dMerge 9.0 - Workaround for [8c63606802] - testsetplatform / path caching with -singleproc 1 check-in2025-07-30 16:23:17
  • 55a5ddf7e6Workaround for [8c63606802] - testsetplatform / path caching with -singleproc 1 check-in2025-07-30 16:20:10
oehharplain2025-07-30 18:39:01
+1 to remove.
Thanks for thegreat analysis!
Harald
apnadkarniplain2026-03-11 07:06:09
Closing as those specific tests have been fixed to avoid caching of the normalized path.

However, the whole testsetplatform configuration is a misfeature in my opinion but that's a bigger kettle of fish that can be addressed elsewhere.
Log in (anonymous is fine) to add a comment.