#!/usr/bin/python # # lua_test: tests the functionality implemented by Lua plug-ins. # # Tests executing the sample plugin `hellolua`. Upon running the command, the # plugin should output a message indicating that the Lua environment has been # created properly and that Lua can print to the Shell. If the message is output # to the shell, this indicates that plug-in initialization was also successful. # Finally, arguments are parsed and output to the console, if provided, for the # `hellolua` plug-in. # # 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) plugin_module = imp.load_source('', './plugins/group454_lua_eshoutput.py') 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 # run the `hellolua` Lua command c.sendline("hellolua") # hellolua should output "Hello, Lua!" assert c.expect_exact(plugin_module.hellolua_msg) == 0, "Shell did not output the result from the `hellolua` command" # send additional arguments to `hellolua` c.sendline("hellolua a b c") # hellolua should output "a, b, c" on the final line of output assert c.expect(plugin_module.hellolua_args) == 0, "Shell didn't output the arguments sent to the `hellolua` command" shellio.success()