# HG changeset patch # User Atul Varma # Date 1210539485 25200 # Node ID 4b6b9ea26552c05727b468fcc5015a4ee8e1b30f # Parent 6913491b18c41aa654065805480cfa15e751f61f Converted tests to output comparison tests, which makes them shorter and easier to understand and more accurate. diff -r 6913491b18c4 -r 4b6b9ea26552 run_tests.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/run_tests.py Sun May 11 13:58:05 2008 -0700 @@ -0,0 +1,35 @@ +import glob +import os +import subprocess + +JS_CMD = "js" + +TESTS = glob.glob(os.path.join("tests", "*.js")) + +OUTPUT_FILE = "test_output.txt" + +def run_tests(): + for test in TESTS: + output = open(OUTPUT_FILE, "w") + subprocess.call( + [JS_CMD, test], + stdout = output, + stderr = subprocess.STDOUT + ) + output.close() + + expected_output_file = "tests/output/%s.txt" % ( + os.path.splitext(os.path.basename(test))[0] + ) + + lines = open(OUTPUT_FILE, "r").readlines() + expected_lines = open(expected_output_file, "r").readlines() + + if lines != expected_lines: + print 'Test "%s" failed.' % test + else: + print 'Test "%s" passed.' % test + os.remove(OUTPUT_FILE) + +if __name__ == "__main__": + run_tests() diff -r 6913491b18c4 -r 4b6b9ea26552 tests/output/test_engine_runner.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/output/test_engine_runner.txt Sun May 11 13:58:05 2008 -0700 @@ -0,0 +1,3 @@ +onLineInput() received, responding with: hello +engine.answer() received: 1, hello +onQuit() received diff -r 6913491b18c4 -r 4b6b9ea26552 tests/output/test_gnusto_engine.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/output/test_gnusto_engine.txt Sun May 11 13:58:05 2008 -0700 @@ -0,0 +1,43 @@ +[SS] + + + + +It's not much of a job, but the Dungeon Master was looking for a guard troll, so you volunteered. You were given the standard-issue axe, and told to... well, guard. + + + +[SS] Zork: A Troll's Eye View +[SS] +An Interactive Tedium +by Dylan O'Donnell (dylanw@demon.net) +Type "info" for the story behind it. +["Zork" is a registered trademark of Activision, Inc., used with permission.] +Release 3 / Serial number 980518 / Inform v6.15 Library 6/7 + + +[SS] The Troll Room +[TW] +This is a small room with passages to the east and south and a forbidding hole leading west. Bloodstains and deep scratches (perhaps made by an axe) mar the walls. + +> +[SW] +[SC] +[SS] +[SC] +[SC] The Troll Room +[SS] +[SW] +[RS] +responding with "quit" +[TW] Are you sure you want to quit? +[SW] +[SC] +[SS] +[SC] +[SC] The Troll Room +[SS] +[SW] +[RS] +responding with "yes" +[QU] diff -r 6913491b18c4 -r 4b6b9ea26552 tests/test_engine_runner.js --- a/tests/test_engine_runner.js Sun May 11 13:29:13 2008 -0700 +++ b/tests/test_engine_runner.js Sun May 11 13:58:05 2008 -0700 @@ -21,15 +21,14 @@ effect = GNUSTO_EFFECT_QUIT; break; default: - throw Error('Unexpected step.'); + throw Error('Unexpected step'); } return effect.slice(1, -1); }, answer: function(number, response) { - if (response != "hello") - throw Error('Unexpected response.'); + print("engine.answer() received: "+number+", "+response); } }; } @@ -37,17 +36,15 @@ function TestZui() { var self = this; - self.callbackCount = 0; - self.hasQuit = false; - this.__proto__ = { onQuit: function() { - self.hasQuit = true; + print("onQuit() received"); }, onLineInput: function(callback) { - self.callbackCount += 1; - callback("hello"); + var response = "hello"; + print("onLineInput() received, responding with: "+response); + callback(response); } }; }; @@ -55,8 +52,3 @@ var gZui = new TestZui(); var gRunner = new EngineRunner(new FakeEngine(), gZui); gRunner.run(); -if (!gZui.callbackCount == 1) - throw Error('zui unexpected callback count: '+gZui.callbackCount); -if (!gZui.hasQuit) - throw Error('zui onQuit() not called.'); -print('Engine runner test run successfully.'); diff -r 6913491b18c4 -r 4b6b9ea26552 tests/test_gnusto_engine.js --- a/tests/test_gnusto_engine.js Sun May 11 13:29:13 2008 -0700 +++ b/tests/test_gnusto_engine.js Sun May 11 13:58:05 2008 -0700 @@ -1,7 +1,6 @@ load("troll.js", "gnusto-engine.js"); var gInputTimes = 0; -var gSetCursorTimes = 0; function step() { var retval = 0; @@ -9,46 +8,23 @@ engine.run(); var effect = engine.effect(0); var text = engine.consoleText(); - //if (text) - // print('['+effect+'] '+text); + print('['+effect+'] '+text); effect = '"' + effect + '"'; switch (effect) { - case GNUSTO_EFFECT_STYLE: - case GNUSTO_EFFECT_SPLITWINDOW: - case GNUSTO_EFFECT_SETWINDOW: - break; - case GNUSTO_EFFECT_SETCURSOR: - if (text) { - if (text != 'The Troll Room') - throw Error('Unexpected console text: "' + text + '"'); - gSetCursorTimes += 1; - } - break; case GNUSTO_EFFECT_INPUT: - switch (gInputTimes) { - case 0: - engine.answer(1, 'quit'); - break; - case 1: - engine.answer(1, 'yes'); - break; - default: - throw Error('Unexpected input.'); - } + var responses = ['quit', 'yes']; + var response = responses[gInputTimes]; + print('responding with "' + response + '"'); + engine.answer(1, response); gInputTimes += 1; break; case GNUSTO_EFFECT_QUIT: - if (gInputTimes != 2) - throw Error('Did not receive proper input before quit effect.'); - if (gSetCursorTimes != 2) - throw Error('Did not receive proper set cursor effects ' + - 'before quit effect.'); retval = 1; break; default: - throw Error('Unexpected effect: ' + effect); + break; }; return retval; @@ -59,4 +35,3 @@ engine.loadStory(troll_z5); while (step() == 0) {} -print('Gnusto engine test run successfully.');