#!/usr/bin/python # # Samyak Singh (ssing94) # Michael Louie (louiem) # # history_test: tests the history plugin. # # Test the history plugin for recording, displaying, and # clearing user commands in history. # Does not require any additional commands to be implemented # or otherwise unsable. # # SETUP #################################################################################### 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 # TEST #################################################################################### # test "history" c.sendline("history") assert c.expect("No history") == 0, "Test failed: History supposed to initialized empty!" # enter a user command. c.sendline("ls") # test "history"; # expecting ls entry. c.sendline("history") assert c.expect("1\tls") == 0, "Test failed: History supposed to have one entry (ls)." # enter a few user command with switches and built-ins. c.sendline("pwd") c.sendline("ls -al") c.sendline("echo hello world") c.sendline("cd .") c.sendline("jobs") c.sendline("fg") c.sendline("bg") c.sendline("kill") c.sendline("stop") c.sendline("") c.sendline("") # test "history"; # expecting lots of entries. c.sendline("history") assert c.expect("stop") == 0, "Test failed: History supposed to have a bunch of commands!" c.sendline("history -c") assert c.expect("History cleared.") == 0, "Test failed: History did not clear history entries." shellio.success()