Skip to content

Commit 4449b4d

Browse files
committed
Merge branch less_tests_constraints. Summary of changes:
- Work on failsOnUbuntu / failsOnXQuarz constraints to remove them as much as possible. Add completely specific constraints instead in some cases. - Eradicate constraint noExceed - Factorize definition of some constraints (e.g. 'pressbutton', 'movemouse'), and rename some constraints to test* to conform to other test constraint names - (Linux) Add font packages in the install step before running the test suite at CI, so that the CI environment can count on those fonts to be available - Remove warnings when DEBUG_FONTSEL is defined - Modernize code ("eval destroy" -> "destroy {*}")
2 parents f2b81c0 + b6fda36 commit 4449b4d

File tree

16 files changed

+174
-141
lines changed

16 files changed

+174
-141
lines changed

.github/workflows/linux-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ jobs:
147147
path: tcl
148148
- name: Setup Environment (compiler=${{ matrix.compiler }})
149149
run: |
150-
sudo apt-get install libxss-dev libxft-dev xvfb libicu-dev
150+
sudo apt-get install libxss-dev libxft-dev xvfb libicu-dev xfonts-75dpi xfonts-100dpi xfonts-scalable libxfont2 unifont
151151
mkdir "$HOME/install dir"
152152
touch tk/doc/man.macros tk/generic/tkStubInit.c
153153
echo "CFGOPT=$CFGOPT" >> $GITHUB_ENV

macosx/tkMacOSXTest.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
* Forward declarations of procedures defined later in this file:
2222
*/
2323

24-
static Tcl_ObjCmdProc PressButtonObjCmd;
25-
static Tcl_ObjCmdProc MoveMouseObjCmd;
26-
static Tcl_ObjCmdProc InjectKeyEventObjCmd;
27-
static Tcl_ObjCmdProc MenuBarHeightObjCmd;
24+
static Tcl_ObjCmdProc TestpressbuttonObjCmd;
25+
static Tcl_ObjCmdProc TestmovemouseObjCmd;
26+
static Tcl_ObjCmdProc TestinjectkeyeventObjCmd;
27+
static Tcl_ObjCmdProc TestmenubarheightObjCmd;
2828

2929

3030
/*
@@ -52,17 +52,17 @@ TkplatformtestInit(
5252
* Add commands for platform specific tests on MacOS here.
5353
*/
5454

55-
Tcl_CreateObjCommand(interp, "pressbutton", PressButtonObjCmd, NULL, NULL);
56-
Tcl_CreateObjCommand(interp, "movemouse", MoveMouseObjCmd, NULL, NULL);
57-
Tcl_CreateObjCommand(interp, "injectkeyevent", InjectKeyEventObjCmd, NULL, NULL);
58-
Tcl_CreateObjCommand(interp, "menubarheight", MenuBarHeightObjCmd, NULL, NULL);
55+
Tcl_CreateObjCommand(interp, "testpressbutton", TestpressbuttonObjCmd, NULL, NULL);
56+
Tcl_CreateObjCommand(interp, "testmovemouse", TestmovemouseObjCmd, NULL, NULL);
57+
Tcl_CreateObjCommand(interp, "testinjectkeyevent", TestinjectkeyeventObjCmd, NULL, NULL);
58+
Tcl_CreateObjCommand(interp, "testmenubarheight", TestmenubarheightObjCmd, NULL, NULL);
5959
return TCL_OK;
6060
}
6161

6262
/*
6363
*----------------------------------------------------------------------
6464
*
65-
* MenuBarHeightObjCmd --
65+
* TestmenubarheightObjCmd --
6666
*
6767
* This procedure calls [NSMenu menuBarHeight] and returns the result
6868
* as an integer. Windows can never be placed to overlap the MenuBar,
@@ -78,7 +78,7 @@ TkplatformtestInit(
7878
*/
7979

