#!/usr/bin/python # #Brian Wright bwright5@vt.edu # # Reverse Echo test # Tests 3 cases: valid string, single char, null input # #This file needs to be declared in plugins.tst and located in the plugins directory # import sys, imp, atexit, mmap 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) c.sendline("touch log") #make sure file exists in time time.sleep(5) # set timeout for all following 'expect*' calls to 2 seconds c.timeout = 2 #create log file # run commands through a child process child = pexpect.spawn("./esh -p plugins") #redirect output to a log file with open("log","r+")as log_file: child.logfile = log_file child.send("recho abcdef\n") #run 3 cases of recho to test full functionality child.expect(".*") child.send("recho a\n") child.expect(".*") child.send("recho \n") child.expect(".*") child.send("\n") # just send a command to cmd prompt to allow recho to run child.expect(".*") a = open("log").read() # grab string for file #test that strings are found for each case in valid locations case1 = a.find("Reversed!: fedcba") != -1 case2 = a.find("Reversed!: a ") != -1 case3 = a.find("Need to type a string to reverse :(") != -1 assert case1 assert case2 #lame assert case3 #assert a.find("Reversed!: fedcba \n") != -1 # FAILS WHY??? #assert a.find("Reversed!: a \n") != -1 #assert a.find("Need") != -1 assert log_file.closed #make sure file closed time.sleep(2) os.remove("log") shellio.success()