Skip to content

Commit ab291eb

Browse files
Isolate Windows shared tests in a per-test working directory
The Windows shared-test bat wrote fixed-name artifacts (<stem>.obj, <stem>.dll, <stem>.lib) directly in the shared test/tester cwd, while the imported-module stem is not unique across test variants - e.g. decl_class.ts feeds the -shared, -compile-time and -jit variants, and export_vars2.ts feeds two variants. Under `ctest -j` these run concurrently and stomp/delete each other's artifacts, causing random failures (e.g. test-compile-shared-decl-emit-class, test-compile-shared-export-import-vars-2). Port the per-test WORKDIR isolation the Linux branch already uses: create a unique <tempname>_wd dir, cd into it, build/link/run there (the shared lib keeps its real <stem> name needed for import resolution but can no longer collide), write .txt/.err to the parent dir the runner reads from, then remove the dir. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 82ff7ce commit ab291eb

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎tsc/test/tester/test-runner.cpp‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,16 @@ void createSharedMultiBatchFile(std::string tempOutputFileNameNoExt, std::vector
428428
batFile << "set TSC_LIB_PATH=" << TEST_TSC_LIBPATH << std::endl;
429429
batFile << "set GC_LIB_PATH=" << TEST_GCPATH << std::endl;
430430

431+
// run everything inside a unique per-test working directory: the shared lib must keep its
432+
// real name (<stem>.dll) for `import './<stem>'` to resolve, but that name is not unique
433+
// across tests reusing the same source file (e.g. decl_class.ts feeds the compile/compile-time/jit
434+
// variants) - isolating the cwd avoids parallel collisions under `ctest -j`. The .txt/.err output
435+
// is written to the parent dir where the runner reads it from.
436+
batFile << "set WORKDIR=" << tempOutputFileNameNoExt << "_wd" << std::endl;
437+
batFile << "if exist %WORKDIR% rmdir /s /q %WORKDIR%" << std::endl;
438+
batFile << "mkdir %WORKDIR%" << std::endl;
439+
batFile << "cd %WORKDIR%" << std::endl;
440+
431441
auto first = true;
432442
std::stringstream shared_objs;
433443
std::stringstream shared_libs;
@@ -472,7 +482,7 @@ void createSharedMultiBatchFile(std::string tempOutputFileNameNoExt, std::vector
472482

473483
if (jitRun)
474484
{
475-
batFile << "%TSCEXEPATH%\\tsc.exe --emit=jit " << tsc_opt << " --shared-libs=%TSCEXEPATH%/TypeScriptRuntime.dll " << *files.begin() << " 1> %FILENAME%.txt 2> %FILENAME%.err"
485+
batFile << "%TSCEXEPATH%\\tsc.exe --emit=jit " << tsc_opt << " --shared-libs=%TSCEXEPATH%/TypeScriptRuntime.dll " << *files.begin() << " 1> ..\\%FILENAME%.txt 2> ..\\%FILENAME%.err"
476486
<< std::endl;
477487

478488
batFile << "del " << shared_libs.str() << std::endl;
@@ -494,7 +504,7 @@ void createSharedMultiBatchFile(std::string tempOutputFileNameNoExt, std::vector
494504

495505
batFile << "del " << exec_objs.str() << std::endl;
496506

497-
batFile << "call " RUN_CMD "%FILENAME%.exe 1> %FILENAME%.txt 2> %FILENAME%.err" << std::endl;
507+
batFile << "call " RUN_CMD "%FILENAME%.exe 1> ..\\%FILENAME%.txt 2> ..\\%FILENAME%.err" << std::endl;
498508

499509
batFile << "echo off" << std::endl;
500510
batFile << "del " << shared_libs.str() << std::endl;
@@ -506,6 +516,12 @@ void createSharedMultiBatchFile(std::string tempOutputFileNameNoExt, std::vector
506516
batFile << "echo on" << std::endl;
507517
}
508518

519+
// leave and remove the per-test working directory (with the shared lib, exe, objs, etc.)
520+
batFile << "echo off" << std::endl;
521+
batFile << "cd .." << std::endl;
522+
batFile << "rmdir /s /q %WORKDIR%" << std::endl;
523+
batFile << "echo on" << std::endl;
524+
509525
batFile.close();
510526
#else
511527
std::ofstream batFile(tempOutputFileNameNoExt + BAT_NAME);

0 commit comments

Comments
 (0)