#
# run a wizard file
#
proc wizard-run { src ui } {

  set path [split $src "/"]
  set filename [lindex $path [expr [llength $path]-1]]

  # extract basename and check extension

  set fname [split $filename "."]

  if {[llength $fname] < 2} {
    fail "Bad filename syntax '$src'"
    return
  }
  if {[lindex $fname [expr [llength $fname]-1]] != "ycp"} {
    fail "Not .ycp extension '$src'"
    return
  }

  # setup filenames

  set base_name [lindex $fname 0]

  set stdout_name "tests/$base_name.out"
  set stderr_name "tests/$base_name.err"
  set tmpout_name "tmp.out.$base_name"
  set tmperr_name "tmp.err.$base_name"
  # run the test

  puts "Running $base_name..."   

  set result ""
  set oops [catch { set result [exec "/usr/lib/YaST2/bin/y2base" "$src" "$ui" "-T" ">" "$tmpout_name" "2>" "$tmperr_name"] } catched]

  if {$oops != 0} {
    fail "y2$ui failed: $catched"
    return
  }

  # check return code from y2XX

  if {$result != ""} {
    warning "Compilation of $base_name results in '$result'"
    return
  }

  # check stdout

  if {[diff $stdout_name $tmpout_name] != 1} {
    fail "Wrong stdout for $base_name"
    return
  }

  # check stderr
# D I S A B L E D
#  if {[diff $stderr_name $tmperr_name] != 1} {
#    fail "Wrong stderr for $base_name"
#    return
#  }
#
  # ok, all is fine

  pass $base_name

  return
}

