Fix typo in reference manual
[dejagnu.git] / testsuite / report-card.all / onetest.exp
blobfbf58b97ef96df045c8784caadb7b51dc9defbb7
1 # Copyright (C) 2018, 2024 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, see <http://www.gnu.org/licenses/>.
18 # This file was written by Jacob Bachmeyer.
20 set header_column_names { PASS FAIL ?PASS ?FAIL UNSUP UNRES UNTEST }
21 set separator_count 0
22 set re_digit_columns {}
23 for { set i 0 } { $i < 7 } { incr i } {
24     append re_digit_columns {[[:space:]]+([[:digit:]]+)}
27 set test_names { pass fail kpass kfail xpass xfail
28                  unsupported unresolved untested
29                  note warning error }
30 set test_results { PASS FAIL KPASS KFAIL XPASS XFAIL
31                    UNSUPPORTED UNRESOLVED UNTESTED
32                    NOTE WARNING ERROR }
34 foreach name $test_names result $test_results {
35     set fd [open [testsuite file -object -test onetest one-${name}.sum] w]
36     puts $fd "${result}: one test"
37     close $fd
40 set stty_init { -onlcr }
42 spawn /bin/sh -c \
43     "cd [testsuite file -object -test onetest]\
44      && exec $LAUNCHER report-card"
46 # check header
47 expect {
48     -re {^[[:space:]]+_+[\r\n]+} {
49         # discard initial header line
50         exp_continue
51     }
52     -re {^[[:space:]]+/([^\r\n]*)[\r\n]+} {
53         # check column labels
54         foreach want $header_column_names have $expect_out(1,string) {
55             if { $have eq $want } {
56                 pass "header item $want"
57             } else {
58                 fail "header item $want"
59             }
60         }
61         exp_continue
62     }
63     -re {^[[:space:]]+\|-+[\r\n]+} {
64         incr separator_count
65     }
68 # check results
69 array unset scoreboard
70 array set scoreboard {
71     pass 0 fail 0 kpass 0 kfail 0 xpass 0 xfail 0
72     unsupported 0 unresolved 0 untested 0
73     note 0 warning 0 error 0
75 array unset column_subexp_map
76 array set column_subexp_map {
77     pass 2 fail 3 kpass 4 kfail 5 xpass 4 xfail 5
78     unsupported 6 unresolved 7 untested 8
79     note 0 warning 9 error 9
81 set re_table_row {^[[:space:]]*one-([[:alpha:]]+)[[:space:]]+\|}
82 append re_table_row $re_digit_columns
83 append re_table_row {((?:[[:space:]]+![EW]!)*)[\r\n]+}
84 expect {
85     -re $re_table_row {
86         for { set i 2 } { $i < 9 } { incr i } {
87             if { $expect_out($i,string)\
88                      == ( $i == $column_subexp_map($expect_out(1,string))\
89                               ? 1 : 0 ) } {
90                 incr scoreboard($expect_out(1,string))
91             } else {
92                 incr scoreboard($expect_out(1,string)) -1
93             }
94         }
95         set have_warning_tag [string match "*!W!*" $expect_out(9,string)]
96         set have_error_tag [string match "*!E!*" $expect_out(9,string)]
97         if { $column_subexp_map($expect_out(1,string)) == 9 } {
98             # testing an after-row tag
99             switch -- $expect_out(1,string) {
100                 warning {
101                     incr scoreboard(warning) \
102                         [expr { $have_warning_tag ? 1 : -1 }]
103                     incr scoreboard(error) \
104                         [expr { $have_error_tag   ? -1 : 1 }]
105                 }
106                 error {
107                     incr scoreboard(warning) \
108                         [expr { $have_warning_tag ? -1 : 1 }]
109                     incr scoreboard(error) \
110                         [expr { $have_error_tag   ? 1 : -1 }]
111                 }
112                 default { error "unknown tag $expect_out(1,string)" }
113             }
114         } else {
115             incr scoreboard(warning) [expr { $have_warning_tag ? -1 : 1 }]
116             incr scoreboard(error)   [expr { $have_error_tag   ? -1 : 1 }]
117         }
118         exp_continue
119     }
120     -re {^[[:space:]]+\|-+[\r\n]+} {
121         incr separator_count
122     }
124 foreach result [lsort [array names scoreboard]] {
125     verbose -log "scoreboard($result) = $scoreboard($result)"
127 foreach result [array names scoreboard] {
128     if { $scoreboard($result) == ( 7 + ( $column_subexp_map($result) == 9\
129                                              ? [llength $test_names] : 0 ) ) } {
130         pass "count result $result"
131     } else {
132         fail "count result $result"
133     }
136 # check totals
137 set column_totals { pad 1 1 2 2 1 1 1 }
138 set re_totals_row {^[[:space:]]+\|}
139 append re_totals_row $re_digit_columns
140 append re_totals_row {[\r\n]+}
141 set totals_matched 0
142 expect {
143     -re $re_totals_row {
144         for { set i 1 } { $i < 8 } { incr i } {
145             if { [lindex $column_totals $i] == $expect_out($i,string) } {
146                 incr totals_matched
147             }
148         }
149         exp_continue
150     }
151     -re {^[[:space:]]+\|-+[\r\n]+} {
152         incr separator_count
153     }
154     -re {^[[:space:]]+\\_+[\r\n]+} {
155         # all done
156     }
159 if { $totals_matched == 7 } {
160     pass "expected total count"
161 } else {
162     fail "expected total count"
165 if { $separator_count == 2 } {
166     pass "expected separator lines"
167 } else {
168     fail "expected separator lines"
171 # Ensure that totals map correctly by reading each file one at a time
172 foreach name $test_names {
173     set separator_count 0
174     spawn /bin/sh -c \
175         "cd [testsuite file -object -test onetest]\
176          && exec $LAUNCHER report-card one-${name}.sum"
177     # skip header
178     expect {
179         -re {^[[:space:]]+_+[\r\n]+} { exp_continue }
180         -re {^[[:space:]]+/([^\r\n]*)[\r\n]+} { exp_continue }
181         -re {^[[:space:]]+\|-+[\r\n]+} { incr separator_count }
182     }
183     # capture the item line
184     expect -re {^one-[^|]+(\|[[:space:][:digit:]]*)[[:space:]!EW]*[\r\n]+} {
185         regsub {[[:space:]]*$} $expect_out(1,string) "" item_line
186     }
187     # skip the separator
188     expect -re {^[[:space:]]+\|-+[\r\n]+} { incr separator_count }
189     # capture the totals line
190     expect -re {^[[:space:]]+(\|[[:space:][:digit:]]*)[\r\n]+} {
191         regsub {[[:space:]]*$} $expect_out(1,string) "" totals_line
192     }
193     # skip the footer
194     expect -re {.+} { exp_continue }
195     # were item and totals lines even produced?
196     if { [info exists item_line] && [info exists totals_line] } {
197         # do the item and totals lines match?
198         if { $item_line eq $totals_line } {
199             pass "verify total for $name"
200         } else {
201             fail "verify total for $name"
202         }
203     } else {
204         # either an item line or the totals line was not seen
205         unresolved "verify total for $name"
206     }
207     if { $separator_count == 2 } {
208         pass "expected separator lines for $name"
209     } else {
210         fail "expected separator lines for $name"
211     }
214 #EOF