title: #include in Expect script
body: <p>So I am having trouble making TestCases with expect scripts, I have like 10 TestCases which all starts and ends with the same "functions" like login and logout or turning some flags off, is there a possibility to include them or execute them remotely from my script, like <code>spawn login.exp</code> or even better to put them in functions ?</p>
  
  <p>TC01.exp</p>
  
  <pre><code>#!/usr/bin/expect -f
  set timeout 5
  
  #example of getting arguments passed from command line..
  #not necessarily the best practice for passwords though...
  set server [lindex $argv 0]
  set user [lindex $argv 1]
  set pass [lindex $argv 2]
  set no [lindex $argv 3]
  set counter 0
  
  # connect to server via ssh, login, and su to root
  send_user "connecting to $server\n"
  spawn ssh $user@$server
  
  #login handles cases:
  #   login with keys (no user/pass)
  #   user/pass
  #   login with keys (first time verification)
  expect {
    "&gt; " { }
    "$ " { }
  
    "assword: " { 
          send "$pass\n" 
          expect {
            "&gt; " { }
            "$ " { }
            "assword: " { 
                      send_user "\nLogin failed\n" 
                                      incr counter 1
                      exit 5
  
                  }
          }
    }
    "(yes/no)? " { 
          send "yes\n"
          expect {
            "&gt; " { }
            "$ " { }
          }
    }
   default {
          send_user "Login failed\n"
          incr counter 1
          exit
    }
  }
  
  
  #TEST CASE HERE
  
  
  #login out
  send "exit\n"
  
  expect {
      "&gt; " {}
      default {}
  }
  
  
  if { $counter &gt; 0 } {
      send_user "\nTestCase finished with some errors!\nFAILED!!!\nERRORS $counter\n";
      exit 4;
  }
  
  send_user "\nTestCase finished with SUCCESS!\nERRORS: $counter\n";
  </code></pre>
  
  <p>So i would like to have login and count_error as functions, so I would be able to create my test cases just like this:</p>
  
  <p>TC01.exp</p>
  
  <pre><code>#!/usr/bin/expect -f
  set timeout 5
  set server [lindex $argv 0]
  set user [lindex $argv 1]
  set pass [lindex $argv 2]
  set no [lindex $argv 3]
  set counter 0
  
  
  login($server, $user, $pass)
  
  #TestCase
  
  Errors($counter)
  exit
  </code></pre>