Skip to content

Commit 9b0b71d

Browse files
committed
ts: fix json whatis error test with random output order
Signed-off-by: Xavier Delaruelle <[email protected]>
1 parent b3725a6 commit 9b0b71d

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

testsuite/config/base-config.exp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,31 @@ proc _test_err_re {test_shell cmd answer force_nl failcmd} {
836836
}
837837
}
838838

839+
proc _test_err_re_sort {test_shell cmd answer failcmd} {
840+
global comp_error
841+
global verbose
842+
843+
# newline is expected at end of answer
844+
if {$answer ne {} && $answer ne "\n"} {
845+
append answer \n
846+
}
847+
848+
set comp_error_sort [join [lsort [split $comp_error \n]] \n]
849+
set answer_sort [join [lsort [split $answer \n]] \n]
850+
set answer_sort "^$answer_sort\$"
851+
852+
if {![regexp -- $answer_sort $comp_error_sort]} {
853+
$failcmd "$cmd ($test_shell)"
854+
set ol [string length $comp_error_sort]
855+
set oe [string length $answer_sort]
856+
send_user "ERR\[$ol\]: '$comp_error_sort'#>\n"
857+
send_user "EXP\[$oe\]: '$answer_sort'#>\n"
858+
return 0;
859+
} else {
860+
return 1;
861+
}
862+
}
863+
839864
proc _test_out {test_shell cmd answer failcmd} {
840865
global comp_output
841866
global verbose
@@ -1118,6 +1143,25 @@ proc testouterr_cmd {test_shell cmd answer anserr {failcmd {fail}}} {
11181143
}
11191144
}
11201145

1146+
#
1147+
# Test procedure for matching with regular expressions in the stdout and sorted stderr
1148+
#
1149+
1150+
proc testouterr_cmd_re_sort {test_shell cmd answer anserr {failcmd {fail}}} {
1151+
if {$test_shell eq "ALL"} {
1152+
global supported_shells
1153+
foreach shell $supported_shells {
1154+
testouterr_cmd_re_sort $shell $cmd $answer $anserr
1155+
}
1156+
} else {
1157+
_test_sub $test_shell "$cmd"
1158+
if { [_test_out_re $test_shell "$cmd" "$answer" $failcmd]
1159+
&& [_test_err_re_sort $test_shell "$cmd" "$anserr" $failcmd] } {
1160+
_test_ok $test_shell "$cmd"
1161+
}
1162+
}
1163+
}
1164+
11211165
#
11221166
# Test procedure for full text matching with stdout and specified file
11231167
#

testsuite/modules.70-maint/290-json.exp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ if {$is_file_perms_editable && $tcl_platform(user) ne {root} && !$is_locked_dir_
246246
change_file_perms $mp/iCaSe/1 ugo-rx
247247
change_file_perms $mp/icASE/1 ugo-rx
248248
change_file_perms $mp/icase/1 ugo-rx
249-
testouterr_cmd sh {whatis --json -i ICASE/1} ERR "{\"errors\": \[
250-
{ \"severity\": \"ERROR\", \"message\": \[ \"Permission denied on '$mp/iCaSe/1'\" \] },
251-
{ \"severity\": \"ERROR\", \"message\": \[ \"Permission denied on '$mp/ICASE/1'\" \] },
252-
{ \"severity\": \"ERROR\", \"message\": \[ \"Permission denied on '$mp/IcAsE/1'\" \] },
253-
{ \"severity\": \"ERROR\", \"message\": \[ \"Permission denied on '$mp/icASE/1'\" \] },
254-
{ \"severity\": \"ERROR\", \"message\": \[ \"Permission denied on '$mp/icase/1'\" \] } \]
249+
testouterr_cmd_re_sort sh {whatis --json -i ICASE/1} ERR "{\"errors\": \\\[
250+
{ \"severity\": \"ERROR\", \"message\": \\\[ \"Permission denied on '$mpre/iCaSe/1'\" \\\] }.*
251+
{ \"severity\": \"ERROR\", \"message\": \\\[ \"Permission denied on '$mpre/ICASE/1'\" \\\] }.*
252+
{ \"severity\": \"ERROR\", \"message\": \\\[ \"Permission denied on '$mpre/IcAsE/1'\" \\\] }.*
253+
{ \"severity\": \"ERROR\", \"message\": \\\[ \"Permission denied on '$mpre/icASE/1'\" \\\] }.*
254+
{ \"severity\": \"ERROR\", \"message\": \\\[ \"Permission denied on '$mpre/icase/1'\" \\\] }.*
255255
}"
256256
testouterr_cmd sh {whatis --json -i -s ICASE/1} ERR "{}"
257257
restore_file_perms $mp/IcAsE/1

0 commit comments

Comments
 (0)