#!/usr/bin/python # glob_test: tests the global expansion character * # # * # # Requires ls command to be implemented and prompt plugin to be initialized # # ls, prompt # import sys, imp, atexit sys.path.append("/home/courses/cs3214/software/pexpect-dpty/"); import pexpect, shellio, signal, time, os, re, proc_check #Ensure the shell process is terminated def force_shell_termination(shell_process): c.close(force=True) # pulling in the regular expression and other definitions definitions_scriptname = sys.argv[1] plugin_dir = sys.argv[2] def_module = imp.load_source('', definitions_scriptname) logfile = None if hasattr(def_module, 'logfile'): logfile = def_module.logfile # spawn an instance of the shell c = pexpect.spawn(def_module.shell + plugin_dir, drainpty=True, logfile=logfile) atexit.register(force_shell_termination, shell_process=c) # set timeout for all following 'expect*' calls to 2 seconds c.timeout = 2 # call ls with one wildcard c.sendline("ls esh.*") # ensure ls prints the 3 esh files assert c.expect("esh.c esh.h esh.o\r\n") == 0, "Shell did not find expected esh files" # call ls with two wildcards c.sendline("ls esh.* esh-grammar.*") # ensure ls prints the 6 files assert c.expect("esh.c esh-grammar.l esh-grammar.o esh-grammar.y esh.h esh.o\r\n") == 0, \ "Shell did not find expected esh and esh-grammar files" # run an exit c.sendline("exit") # ensure that no extra characters are output after exiting assert c.expect_exact("exit\r\n") == 0, "Shell output extraneous characters" # the test was successful shellio.success()