title: detect assert(0) using tcl/expect
body: <p>Here is my <code>test.cpp</code> program.  It exits abnormally via an <code>assert(0)</code>.</p>
  
  <pre><code>#include &lt;cassert&gt;
  
  int main() {
    assert(0);
  }
  </code></pre>
  
  <p>When I run this program directly I get the expected output including a non-zero exit status:</p>
  
  <pre><code>$ ./test
  ...
  $ echo $?
  134
  </code></pre>
  
  <p>But when I try to detect the abnormal exit in <code>tcl/expect</code> I don't seem to be able to:</p>
  
  <pre><code>#!/usr/bin/expect
  
  spawn ./test
  expect eof
  lassign [wait] pid spawnid os_error_flag value
  
  if {$os_error_flag != 0} {
    puts "OS error"
    exit 1
  }
  if {$value != 0} {
    puts "Application error"
    exit 1
  }
  
  puts "No error"
  </code></pre>
  
  <p>When I run that script:</p>
  
  <pre><code>$ ./test.expect
  No error
  </code></pre>
  
  <p>If I use <code>exit(1)</code> instead of <code>assert(0)</code> then the tcl script is able to detect the abnormal exit.  Why doesn't <code>tcl/expect</code> provide an <code>OS-</code> or <code>application-returned</code> error code for assertion failures and how can I uniformly detect all abnormal program exits by checking the exit code?</p>