#!/usr/bin/python # Authors: dyland, mnutter3 # This script checks that the plug-in is working as expected. # import sys, imp, atexit, os 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) ######################################################################################################## #Cleaning up test directories from previous failures of the script. dirOne = "testDirForMnutter3DylandLS" dirTwo = "testDirForMnutter3DylandLS/A" dirThree = "testDirForMnutter3DylandLS/B" dirFour = "testDirForMnutter3DylandLS/A/.hiddenTester" if os.path.exists(dirFour): os.rmdir (dirFour) if os.path.exists(dirTwo): os.rmdir (dirTwo) if os.path.exists(dirThree): os.rmdir (dirThree) if os.path.exists(dirOne): os.rmdir(dirOne) ######################################################################################################## # set timeout for all following 'expect*' calls to 2 seconds c.timeout = 1 # ensure that shell prints expected prompt assert c.expect(def_module.prompt) == 0, "Shell did not print expected prompt (1)" #Making test directories. os.mkdir(dirOne) os.mkdir (dirTwo) #This dir has one other dir in it. c.sendline("ls testDirForMnutter3DylandLS") assert c.expect("A ") == 0, "Shell output did not match what was expected." #This dir should be empty. c.sendline("ls ./testDirForMnutter3DylandLS/A/") assert c.expect("") == 0, "Shell outputted something for ls in an empty directory." #Make a second directory in testDirForMnutter3DylandLS os.mkdir (dirThree) #This dir has two other dirs in it. Also checks that if the last char is '/' it is ignored. c.sendline("ls testDirForMnutter3DylandLS/") try: assert(c.expect("B A ") == 0), "Shell output is incorrect." except: assert(c.expect("A B ") == 0), "Shell output is incorrect." #Make hidden directory that ls shouldn't print off. os.mkdir(dirFour) #This dir has a hidden directory in it and should not output anything. c.sendline("ls testDirForMnutter3DylandLS/A") assert c.expect("") == 0 , "Shell output is incorrect." #Call ls on non existant directory. c.sendline("ls thisTestDirectoryShouldntExistAndIfItDoesYouProbablyPutItThereDylandMnutter3") assert c.expect("ls: No such file or directory") == 0 , "Shell output is incorrect." ######################################################################################################## #Cleaning up test directories. os.rmdir(dirFour) os.rmdir(dirThree) os.rmdir(dirTwo) os.rmdir(dirOne) ######################################################################################################## shellio.success()