| # Copyright (C) 2000-2026 Free Software Foundation, Inc. | |
| # This program is free software; you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation; either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| # GNU General Public License for more details. | |
| # | |
| # You should have received a copy of the GNU General Public License | |
| # along with GCC; see the file COPYING3. If not see | |
| # <http://www.gnu.org/licenses/>. | |
| # Various utilities for scanning HTML output, used by gcc-dg.exp and | |
| # g++-dg.exp. | |
| # | |
| # This is largely borrowed from scansarif.exp. | |
| proc html-pytest-format-line { args } { | |
| global subdir | |
| set testcase [lindex $args 0] | |
| set pytest_script [lindex $args 1] | |
| set output_line [lindex $args 2] | |
| set index [string first "::" $output_line] | |
| set test_output [string range $output_line [expr $index + 2] [string length $output_line]] | |
| return "$subdir/$testcase ${pytest_script}::${test_output}" | |
| } | |
| # Call by dg-final to run a pytest Python script. | |
| # We pass filename of a test via HTML_PATH environment variable. | |
| proc run-html-pytest { args } { | |
| global srcdir subdir | |
| # Extract the test file name from the arguments. | |
| set testcase [lindex $args 0] | |
| verbose "Running HTML $testcase in $srcdir/$subdir" 2 | |
| set testcase [remote_download host $testcase] | |
| set pytest_script [lindex $args 1] | |
| if { ![check_effective_target_pytest3] } { | |
| unsupported "$pytest_script pytest python3 is missing" | |
| return | |
| } | |
| setenv HTML_PATH $testcase | |
| set libdir "${srcdir}/lib" | |
| # Set/prepend libdir to PYTHONPATH | |
| if [info exists ::env(PYTHONPATH)] { | |
| set old_PYTHONPATH $::env(PYTHONPATH) | |
| setenv PYTHONPATH "${libdir}:${old_PYTHONPATH}" | |
| } else { | |
| setenv PYTHONPATH "${libdir}" | |
| } | |
| verbose "PYTHONPATH=[getenv PYTHONPATH]" 2 | |
| spawn -noecho {*}[pytest_invoke] $srcdir/$subdir/$pytest_script | |
| if [info exists old_PYTHONPATH] { | |
| setenv PYTHONPATH ${old_PYTHONPATH} | |
| } | |
| set prefix "\[^\r\n\]*" | |
| set timeout 300 | |
| expect { | |
| -re "FAILED($prefix)\r\n" { | |
| set output [html-pytest-format-line $testcase $pytest_script $expect_out(1,string)] | |
| fail $output | |
| exp_continue | |
| } | |
| -re "ERROR($prefix)\r\n" { | |
| set output [html-pytest-format-line $testcase $pytest_script $expect_out(1,string)] | |
| fail $output | |
| exp_continue | |
| } | |
| -re "PASSED($prefix)\r\n" { | |
| set output [html-pytest-format-line $testcase $pytest_script $expect_out(1,string)] | |
| pass $output | |
| exp_continue | |
| } | |
| timeout { | |
| fail "$subdir/$testcase $pytest_script timed out" | |
| } | |
| } | |
| } |