#!../tclsh
#
#	Check the results of the regression tests against known
#	problems:
#

catch {eval exec cat [glob *.results] | grep -c FAILED} rrr
if {[lindex $rrr 0] == 0} {puts "No failed tests"} else {
    puts "[lindex $rrr 0] tests failed.  The Failures are:"
    catch {eval exec cat [glob *.results] | grep -n FAILED} rrr
    puts $rrr
    set f [open temp w]
    puts $f $rrr
    close $f
    catch {exec diff known_errors temp} rrr
    if {[lindex $rrr 0] == 0} {puts "No New failed tests!"} else {
	puts "[lindex $rrr 0] tests results changed.  The changes are:"
	puts $rrr
    }
}

foreach gte {error return break continue exception} {
    set check_for "generated $gte"
    catch {eval exec cat [glob *results] | grep -c \"$check_for\"} rrr
    if {[lindex $rrr 0] == 0} {
	puts "No generated $gte errors in tests"
    } else {
	puts "$rrr tests generated $gte errors."
    }
}

set tr [open cur_tests_run r]
set ar [open all_tests_run r]
set lar [read $ar]
set ltr [read $tr]
close $tr
close $ar

set count 0
foreach tar $lar {
    set ind_mat [lsearch $ltr $tar]
    if {$ind_mat < 0} {
	puts "Test $tar was not run!"
	incr count
    } else {
	lreplace $ltr $ind_mat $ind_mat
    }
}

set leftover [llength $ltr]
if {$leftover > 0} {
    puts "Tests that were run that were not noted before:\n$ltr"
}

if {$count == 0} {puts "All tests run!"} else {
    puts "A total of $count tests were not run!"
    puts "Unrun files of tests due to compilation failure:"
    set allTests [glob *.test]
    set actualTests [glob *.results]
    regsub -all test $allTests results allRunTests
    foreach runTest $allRunTests {
	if {![regexp $runTest $actualTests]} {
	    regsub ".results" $runTest "" testName
	    if {$testName != "expr"} {puts "Test $testName was not run!"}
	}
    }
}

