#!/usr/bin/python # # Tests the functionality of piping one command # to another command. EX: cat | sort -r # import sys, imp, atexit sys.path.append("/home/courses/cs3214/software/pexpect-dpty/"); import pexpect, shellio, signal, time, os, re, proc_check # glob_location should point to a directory with these 5 files: README.txt, # apple.c, pear.c, apple_pie.h, pear_pie.h # If need be, you can create a directory and then run the "touch" # command to create all of these files. what the files consist # of does not matter. glob_location = "/home/ugrads/nonmajors/domnap/systems/conch/trunk/test_material/glob_expansion" # location of the glob.so file. # either relative to stdriver.py, or can be absolute path to glob.so #so_location = "./plugins/glob" plugin_dir = sys.argv[2] #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] 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) c.logfile = sys.stdout # set timeout for all following 'expect*' calls to 2 seconds c.timeout = 2 # ensure that shell prints expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt (1)" ################################################################# # First, ensure that all of the files are present: # apple.c apple_pie.h pear.c pear_pie.h README.txt # run ls c.sendline("ls " + glob_location); #wait until the process "cat" takes over the foreground process group #proc_check.wait_until_child_is_in_foreground(c) assert c.expect_exact("apple.c apple_pie.h pear.c pear_pie.h README.txt") == 0, \ "glob_location must point to a director containing these files: apple.c apple_pie.h pear.c pear_pie.h README.txt" ################################################################# # Test glob expansion for *.c # ensure that shell prints expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt (after ls)" # cd to the working test directory c.sendline("cd " + glob_location) assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt (after cd)" # run command. should print .c files c.sendline("echo *.c") assert c.expect_exact("apple.c pear.c") == 0, "command did not print correct *.c fruits" ################################################################# # Test glob expansion at the end of the word # ensure that shell prints expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt (3)" # run command. should print fruit names containing p c.sendline("echo pear*") assert c.expect_exact("pear.c pear_pie.h") == 0, "echo pear* does not work correctly" shellio.success()