Skip to content

Commit aed3715

Browse files
committed
bootstrap jimsh: pass all tests
In order to test bootstrap jimsh, it is very helpful if it can pass all the unit tests. - Set tcl_platform(bootstrap) to 1 for bootstrap jimsh or 0 otherwise - Use getref to determine in we have references, not ref since we implement a poor-man's ref for bootstrap jimsh - bootstrap jimsh package doesn't return a "Can't load package" message if loading the package fails - exec tests using [open |command] need pipe - bootstrap jimsh can't set file times with [file mtime] Signed-off-by: Steve Bennett <[email protected]>
1 parent a432a96 commit aed3715

9 files changed

+108
-76
lines changed

bootstrap.tcl

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Minimal support for package require
2-
# No error on failure since C extensions aren't handled
3-
proc package {cmd pkg args} {
2+
proc package {cmd args} {
43
if {$cmd eq "require"} {
54
foreach path $::auto_path {
5+
lassign $args pkg
66
set pkgpath $path/$pkg.tcl
77
if {$path eq "."} {
88
set pkgpath $pkg.tcl
99
}
1010
if {[file exists $pkgpath]} {
11-
uplevel #0 [list source $pkgpath]
12-
return
11+
tailcall uplevel #0 [list source $pkgpath]
1312
}
1413
}
1514
}
1615
}
16+
set tcl_platform(bootstrap) 1

jim.c

+1
Original file line numberDiff line numberDiff line change
@@ -5671,6 +5671,7 @@ Jim_Interp *Jim_CreateInterp(void)
56715671
Jim_SetVariableStrWithStr(i, "tcl_platform(pathSeparator)", TCL_PLATFORM_PATH_SEPARATOR);
56725672
Jim_SetVariableStrWithStr(i, "tcl_platform(byteOrder)", Jim_IsBigEndian() ? "bigEndian" : "littleEndian");
56735673
Jim_SetVariableStrWithStr(i, "tcl_platform(threaded)", "0");
5674+
Jim_SetVariableStrWithStr(i, "tcl_platform(bootstrap)", "0");
56745675
Jim_SetVariableStr(i, "tcl_platform(pointerSize)", Jim_NewIntObj(i, sizeof(void *)));
56755676
Jim_SetVariableStr(i, "tcl_platform(wordSize)", Jim_NewIntObj(i, sizeof(jim_wide)));
56765677

tests/coverage.test

+9-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
source [file dirname [info script]]/testing.tcl
44

5-
testCmdConstraints ref rand namespace
5+
testCmdConstraints getref rand namespace
66

77
testConstraint debug-invstr 0
88
catch {
@@ -79,39 +79,39 @@ test script-1 {convert empty object to script} {
7979
eval $empty
8080
} {}
8181

82-
test ref-1 {treat something as a reference} ref {
82+
test ref-1 {treat something as a reference} getref {
8383
set ref [ref abc tag]
8484
append ref " "
8585
getref " $ref "
8686
} {abc}
8787

88-
test ref-2 {getref invalid reference} -constraints ref -body {
88+
test ref-2 {getref invalid reference} -constraints getref -body {
8989
getref "<reference.<tag____>.99999999999999000000>"
9090
} -returnCodes error -match glob -result {invalid reference id *}
9191

92-
test ref-3 {getref invalid reference tag} -constraints ref -body {
92+
test ref-3 {getref invalid reference tag} -constraints getref -body {
9393
getref "<reference.<tag!%(*>.99999999999999000000>"
9494
} -returnCodes error -match glob -result {expected reference but got "<reference.<tag!%(*>.99999999999999000000>"}
9595

96-
test ref-4 {finalize} ref {
96+
test ref-4 {finalize} getref {
9797
finalize $ref
9898
} {}
9999

100-
test ref-5 {finalize} ref {
100+
test ref-5 {finalize} getref {
101101
finalize $ref cleanup
102102
finalize $ref cleanup2
103103
finalize $ref
104104
} {cleanup2}
105105

106-
test ref-6 {finalize get invalid reference} -constraints ref -body {
106+
test ref-6 {finalize get invalid reference} -constraints getref -body {
107107
finalize "<reference.<tag____>.99999999999999000000>"
108108
} -returnCodes error -match glob -result {invalid reference id *}
109109

110-
test ref-7 {finalize set invalid reference} -constraints ref -body {
110+
test ref-7 {finalize set invalid reference} -constraints getref -body {
111111
finalize "<reference.<tag____>.99999999999999000000>" cleanup
112112
} -returnCodes error -match glob -result {invalid reference id *}
113113

114-
test collect-1 {recursive collect} ref {
114+
test collect-1 {recursive collect} getref {
115115
set ref2 [ref dummy cleanup2]
116116
unset ref2
117117
proc cleanup2 {ref value} {
@@ -209,10 +209,6 @@ test divide-1 {expr} -constraints jim -body {
209209
/ 2 0
210210
} -returnCodes error -result {Division by zero}
211211

212-
test package-1 {package names} jim {
213-
expr {"stdlib" in [package names]}
214-
} {1}
215-
216212
test variable-1 {upvar, name with embedded null} -constraints jim -body {
217213
proc a {} {
218214
upvar var\0null abc

tests/error.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test error-1.2 "Modify stacktrace" {
4949

5050
# Package should be able to invoke exit, which should exit if not caught
5151
test error-2.1 "Exit from package" {
52-
list [catch -exit {package require exitpackage} msg] $msg
53-
} {6 {Can't load package exitpackage}}
52+
catch -exit {package require exitpackage} msg
53+
} 6
5454

5555
testreport

tests/exec.test

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ source [file dirname [info script]]/testing.tcl
1818
needs cmd exec
1919
needs cmd flush
2020

21+
# Jim needs [pipe] to implement [open |command]
22+
if {[testConstraint tcl]} {
23+
testConstraint pipe 1
24+
} else {
25+
testCmdConstraints pipe
26+
}
27+
2128
testConstraint unix [expr {$tcl_platform(platform) eq {unix}}]
2229

2330
# Sleep which supports fractions of a second
@@ -415,7 +422,7 @@ Third line}
415422

416423
test exec-17.1 {redirecting from command pipeline} -setup {
417424
makeFile "abc\nghi\njkl" gorp.file
418-
} -body {
425+
} -constraints pipe -body {
419426
set f [open "|cat gorp.file | wc -l" r]
420427
set result [lindex [exec cat <@$f] 0]
421428
close $f
@@ -426,7 +433,7 @@ test exec-17.1 {redirecting from command pipeline} -setup {
426433

427434
test exec-17.2 {redirecting to command pipeline} -setup {
428435
makeFile "abc\nghi\njkl" gorp.file
429-
} -body {
436+
} -constraints pipe -body {
430437
set f [open "|wc -l >gorp2.file" w]
431438
exec cat gorp.file >@$f
432439
flush $f

tests/exec2.test

+13-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
source [file dirname [info script]]/testing.tcl
66

77
needs cmd exec
8-
testCmdConstraints pipe signal wait alarm
8+
testCmdConstraints signal wait alarm after
9+
10+
# Jim needs [pipe] to implement [open |command]
11+
if {[testConstraint tcl]} {
12+
testConstraint pipe 1
13+
} else {
14+
testCmdConstraints pipe
15+
}
916

1017
# Some Windows platforms (e.g. AppVeyor) produce ENOSPC rather than killing
1118
# the child with SIGPIPE). So turn off this test for that platform
@@ -53,14 +60,14 @@ test exec2-2.4 "Remove all env var" {
5360

5461
array set env [array get saveenv]
5562

56-
test exec2-3.1 "close pipeline return value" {
63+
test exec2-3.1 "close pipeline return value" pipe {
5764
set f [open |false]
5865
set rc [catch {close $f} msg opts]
5966
lassign [dict get $opts -errorcode] status pid exitcode
6067
list $rc $msg $status $exitcode
6168
} {1 {child process exited abnormally} CHILDSTATUS 1}
6269

63-
test exec2-3.2 "close pipeline return value" -constraints {pipe nomingw32} -body {
70+
test exec2-3.2 "close pipeline return value" -constraints {jim pipe nomingw32} -body {
6471
# Create a pipe and immediately close the read end
6572
lassign [pipe] r w
6673
close $r
@@ -101,7 +108,7 @@ test exec2-3.4 "wait for background task" -constraints wait -body {
101108

102109
test exec2-4.1 {redirect from invalid filehandle} -body {
103110
exec cat <@bogus
104-
} -returnCodes error -result {invalid command name "bogus"}
111+
} -returnCodes error -match glob -result {*"bogus"}
105112

106113
test exec2-4.2 {env is invalid dict} -constraints jim -body {
107114
set saveenv $env
@@ -127,7 +134,7 @@ test exec2-4.5 {exec - consecutive | with &} -body {
127134

128135
test exec2-4.6 {exec - illegal channel} -body {
129136
exec echo hello >@nonexistent
130-
} -returnCodes error -result {invalid command name "nonexistent"}
137+
} -returnCodes error -match glob -result {*"nonexistent"}
131138

132139
test exec2-5.1 {wait with invalid pid} wait {
133140
wait 9999999
@@ -148,7 +155,7 @@ test exec2-5.4 {wait -nohang} -constraints wait -body {
148155
wait $pid
149156
} -match glob -result {CHILDSTATUS * 0}
150157

151-
test exec2-5.5 {wait for all children} -body {
158+
test exec2-5.5 {wait for all children} -constraints {after jim} -body {
152159
# We want to have children finish at different times
153160
# so that we test the handling of the wait table
154161
foreach i {0.1 0.2 0.6 0.5 0.4 0.3} {

tests/file.test

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ testConstraint filelink [string match "wrong # args:*" $msg]
66
catch {file lstat} msg
77
testConstraint filelstat [string match "wrong # args:*" $msg]
88
testConstraint unix [expr {$tcl_platform(platform) eq "unix"}]
9+
if {[testConstraint jim]} {
10+
testConstraint mtimeset [expr {!$tcl_platform(bootstrap)}]
11+
} else {
12+
testConstraint mtimeset 1
13+
}
914

1015
test join-1.1 "One name" {
1116
file join abc
@@ -366,7 +371,7 @@ test mtime-1.4 {file mtime} {
366371
}
367372
} {}
368373

369-
test mtime-1.5 {file mtime} -constraints unix -body {
374+
test mtime-1.5 {file mtime} -constraints {mtimeset unix} -body {
370375
set name tmp.[pid]
371376
makeFile testing $name
372377
set t [file mtime [info script]]

tests/package.test

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ source [file dirname [info script]]/testing.tcl
33
needs constraint jim
44
needs cmd package
55

6+
if {[exists -proc package]} {
7+
skiptest " (bootstrap jimsh)"
8+
}
9+
610
test package-1.1 {provide} -body {
711
package provide new-package-name
812
expr {"new-package-name" in [package names]}
@@ -12,5 +16,9 @@ test package-1.2 {provide, duplicate} -body {
1216
package provide new-package-name
1317
} -returnCodes error -result {package "new-package-name" was already provided}
1418

19+
test package-1.3 {package names} -body {
20+
expr {"stdlib" in [package names]}
21+
} -result 1
22+
1523
testreport
1624

0 commit comments

Comments
 (0)