#!/usr/bin/python # # Tests the functionality of canadian's quote removal plugin # # Written for CS 3214 Spring 2015. # # To run this test on your own shell, simply run: # # ~/cs3214/public_html/spring2015/projects/student-plugins/canadian/quote_support/canadian_quote_support_test.py eshoutput.py # # Execute the test from the directory in which your "esh" and your "eshoutput.py" is located. # # It should also be possible to make a copy of the test file anywhere, as long as the # 'canadian_quote_support.so' file is located within the same directory. # # @author gback # @author canadian # 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 = 2 ############################################################################# # Now the real test starts! # # ensure that shell prints expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt (1)" ################################################################# # Step 1. See if we can echo something in quotes c.sendline('echo "test"'); assert c.expect("test") == 0, 'Did not strip "test" correctly' ################################################################# # Step 2. See if we can handle quotes in quotes correctly c.sendline('echo """test"""'); assert c.expect("test") == 0, 'Did not strip ""test""" correctly' ################################################################# # Step 3. Now lets test with spaces in the quotes c.sendline('echo "test with spaces"'); assert c.expect("test with spaces") == 0, 'Did not strip "test with spaces" correctly' ################################################################# # Step 4. how about a combination of all of the above c.sendline('echo "this" is a "test with" ""multiple""" different """"things""""'); assert c.expect('this is a test with multiple" different things') == 0, 'Did not strip "this" is a "test with" ""multiple""" different """"things"""" correctly' shellio.success()