#!/bin/sh
#\
exec tclsh "$0" "$@"



set host [exec uname -n]

## If you feel that you cannot live any more without running these test,
## then change the 1 in the `if' below to a 0.
##                                            You really shouldn't.
if {1 && ("$host"!="Gauss" || "[pwd]"!="/home1/kir/work/bras")} {
  puts stderr "\
\n\n\n\n\n\n\n\nHi there,

it is nice that you like to run the tests, but I am afraid that it
does not make much sense. The tests are set up to be run on my machine in
a certain directory. They don't run on in another directory because
they contain absolute path names. 

If you insist on running the tests, then you may of course edit this
script. But then certainly some test fail. Please don't send me mail
about that.

Thanks,
   Harald Kirsch

P.S.: I hope to have tests independent of absolute path names in the
next release.
"
exit 1
}
########################################################################
## 
## Run prefabricated tests on bras.
## This is done by running bras on the files Test1/brasfile.??. These
## files return a message which describes the test, the result to be
## expected and finally the result. Expected result and actual result
## are compared.
##
cd Test1
foreach test [lsort -decreasing [glob brasfile.\[0-9\]\[0-9\]]] {
  puts -nonewline "[string trim $test brasfile.]: "
  catch "exec ../bras -f $test" output
  set expect {}
  set result {}
  foreach line [split $output "\n"] {
    switch -glob -- $line {
      msg:* {
	puts -nonewline [string range $line 5 end]
      }
      expect:* {
	append expect "[string range $line 8 end]\n"
      }
      default {
	append result "$line\n"
      }
    }
  }
  if { [string match "$expect*" $result] } {
    puts "    ...ok"
  } else {
    puts "    *** FAILED ***"
    puts "-----------------------------------------------------"
    puts "expected:"
    puts $expect
    puts "got:"
    puts $result
    puts "-----------------------------------------------------"
  }
}
