def integration_tests(deno_exe, test_filter=None): assert os.path.isfile(deno_exe) tests = sorted([ filename for filename in os.listdir(tests_path) if filename.endswith(".test") ]) assert len(tests) > 0 for test_filename in tests: if test_filter and test_filter not in test_filename: continue test_abs = os.path.join(tests_path, test_filename) test = read_test(test_abs) exit_code = int(test.get("exit_code", 0)) args = test.get("args", "").split(" ") check_stderr = str2bool(test.get("check_stderr", "false")) stderr = subprocess.STDOUT if check_stderr else open(os.devnull, 'w') output_abs = os.path.join(root_path, test.get("output", "")) with open(output_abs, 'r') as f: expected_out = f.read() cmd = [deno_exe] + args sys.stdout.write("tests/%s ... " % (test_filename)) sys.stdout.flush() actual_code = 0 try: actual_out = subprocess.check_output(cmd, universal_newlines=True, stderr=stderr) except subprocess.CalledProcessError as e: actual_code = e.returncode actual_out = e.output if exit_code != actual_code: print "... " + red_failed() print "Expected exit code %d but got %d" % (exit_code, actual_code) print "Output:" print actual_out sys.exit(1) actual_out = strip_ansi_codes(actual_out) if pattern_match(expected_out, actual_out) != True: print red_failed() print "Expected output does not match actual." print "Expected output: \n" + expected_out print "Actual output: \n" + actual_out sys.exit(1) print green_ok()
def test_pattern_match(self): # yapf: disable fixtures = [("foobarbaz", "foobarbaz", True), ("[WILDCARD]", "foobarbaz", True), ("foobar", "foobarbaz", False), ("foo[WILDCARD]baz", "foobarbaz", True), ("foo[WILDCARD]baz", "foobazbar", False), ("foo[WILDCARD]baz[WILDCARD]qux", "foobarbazqatqux", True), ("foo[WILDCARD]", "foobar", True), ("foo[WILDCARD]baz[WILDCARD]", "foobarbazqat", True)] # yapf: enable # Iterate through the fixture lists, testing each one for (pattern, string, expected) in fixtures: actual = pattern_match(pattern, string) assert expected == actual, \ "expected %s for\nExpected:\n%s\nTo equal actual:\n%s" % ( expected, pattern, string) assert pattern_match("foo[BAR]baz", "foobarbaz", "[BAR]") == True, "expected wildcard to be set" assert pattern_match("foo[BAR]baz", "foobazbar", "[BAR]") == False, "expected wildcard to be set"
def pattern_match_test(): print "Testing util.pattern_match()..." # yapf: disable fixtures = [("foobarbaz", "foobarbaz", True), ("[WILDCARD]", "foobarbaz", True), ("foobar", "foobarbaz", False), ("foo[WILDCARD]baz", "foobarbaz", True), ("foo[WILDCARD]baz", "foobazbar", False), ("foo[WILDCARD]baz[WILDCARD]qux", "foobarbazqatqux", True), ("foo[WILDCARD]", "foobar", True), ("foo[WILDCARD]baz[WILDCARD]", "foobarbazqat", True)] # yapf: enable # Iterate through the fixture lists, testing each one for (pattern, string, expected) in fixtures: actual = pattern_match(pattern, string) assert expected == actual, \ "expected %s for\nExpected:\n%s\nTo equal actual:\n%s" % ( expected, pattern, string) assert pattern_match("foo[BAR]baz", "foobarbaz", "[BAR]") == True, "expected wildcard to be set" assert pattern_match("foo[BAR]baz", "foobazbar", "[BAR]") == False, "expected wildcard to be set"
def generate(self, test_filename): test_abs = os.path.join(tests_path, test_filename) test = read_test(test_abs) exit_code = int(test.get("exit_code", 0)) args = test.get("args", None) if not args: return # TODO(kevinkassimo): better args parsing with quotation marks. args = args.split(" ") check_stderr = str2bool(test.get("check_stderr", "false")) stderr = subprocess.STDOUT if check_stderr else open(os.devnull, 'w') stdin_input = (test.get("input", "").strip().decode("string_escape").replace( "\r\n", "\n")) has_stdin_input = len(stdin_input) > 0 output_abs = os.path.join(root_path, test.get("output", "")) with open(output_abs, 'r') as f: expected_out = f.read() cmd = [self.deno_exe] + args actual_code = 0 try: if has_stdin_input: # Provided stdin proc = subprocess.Popen( cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr) actual_out, _ = proc.communicate(stdin_input) actual_out = actual_out.replace("\r\n", "\n") else: # No stdin sent actual_out = subprocess.check_output( cmd, universal_newlines=True, stderr=stderr) except subprocess.CalledProcessError as e: actual_code = e.returncode actual_out = e.output actual_out = strip_ansi_codes(actual_out) if not pattern_match(expected_out, actual_out): # This will always throw since pattern_match failed. self.assertEqual(expected_out, actual_out) self.assertEqual(exit_code, actual_code)
def integration_tests(deno_executable): assert os.path.isfile(deno_executable) tests = sorted([ filename for filename in os.listdir(tests_path) if filename.endswith(".test") ]) assert len(tests) > 0 for test_filename in tests: test_abs = os.path.join(tests_path, test_filename) test = read_test(test_abs) exit_code = int(test.get("exit_code", 0)) args = test.get("args", "").split(" ") output_abs = os.path.join(root_path, test.get("output", "")) with open(output_abs, 'r') as f: expected_out = f.read() cmd = [deno_executable] + args print "test %s" % (test_filename) print " ".join(cmd) actual_code = 0 try: actual_out = subprocess.check_output(cmd, universal_newlines=True) except subprocess.CalledProcessError as e: actual_code = e.returncode actual_out = e.output if exit_code != actual_code: print "... " + red_failed() print "Expected exit code %d but got %d" % (exit_code, actual_code) print "Output:" print actual_out sys.exit(1) if pattern_match(expected_out, actual_out) != True: print "... " + red_failed() print "Expected output does not match actual." print "Expected output: \n" + expected_out print "Actual output: \n" + actual_out sys.exit(1) print "... " + green_ok()
def check_output_test(deno_exe_filename): assert os.path.isfile(deno_exe_filename) outs = sorted([ filename for filename in os.listdir(tests_path) if filename.endswith(".out") ]) assert len(outs) > 1 tests = [(os.path.splitext(filename)[0], filename) for filename in outs] for (script, out_filename) in tests: script_abs = os.path.join(tests_path, script) out_abs = os.path.join(tests_path, out_filename) with open(out_abs, 'r') as f: expected_out = f.read() cmd = [deno_exe_filename, script_abs, "--reload"] expected_code = parse_exit_code(script) print " ".join(cmd) actual_code = 0 try: actual_out = subprocess.check_output(cmd, universal_newlines=True) except subprocess.CalledProcessError as e: actual_code = e.returncode actual_out = e.output if expected_code == 0: print "Expected success but got error. Output:" print actual_out sys.exit(1) if expected_code != actual_code: print "Expected exit code %d but got %d" % (expected_code, actual_code) print "Output:" print actual_out sys.exit(1) if pattern_match(expected_out, actual_out) != True: print "Expected output does not match actual." print "Expected: " + expected_out print "Actual: " + actual_out sys.exit(1)