Add tests for C++ unit test library
[dejagnu.git] / testsuite / libdejagnu / unit.exp
blobb52a7dcd23eb4c5ee394a30176bd16f4d01fbd53
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
32 untested untested
33 unresolved unresolved
34 unsupported unsupported
37 foreach test $tests {
38 array set expected_totals {
39 pass 0 fail 0
40 xpass 0 xfail 0
41 untested 0 unresolved 0 unsupported 0
43 set test_idx 0
44 set result pass
46 verbose -log "Spawning $test_program $test ..."
47 eval [list spawn $test_program] $test
49 expect_after {
50 -re {^[^\n]*\n} { exp_continue }
51 full_buffer {
52 perror "Expect matching buffer overrun during test."
54 eof {
55 # No end marker? -> Fail!
56 verbose -log " unit test did not emit an end marker"
57 set result fail
59 timeout {
60 catch close
61 set result unresolved
65 # Check that the reported results match.
66 expect {
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]"
71 set result fail
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) } {
90 set result fail
92 incr test_idx
93 exp_continue
96 # Now ensure that the reported totals are as expected.
97 expect {
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)\
104 $type; got $count"
105 set result fail
107 unset expected_totals($type)
108 exp_continue
110 -re {^\n*\tEND:[^\n]+\n} {
111 # flush to EOF
112 expect -re {.+} { exp_continue } eof
115 catch close
116 wait -nowait
118 foreach { type count } [array get expected_totals] {
119 if { $count == 0 } { continue }
120 verbose -log " expected $count $type; got no report"
121 set result fail
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