8080
static int
81-
MenuBarHeightObjCmd(
81+
TestmenubarheightObjCmd(
8282
TCL_UNUSED(void *), /* Not used. */
8383
Tcl_Interp *interp, /* Not used. */
8484
TCL_UNUSED(int), /* Not used. */
@@ -124,7 +124,7 @@ TkTestLogDisplay(
124124
/*
125125
*----------------------------------------------------------------------
126126
*
127-
* PressButtonObjCmd --
127+
* TestpressbuttonObjCmd --
128128
*
129129
* This Tcl command simulates a button press at a specific screen
130130
* location. It injects NSEvents into the NSApplication event queue, as
@@ -143,7 +143,7 @@ TkTestLogDisplay(
143143
*/
144144

145145
static int
146-
PressButtonObjCmd(
146+
TestpressbuttonObjCmd(
147147
TCL_UNUSED(void *),
148148
Tcl_Interp *interp,
149149
int objc,
@@ -225,7 +225,7 @@ PressButtonObjCmd(
225225
/*
226226
*----------------------------------------------------------------------
227227
*
228-
* MoveMouseObjCmd --
228+
* TestmovemouseObjCmd --
229229
*
230230
* This Tcl command simulates a mouse motion to a specific screen
231231
* location. It injects an NSEvent into the NSApplication event queue,
@@ -242,7 +242,7 @@ PressButtonObjCmd(
242242
*/
243243

244244
static int
245-
MoveMouseObjCmd(
245+
TestmovemouseObjCmd(
246246
TCL_UNUSED(void *),
247247
Tcl_Interp *interp,
248248
int objc,
@@ -302,7 +302,7 @@ MoveMouseObjCmd(
302302
}
303303

304304
static int
305-
InjectKeyEventObjCmd(
305+
TestinjectkeyeventObjCmd(
306306
TCL_UNUSED(void *),
307307
Tcl_Interp *interp,
308308
int objc,

tests/bind.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6931,7 +6931,7 @@ proc testKey {window event type mods} {
69316931
}
69326932
set save $keyInfo
69336933
set keyInfo {}
6934-
set injectcmd [list injectkeyevent $type $numericKeysym]
6934+
set injectcmd [list testinjectkeyevent $type $numericKeysym]
69356935
foreach {option} $mods {
69366936
lappend injectcmd $option
69376937
}
@@ -7002,7 +7002,7 @@ test bind-35.2 {Can bind to function keys} -constraints {aqua} -body {
70027002
set numericKeysym {}
70037003
focus -force .
70047004
event generate . <F2>
7005-
injectkeyevent press $numericKeysym -function
7005+
testinjectkeyevent press $numericKeysym -function
70067006
vwait keyInfo
70077007
return $keyInfo
70087008
} -cleanup {
@@ -7032,7 +7032,7 @@ test bind-35.3 {Events agree for modifier keys} -constraints {aqua} -setup {
70327032
vwait keyInfo
70337033
}
70347034
set save $keyInfo
7035-
injectkeyevent flagschanged $numericKeysym [lindex $event 1]
7035+
testinjectkeyevent flagschanged $numericKeysym [lindex $event 1]
70367036
if {$keyInfo == {}} {
70377037
vwait keyInfo
70387038
}

tests/constraints.tcl

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -282,33 +282,33 @@ testConstraint nonUnixUserInteraction [expr {
282282
}]
283283
testConstraint haveDISPLAY [expr {[info exists env(DISPLAY)] && [testConstraint x11]}]
284284
testConstraint altDisplay [info exists env(TK_ALT_DISPLAY)]
285-
testConstraint noExceed [expr {
286-
![testConstraint unix] || [catch {font actual "\{xyz"}]
287-
}]
285+
288286
testConstraint deprecated [expr {![::tk::build-info no-deprecate]}]
289287

290288
# constraint for running a test on all windowing system except aqua
291289
# where the test fails due to a known bug
292290
testConstraint aquaKnownBug [expr {[testConstraint notAqua] || [testConstraint knownBug]}]
293291

294292
# constraints for testing facilities defined in the tktest executable...
295-
testConstraint testImageType [expr {"test" in [image types]}]
296-
testConstraint testbitmap [llength [info commands testbitmap]]
297-
testConstraint testborder [llength [info commands testborder]]
298-
testConstraint testcbind [llength [info commands testcbind]]
299-
testConstraint testclipboard [llength [info commands testclipboard]]
300-
testConstraint testcolor [llength [info commands testcolor]]
301-
testConstraint testcursor [llength [info commands testcursor]]
302-
testConstraint testembed [llength [info commands testembed]]
303-
testConstraint testfont [llength [info commands testfont]]
304-
testConstraint testmakeexist [llength [info commands testmakeexist]]
305-
testConstraint testmenubar [llength [info commands testmenubar]]
306-
testConstraint testmetrics [llength [info commands testmetrics]]
307-
testConstraint testobjconfig [llength [info commands testobjconfig]]
308-
testConstraint testsend [llength [info commands testsend]]
309-
testConstraint testtext [llength [info commands testtext]]
310-
testConstraint testwinevent [llength [info commands testwinevent]]
311-
testConstraint testwrapper [llength [info commands testwrapper]]
293+
testConstraint testbitmap [llength [info commands testbitmap]]
294+
testConstraint testborder [llength [info commands testborder]]
295+
testConstraint testcbind [llength [info commands testcbind]]
296+
testConstraint testclipboard [llength [info commands testclipboard]]
297+
testConstraint testcolor [llength [info commands testcolor]]
298+
testConstraint testcursor [llength [info commands testcursor]]
299+
testConstraint testembed [llength [info commands testembed]]
300+
testConstraint testfont [llength [info commands testfont]]
301+
testConstraint testImageType [expr {"test" in [image types]}]
302+
testConstraint testmakeexist [llength [info commands testmakeexist]]
303+
testConstraint testmenubar [llength [info commands testmenubar]]
304+
testConstraint testmetrics [llength [info commands testmetrics]]
305+
testConstraint testmovemouse [llength [info commands testmovemouse]]
306+
testConstraint testobjconfig [llength [info commands testobjconfig]]
307+
testConstraint testpressbutton [llength [info commands testpressbutton]]
308+
testConstraint testsend [llength [info commands testsend]]
309+
testConstraint testtext [llength [info commands testtext]]
310+
testConstraint testwinevent [llength [info commands testwinevent]]
311+
testConstraint testwrapper [llength [info commands testwrapper]]
312312

313313
# constraints about what sort of fonts are available
314314
testConstraint fonts 1
@@ -329,6 +329,31 @@ destroy .t
329329
if {![string match {{22 3 6 15} {31 18 [34] 15}} $x]} {
330330
testConstraint fonts 0
331331
}
332+
333+
testConstraint withXft [expr {![catch {tk::pkgconfig get fontsystem} fs] && ($fs eq "xft")}]
334+
testConstraint withoutXft [expr {![testConstraint withXft]}]
335+
unset fs
336+
337+
# Expected results of some tests on Linux rely on availability of the "times"
338+
# font. This font is generally provided when Tk uses the old X font system,
339+
# but not when using Xft on top of fontconfig. Specifically (old system):
340+
# xlsfonts | grep times
341+
# may return quite some output while (new system):
342+
# fc-list | grep times
343+
# return value is empty. That's not surprising since the two font systems are
344+
# separate (availability of a font in one of them does not mean it's available
345+
# in the other one). The following constraints are useful in this kind of
346+
# situation.
347+
testConstraint haveTimesFamilyFont [expr {
348+
[string tolower [font actual {-family times} -family]] == "times"
349+
}]
350+
testConstraint haveFixedFamilyFont [expr {
351+
[string tolower [font actual {-family fixed} -family]] == "fixed"
352+
}]
353+
testConstraint haveCourierFamilyFont [expr {
354+
[string tolower [font actual {-family courier} -family]] == "courier"
355+
}]
356+
332357
# Although unexpected, some systems may have a very limited set of fonts available.
333358
# The following constraints happen to evaluate to false at least on one system: the
334359
# Github CI runner for Linux with --disable-xft, which has exactly ONE single font
@@ -341,17 +366,14 @@ if {![string match {{22 3 6 15} {31 18 [34] 15}} $x]} {
341366
# tests they constrain (that is: availability of any font having the given font
342367
# attributes), so that these constrained tests will in fact run on all systems having
343368
# reasonable font dotation.
344-
testConstraint haveTimes12Font [expr {
345-
[font actual {times 12} -size] == 12
346-
}]
347-
testConstraint haveCourier37Font [expr {
369+
testConstraint havePointsize37Font [expr {
348370
[font actual {-family courier -size 37} -size] == 37
349371
}]
350-
testConstraint haveTimes14BoldFont [expr {
372+
testConstraint havePointsize14BoldFont [expr {
351373
([font actual {times 14 bold} -size] == 14) &&
352374
([font actual {times 14 bold} -weight] eq "bold")
353375
}]
354-
testConstraint haveTimes12BoldItalicUnderlineOverstrikeFont [expr {
376+
testConstraint haveBoldItalicUnderlineOverstrikeFont [expr {
355377
([font actual {times 12 bold italic overstrike underline} -weight] eq "bold") &&
356378
([font actual {times 12 bold italic overstrike underline} -slant] eq "italic") &&
357379
([font actual {times 12 bold italic overstrike underline} -underline] eq "1") &&

tests/font.test

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ tcltest::loadTestedCommands
1414
# Some tests require support for 4-byte UTF-8 sequences
1515
testConstraint fullutf [expr {[format %c 0x010000] != "\uFFFD"}]
1616
testConstraint utfcompat [expr {([string length "\U10000"] == 2) && [package vsatisfies [package provide Tcl] 8]}]
17-
testConstraint failsOnUbuntu [expr {![info exists ::env(CI)] || ![string match Linux $::tcl_platform(os)]}]
18-
1917
set defaultfontlist [font names]
2018

2119
proc getnondefaultfonts {} {
@@ -130,15 +128,15 @@ test font-4.6 {font command: actual: arguments} -body {
130128
# (objc - skip > 4) when skip == 2
131129
font actual xyz -displayof . abc def
132130
} -returnCodes error -result {wrong # args: should be "font actual font ?-displayof window? ?-option? ?--? ?char?"}
133-
test font-4.7 {font command: actual: arguments} -constraints noExceed -body {
131+
test font-4.7 {font command: actual: arguments} -body {
134132
# (tkfont == NULL)
135133
font actual "\{xyz"
136134
} -returnCodes error -result "font \"{xyz\" does not exist"
137135
test font-4.8 {font command: actual: all attributes} -body {
138136
# not (objc > 3) so objPtr = NULL
139137
lindex [font actual {-family times}] 0
140138
} -result {-family}
141-
test font-4.9 {font command: actual} -constraints {unix noExceed failsOnUbuntu} -body {
139+
test font-4.9 {font command: actual} -constraints {haveTimesFamilyFont} -body {
142140
# (objc > 3) so objPtr = objv[3 + skip]
143141
string tolower [font actual {-family times} -family]
144142
} -result {times}
@@ -384,7 +382,7 @@ test font-8.3 {font command: families: arguments} -body {
384382
# (objc - skip != 2) when skip == 2
385383
font families -displayof . xyz
386384
} -returnCodes error -result {wrong # args: should be "font families ?-displayof window?"}
387-
test font-8.4 {font command: families} -constraints failsOnUbuntu -body {
385+
test font-8.4 {font command: families} -constraints haveTimesFamilyFont -body {
388386
# TkpGetFontFamilies()
389387
regexp -nocase times [font families]
390388
} -result 1
@@ -402,7 +400,7 @@ test font-9.3 {font command: measure: arguments} -body {
402400
# (objc - skip != 4)
403401
font measure xyz abc def
404402
} -returnCodes error -result {wrong # args: should be "font measure font ?-displayof window? text"}
405-
test font-9.4 {font command: measure: arguments} -constraints noExceed -body {
403+
test font-9.4 {font command: measure: arguments} -body {
406404
# (tkfont == NULL)
407405
font measure "\{xyz" abc
408406
} -returnCodes error -result "font \"{xyz\" does not exist"
@@ -440,7 +438,7 @@ test font-10.5 {font command: metrics: arguments} -body {
440438
# (objc - skip) > 4) when skip == 2
441439
font metrics xyz -displayof . abc
442440
} -returnCodes error -result {bad metric "abc": must be -ascent, -descent, -fixed, or -linespace}
443-
test font-10.6 {font command: metrics: bad font} -constraints noExceed -body {
441+
test font-10.6 {font command: metrics: bad font} -body {
444442
# (tkfont == NULL)
445443
font metrics "\{xyz"
446444
} -returnCodes error -result "font \"{xyz\" does not exist"
@@ -704,7 +702,7 @@ test font-15.9 {Tk_AllocFontFromObj procedure: get attribute font} -setup {
704702
} -cleanup {
705703
destroy .t.f
706704
} -returnCodes error -result {expected integer but got "yyy"}
707-
test font-15.10 {Tk_AllocFontFromObj procedure: no match} -constraints noExceed -body {
705+
test font-15.10 {Tk_AllocFontFromObj procedure: no match} -body {
708706
# (ParseFontNameObj() != TCL_OK)
709707
font actual "\{xyz"
710708
} -returnCodes error -result "font \"{xyz\" does not exist"
@@ -936,11 +934,15 @@ test font-21.5 {Tk_PostscriptFontName procedure: spaces} -constraints {
936934
}
937935
} -result {LucidaBright}
938936
test font-21.6 {Tk_PostscriptFontName procedure: spaces} -constraints {
939-
x11 failsOnUbuntu
937+
x11
940938
} -body {
941-
psfontname "{new century schoolbook} 10"
939+
set name {{new century schoolbook} 10}
940+
if {[font actual {{new century schoolbook} 10} -family] == "new century schoolbook"} {
941+
set x [psfontname "{new century schoolbook} 10"]
942+
} else {
943+
set x NewCenturySchlbk-Roman
944+
}
942945
} -result {NewCenturySchlbk-Roman}
943-
944946
test font-21.7 {Tk_PostscriptFontName procedure: exhaustive} -constraints {
945947
unix
946948
} -body {
@@ -2252,10 +2254,10 @@ test font-38.5 {ParseFontNameObj procedure: begins with *} -body {
22522254
test font-38.6 {ParseFontNameObj procedure: begins with *} -body {
22532255
font actual *-times-xyz -family
22542256
} -result [font actual {times 0} -family]
2255-
test font-38.7 {ParseFontNameObj procedure: arguments} -constraints noExceed -body {
2257+
test font-38.7 {ParseFontNameObj procedure: arguments} -body {
22562258
font actual "\{xyz"
22572259
} -returnCodes error -result "font \"{xyz\" does not exist"
2258-
test font-38.8 {ParseFontNameObj procedure: arguments} -constraints noExceed -body {
2260+
test font-38.8 {ParseFontNameObj procedure: arguments} -body {
22592261
font actual ""
22602262
} -returnCodes error -result {font "" does not exist}
22612263
test font-38.9 {ParseFontNameObj procedure: arguments} -body {
@@ -2265,7 +2267,7 @@ test font-38.10 {ParseFontNameObj procedure: arguments} -body {
22652267
font actual {times xyz xyz}
22662268
} -returnCodes error -result {expected integer but got "xyz"}
22672269
test font-38.11 {ParseFontNameObj procedure: stylelist loop} -constraints {
2268-
unixOrWin haveTimes12BoldItalicUnderlineOverstrikeFont
2270+
unixOrWin haveBoldItalicUnderlineOverstrikeFont
22692271
} -body {
22702272
lrange [font actual {times 12 bold italic overstrike underline}] 4 end
22712273
} -result {-weight bold -slant italic -underline 1 -overstrike 1}
@@ -2356,14 +2358,15 @@ test font-44.1 {TkFontGetPixels: size < 0} -setup {
23562358
} -cleanup {
23572359
tk scaling $oldscale
23582360
} -result 26
2359-
test font-44.2 {TkFontGetPoints: size >= 0} -constraints {noExceed haveTimes12Font} -setup {
2361+
test font-44.2 {TkFontGetPoints: size >= 0} -setup {
23602362
set oldscale [tk scaling]
23612363
} -body {
2364+
set oldSize [font actual {times 12} -size]
23622365
tk scaling 0.5
2363-
font actual {times 12} -size
2366+
expr {[font actual {times 12} -size] == $oldSize}
23642367
} -cleanup {
23652368
tk scaling $oldscale
2366-
} -result 12
2369+
} -result 1
23672370
test font-44.3 {font create with display scaling not 100% - bug 8162e9b7a9} -body {
23682371
set font1 TkDefaultFont
23692372
set font2 [font create Font2 {*}[font actual $font1]]
@@ -2379,7 +2382,7 @@ test font-45.1 {TkFontGetAliasList: no match} -body {
23792382
test font-45.2 {TkFontGetAliasList: match} -constraints win -body {
23802383
font actual {times 10} -family
23812384
} -result {times}
2382-
test font-45.3 {TkFontGetAliasList: match} -constraints {noExceed failsOnUbuntu} -body {
2385+
test font-45.3 {TkFontGetAliasList: match} -constraints haveTimesFamilyFont -body {
23832386
if {[font actual {{times new roman} 10} -family] eq "Times New Roman"} {
23842387
# avoid test failure on systems that have a real "times new roman" font
23852388
set res 1

tests/fontchooser.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ test fontchooser-4.3 {fontchooser -font} -constraints scriptImpl -body {
179179
expr {$::testfont ne {}}
180180
} -result 1
181181

182-
test fontchooser-4.4 {fontchooser -font} -constraints {scriptImpl haveTimes14BoldFont} -body {
182+
test fontchooser-4.4 {fontchooser -font} -constraints {scriptImpl havePointsize14BoldFont} -body {
183183
start {
184184
tk::fontchooser::Configure -command ApplyFont -font {times 14 bold}
185185
tk::fontchooser::Show

tests/frame.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ set expectedScreen ""
435435
if {[tcltest::testConstraint haveDISPLAY]} {
436436
set expectedScreen [list -screen screen Screen {} $env(DISPLAY)]
437437
}
438-
test frame-2.15 {toplevel configuration options} -constraints {x11 haveDISPLAY} -setup {
438+
test frame-2.15 {toplevel configuration options} -constraints haveDISPLAY -setup {
439439
deleteWindows
440440
} -body {
441441
toplevel .t -width 200 -height 100 -screen $env(DISPLAY)
@@ -444,7 +444,7 @@ test frame-2.15 {toplevel configuration options} -constraints {x11 haveDISPLAY}
444444
} -cleanup {
445445
deleteWindows
446446
} -result $expectedScreen
447-
test frame-2.16 {toplevel configuration options} -constraints {x11 haveDISPLAY} -setup {
447+
test frame-2.16 {toplevel configuration options} -constraints haveDISPLAY -setup {
448448
deleteWindows
449449
} -body {
450450
toplevel .t -width 200 -height 100 -screen $env(DISPLAY)

0 commit comments

Comments
 (0)