1 # Copyright
(C
) 2022 Free Software Foundation
, Inc.
3 # This file is part of DejaGnu.
5 # DejaGnu is free software
; you can redistribute it and
/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation
; either version
3 of the License
, or
8 #
(at your option
) any later version.
10 # DejaGnu is distributed in the hope that it will be useful
, but
11 # WITHOUT
ANY WARRANTY
; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License
for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with DejaGnu
; if not
, write to the Free Software Foundation
,
17 # Inc.
, 51 Franklin Street
- Fifth Floor
, Boston
, MA
02110-1301, USA.
19 # This file is a test driver
for the unit test protocol library.
21 # Each test
program must accept test outcomes
on the command line
, and
22 # produce exactly those results in that order.
24 proc test_libdejagnu_unit
{ language tests
} {
25 set test_program
[testsuite file
-object
-test
"unit-${language}"]
27 # map messages from dejagnu.h
:totals
() to result types
28 array
set expected_totals_map
{
29 passed pass
"real failed" fail
30 "unexpected passes" xpass
31 "expected failures" xfail
34 unsupported unsupported
38 array
set expected_totals
{
41 untested
0 unresolved
0 unsupported
0
46 verbose
-log "Spawning $test_program $test ..."
47 eval
[list spawn $test_program
] $test
50 -re
{^
[^
\n]*\n} { exp_continue
}
52 perror
"Expect matching buffer overrun during test."
55 # No end marker?
-> Fail
!
56 verbose
-log " unit test did not emit an end marker"
65 # Check that the reported results match.
67 -re
{^
[\r\n]*Totals
:[\r\n]+} {
68 # done with results
, but fail
if there should be more
69 if { [lindex $test $test_idx
] ne
"" } {
70 verbose
-log " expected [lindex $test $test_idx]"
74 -re
{(?
:\A|
\n)\t([][[:upper
:]]+):([^
\n]+)\n} {
75 # above pattern copied from lib
/dejagnu.exp
:host_execute
76 switch -- [lindex $test $test_idx
] {
77 note
{ set expected NOTE
}
78 pass
{ set expected PASSED
}
79 fail
{ set expected FAILED
}
80 xpass
{ set expected XPASSED
}
81 xfail
{ set expected XFAILED
}
82 untested
{ set expected UNTESTED
}
83 unresolved
{ set expected UNRESOLVED
}
84 unsupported
{ set expected UNSUPPORTED
}
86 if { [info exists expected_totals
([lindex $test $test_idx
])]} {
87 incr expected_totals
([lindex $test $test_idx
])
89 if { $expected ne $expect_out
(1,string
) } {
96 # Now ensure that the reported totals are as expected.
98 -re
{^
\n*\t#
([^
:]+):\t+([[:digit
:]]+)\r*\n} {
99 set type $expected_totals_map
($expect_out
(1,string
))
100 set count $expect_out
(2,string
)
102 if { $expected_totals
($type
) != $
count } {
103 verbose
-log " expected $expected_totals($type)\
107 unset expected_totals
($type
)
110 -re
{^
\n*\tEND
:[^
\n]+\n} {
112 expect
-re
{.
+} { exp_continue
} eof
118 foreach
{ type
count } [array
get expected_totals
] {
119 if { $
count == 0 } { continue }
120 verbose
-log " expected $count $type; got no report"
124 $result
"test $test_program with: $test"
128 foreach language
{c cxx
} {
129 test_libdejagnu_unit $language
{
130 note pass fail xpass xfail untested unresolved unsupported