Skip to content

Commit 16a1525

Browse files
committed
ts: test module over a removed current working dir
1 parent b398119 commit 16a1525

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

testsuite/example/siteconfig.tcl-1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,4 +437,11 @@ if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_SOURCESHFISHUNSET)]} {
437437
proc execShAndGetEnv [info args execShAndGetEnv] "$tracevarcall ; [info body execShAndGetEnv]"
438438
}
439439

440+
# supersede pwd procedure to raise an error
441+
if {[info exists env(TESTSUITE_ENABLE_SITECONFIG_PWDERROR)]} {
442+
proc pwd {} {
443+
error {Custom error message}
444+
}
445+
}
446+
440447
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
##############################################################################
2+
# Modules Revision 3.0
3+
# Providing a flexible user environment
4+
#
5+
# File: modules.00-init/%M%
6+
# Revision: %I%
7+
# First Edition: 2022/05/20
8+
# Last Mod.: %U%, %G%
9+
#
10+
# Authors: Xavier Delaruelle, [email protected]
11+
#
12+
# Description: Testuite testsequence
13+
# Command:
14+
# Sub-Command:
15+
#
16+
# Comment: %C{
17+
# Check current working directory retrieval error
18+
# }C%
19+
#
20+
##############################################################################
21+
22+
skip_if_quick_mode
23+
24+
# test execution of modulecmd from a removed current working directory
25+
# skip this test in the following situation:
26+
# - when coverage is enabled, as the cwd error will be caught by coverage tool
27+
# rather than getAbsolutePath procedure. The next test (pwd supersede) enable
28+
# coverage check of getAbsolutePath
29+
# - when running on Cygwin/MinGW/MSYS which are unaffected by cwd removal
30+
# - when running on Tcl 8.5 where test outputs are saved in files located in
31+
# current working directory
32+
if {![info exists env(COVERAGE)] && ![regexp {^(CYGWIN|MINGW|MSYS_NT).*}\
33+
$tcl_platform(os)] && [cmpversion $tclsh_version 8.6] > -1} {
34+
35+
# change MODULECMD for the test to make it an absolute path name
36+
set MODULECMD $env(TESTSUITEDIR)/../$MODULECMD
37+
38+
# create a temporary current working directory and remove it after changing to it
39+
set ORIG_CWD [pwd]
40+
file mkdir cwdtest
41+
cd cwdtest
42+
file delete ../cwdtest
43+
44+
set tserr "$error_msgs: error getting working directory name: no such file or directory"
45+
testouterr_cmd sh {load ./unk} ERR $tserr
46+
47+
# move back to testsuite working directory
48+
cd $ORIG_CWD
49+
unset MODULECMD
50+
}
51+
52+
# test pwd error catch in getAbsolutePath for coverage mode by superseding
53+
# the pwd procedure
54+
if {[siteconfig_isStderrTty]} {
55+
setenv_var TESTSUITE_ENABLE_SITECONFIG_PWDERROR 1
56+
set tserr "$error_msgs: Custom error message"
57+
testouterr_cmd sh {load ./unk} ERR $tserr
58+
unsetenv_var TESTSUITE_ENABLE_SITECONFIG_PWDERROR
59+
}
60+
61+
62+
#
63+
# Clean up variables used in this test case
64+
#
65+
66+
reset_test_env

0 commit comments

Comments
 (0)