aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/compile/nr2/compile.exp
blob: f2724f6c45442a13d62a5f347fb6111150e8e28d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# Copyright (C) 2021-2024 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/>.

# Compile tests, no torture testing, for name resolution 2.0
#
# These tests raise errors in the front end; torture testing doesn't apply.

# Load support procs.
load_lib rust-dg.exp

# Initialize `dg'.
dg-init

namespace eval rust-nr2-ns {
    # Exclude tests which aren't passing yet
    # These should be removed from the exclude file over time

    set exclude_fh [open $srcdir/$subdir/exclude r]
    set exclude_raw [lsort [split [read $exclude_fh] "\n"]]
    close $exclude_fh
    unset exclude_fh

    set exclude ""
    foreach ent $exclude_raw {
        if [regexp {^[^#].*} $ent] {
            lappend exclude $ent
	}
    }
    unset exclude_raw

    # Run tests in directories
    # Manually specifying these, in case some other test file
    # does something weird
    set test_dirs {{} {macros builtin} {macros mbe} {macros proc}}

    set tests_expect_ok ""
    set tests_expect_err ""

    foreach test_dir $test_dirs {
        set directory [list {*}[file split $srcdir] {*}[file split $subdir]]
	set directory [lreplace $directory end end]
	set directory [list {*}$directory {*}$test_dir]
        foreach test [lsort [glob -nocomplain -tails -directory [file join {*}$directory] *.rs]] {
	    # use '/' as the path seperator for entries in the exclude file
	    set test_lbl [join [list {*}$test_dir $test] "/"]
	    set idx [lsearch -exact -sorted $exclude $test_lbl]
	    if {$idx == -1} {
		lappend tests_expect_ok [file join {*}$directory $test]
	    } else {
		lappend tests_expect_err [file join {*}$directory $test]
		set exclude [lreplace $exclude $idx $idx]
	    }
	}
    }

    # Generate failures for unmatched tests in the exclude list
    foreach ent $exclude {
        fail "$ent: could not exclude test"
    }
    unset exclude

    # run a test while catching record_test calls
    set record_test_out ""
    proc try_test { test } {
        variable record_test_out
	rename ::record_test record_test_old

	proc ::record_test { type msg args } {
	    namespace eval ::rust-nr2-ns {
		set type [uplevel 1 {set type}]
		set msg [uplevel 1 {set msg}]
		variable record_test_out
		switch $type {
		    FAIL {
			lappend record_test_out "$type: $msg"
		    }
		    XPASS {
			lappend record_test_out "$type: $msg"
		    }
		}
            }
	}

        namespace eval :: {
	    set saved-dg-do-what-default ${dg-do-what-default}
	    set dg-do-what-default "compile"
            dg-runtest [list [uplevel 1 {set test}]] "-frust-name-resolution-2.0" ""
	    set dg-do-what-default ${saved-dg-do-what-default}
	}

        rename ::record_test ""
	rename record_test_old ::record_test

	set record_test_cache $record_test_out
        set record_test_out ""
	return $record_test_cache
    }

    # check for unexpected failures
    foreach test $tests_expect_ok {
        set fails [try_test $test]
	if {[llength $fails] != 0} {
	    foreach ent $fails {
		record_test FAIL "$test: nr2 failure: $ent"
	    }
	} else {
	    record_test PASS "$test: nr2 success"
	}
    }

    #check for unexpected successes
    foreach test $tests_expect_err {
        set fails [try_test $test]
	if {[llength $fails] == 0} {
	    record_test XPASS "$test: nr2 unexpectedly passed"
	} else {
	    record_test XFAIL "$test: nr2 was rightfully excluded"
	}
    }
}

# All done.
dg-finish