#!/usr/bin/expect -f

set env(EDITOR) "./fakeditor.sh"
set env(VISUAL) "./fakeditor.sh"
set crashdir [lindex $argv 0]
spawn report-cli -e test_event_vtre $crashdir

set timeout 60

# timeout handler
proc itstime {args} {
  puts "!! Timeout !!"
  exit 1
}

while {1} {
  expect {
    eof {break}
    timeout { itstime }
    # analyzers
    -re "\n (\[0-9\]).*?GNU Debugger" {
      puts "Got GNU Debbuger"
      set debugger_opt $expect_out(1,string)
      puts ">> $debugger_opt"
    }
    -re "\n (\[0-9\]).*?Retrace Server" {
      puts "Got Retrace Server"
      set retrace_opt $expect_out(1,string)
      puts ">> $retrace_opt"
    }
    "Select analyzer:" {
      send "$debugger_opt\r"
    }
    # debuginfo installation
    "Downloading" {
      send "N\r"
    }
  }
}
wait
