#!/usr/bin/python # # Tests the functionality of time plugin # Does not support background processes # Shell must be able to support process_builtin, # process_raw_cmdline, and command_status_change # # Written for CS 3214 Spring 2015. # # To run this test on your own shell, simply run: # # # @author Lance Chao, Alice Wang # import sys, imp, atexit, os sys.path.append("/home/courses/cs3214/software/pexpect-dpty/"); import pexpect, shellio, signal, time, os, re, proc_check # Determine the path this file is in thisdir = os.path.dirname(os.path.realpath(__file__)) #Ensure the shell process is terminated def force_shell_termination(shell_process): c.close(force=True) # pulling in the regular expression and other definitions # this should be the eshoutput.py file of the hosting shell, see usage above definitions_scriptname = sys.argv[1] def_module = imp.load_source('', definitions_scriptname) # you can define logfile=open("log.txt", "w") in your eshoutput.py if you want logging! logfile = None if hasattr(def_module, 'logfile'): logfile = def_module.logfile #spawn an instance of the shell, note the -p flags c = pexpect.spawn(def_module.shell, drainpty=True, logfile=logfile, args=['-p', thisdir]) atexit.register(force_shell_termination, shell_process=c) # set timeout for all following 'expect*' calls to 2 seconds c.timeout = 5 ############################################################################# # Now the real test starts! # ################################################################# # Step 1. Run sleep with time # c.sendline("time sleep 1") assert c.expect('sleep executed in') == 0, \ "Error: expected output is sleep executed in 1001 milliseconds" ################################################################# # Step 2. Run sleep with time in a pipeline # c.sendline("time sleep 1 | sleep 1") assert c.expect('sleep executed in') == 0, \ "Error: expected output is sleep executed in 1001 milliseconds" shellio.success()