From 60c254b279e8e8443b8ad26cc46b9e4084cff66c Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Sun, 29 Mar 2020 20:43:01 +0200 Subject: [PATCH] testsuite: Handle more kinds of gdc.test test flags and directives. This patch adds cases for JSON and D header file generation flags in the testsuite, and sets up the test accordingly to only compile, then check that the expected output file exists. Support has also been added for the DFLAGS test directive, which disables testing with all default flag permutations. gcc/testsuite/ChangeLog: * lib/gdc-utils.exp: (gdc-convert-args): Handle compilation test arguments -D, -H, -X, and set compilable_output_file_ext. (gdc-convert-test): Document and add cases DFLAGS and EXTRA_CPP_SOURCES. Add dg-final entry for output generation tests, and set compilable_do_what to compile. (gdc-do-test): Define compilable_do_what, default to assemble. --- gcc/testsuite/ChangeLog | 9 ++++ gcc/testsuite/lib/gdc-utils.exp | 76 ++++++++++++++++++++++----------- 2 files changed, 59 insertions(+), 26 deletions(-) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 498c2a9e062..2384d0beb69 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2020-03-29 Iain Buclaw + + * lib/gdc-utils.exp: (gdc-convert-args): Handle compilation test + arguments -D, -H, -X, and set compilable_output_file_ext. + (gdc-convert-test): Document and add cases DFLAGS and + EXTRA_CPP_SOURCES. Add dg-final entry for output generation tests, + and set compilable_do_what to compile. + (gdc-do-test): Define compilable_do_what, default to assemble. + 2020-03-29 Iain Buclaw * gdc.test/runnable_cxx/runnable_cxx.exp: New file. diff --git a/gcc/testsuite/lib/gdc-utils.exp b/gcc/testsuite/lib/gdc-utils.exp index ab8b9d5f838..31a4cf0b5e2 100644 --- a/gcc/testsuite/lib/gdc-utils.exp +++ b/gcc/testsuite/lib/gdc-utils.exp @@ -26,14 +26,26 @@ proc gdc-convert-args { args } { foreach arg [split [lindex $args 0] " "] { # List of switches kept in ASCII collated order. if [string match "-D" $arg] { + upvar 1 compilable_output_file_ext compilable_output_file_ext + set compilable_output_file_ext "html" lappend out "-fdoc" + } elseif [string match "-H" $arg] { + upvar 1 compilable_output_file_ext compilable_output_file_ext + set compilable_output_file_ext "di" + lappend out "-H" + } elseif { [regexp -- {^-I([\w+/-]+)} $arg pattern path] } { lappend out "-I$path" } elseif { [regexp -- {^-J([\w+/-]+)} $arg pattern path] } { lappend out "-J$path" + } elseif [string match "-X" $arg] { + upvar 1 compilable_output_file_ext compilable_output_file_ext + set compilable_output_file_ext "json" + lappend out "-X" + } elseif [string match "-allinst" $arg] { lappend out "-fall-instantiations" @@ -169,8 +181,13 @@ proc gdc-copy-extra { base extra } { # COMPILED_IMPORTS: List of modules files that are imported by the main # source file that should be included in compilation. # Currently handled the same as EXTRA_SOURCES. +# DFLAGS: Overrides the DFLAGS environment variable if specified +# in the test. No values are permitted; an error will be +# emitted if the value is not empty. # EXTRA_SOURCES: List of extra sources to build and link along with # the test. +# EXTRA_CPP_SOURCES: List of extra C++ files to build and link along with +# the test. # EXTRA_FILES: List of extra files to copy for the test runs. # PERMUTE_ARGS: The set of arguments to permute in multiple compiler # invocations. An empty set means only one permutation @@ -192,6 +209,9 @@ proc gdc-convert-test { base test } { set extra_sources "" set extra_files "" + upvar 1 compilable_do_what compilable_do_what + set compilable_output_file_ext "" + # Split base, folder/file. set type [file dirname $test] set name [file tail $test] @@ -220,6 +240,16 @@ proc gdc-convert-test { base test } { # POST_SCRIPT is not handled regsub -- {POST_SCRIPT.*$} $copy_line "" out_line + } elseif [regexp -- {DFLAGS\s*:\s*(.*)} $copy_line match args] { + # DFLAGS overrides the default value of PERMUTE_ARGS. + if { $args != "" } { + error "gdc-convert-test: DFLAGS is not empty as expected" + } + if { $PERMUTE_ARGS == $DEFAULT_DFLAGS } { + set PERMUTE_ARGS "" + } + regsub -- {DFLAGS.*$} $copy_line "" out_line + } elseif [regexp -- {PERMUTE_ARGS\s*:\s*(.*)} $copy_line match args] { # PERMUTE_ARGS is handled by gdc-do-test. set PERMUTE_ARGS [gdc-convert-args $args] @@ -277,24 +307,21 @@ proc gdc-convert-test { base test } { foreach srcfile $extra_sources { gdc-copy-extra $base "$type/$srcfile" } - set out_line "// { dg-additional-sources \"$extra_sources\" }" - puts $fdout $out_line + puts $fdout "// { dg-additional-sources \"$extra_sources\" }" } if { [llength $extra_files] > 0 } { foreach file $extra_files { gdc-copy-extra $base "$type/$file" } - set out_line "// { dg-additional-files \"$extra_files\" }" - puts $fdout $out_line + puts $fdout "// { dg-additional-files \"$extra_files\" }" } # Add specific options for test type # DMD's testsuite is extremely verbose, compiler messages from constructs # such as pragma(msg, ...) would otherwise cause tests to fail. - set out_line "// { dg-prune-output .* }" - puts $fdout $out_line + puts $fdout "// { dg-prune-output .* }" # Compilable files are successful if an output is generated. # Fail compilable are successful if an output is not generated. @@ -302,29 +329,30 @@ proc gdc-convert-test { base test } { switch $type { runnable { if ![isnative] { - set out_line "// { dg-final { output-exists } }" - puts $fdout $out_line + puts $fdout "// { dg-final { output-exists } }" } } compilable { - set out_line "// { dg-final { output-exists } }" - puts $fdout $out_line - - # Check that Ddoc tests also generate a html file. - if [regexp -- "ddoc.*" $name] { - set ddocfile "[file rootname $name].html" - set out_line "// { dg-final { scan-file $ddocfile \"Generated by Ddoc from $test\" } }" - puts $fdout $out_line + puts $fdout "// { dg-final { output-exists } }" + + # Compilable test may require checking another kind of output file. + if { $compilable_output_file_ext != "" } { + set compilable_do_what "compile" + # Check that file generation tests output the expected file. + set genfile "[file rootname $name].$compilable_output_file_ext" + puts $fdout "// { dg-final { if \[file exists $genfile\] \\{ } }" + puts $fdout "// { dg-final { pass \"$test (file exists $genfile)\" } }" + puts $fdout "// { dg-final { \\} else \\{ } }" + puts $fdout "// { dg-final { fail \"$test (file exists $genfile)\" } }" + puts $fdout "// { dg-final { \\} } }" # Cleanup extra generated files. - set out_line "// { dg-final { file delete $ddocfile } }" - puts $fdout $out_line + puts $fdout "// { dg-final { file delete $genfile } }" } } fail_compilation { - set out_line "// { dg-final { output-exists-not } }" - puts $fdout $out_line + puts $fdout "// { dg-final { output-exists-not } }" } } @@ -395,6 +423,7 @@ proc gdc-do-test { testcases } { # Convert to DG test. set imports [format "-I%s/%s" $base $dir] set cleanup_extra_files "" + set compilable_do_what "assemble" set filename "[gdc-convert-test $base $dir/$name.$ext]" if { $dir == "runnable" } { @@ -420,12 +449,7 @@ proc gdc-do-test { testcases } { compilable { for { set i 0 } { $i<[llength $options] } { incr i } { set flags [lindex $options $i] - # Compilable test may require checking another kind of output file. - if [regexp -- "ddoc.*" $name] { - set dg-do-what-default "compile" - } else { - set dg-do-what-default "assemble" - } + set dg-do-what-default $compilable_do_what gdc-dg-runtest $filename $flags $imports } } -- 2.30.2