Exemple #1
0
def fmt_test(deno_exe):
    sys.stdout.write("fmt_test...")
    sys.stdout.flush()
    d = mkdtemp()
    try:
        fixed_filename = os.path.join(tests_path, "badly_formatted_fixed.js")
        src = os.path.join(tests_path, "badly_formatted.js")
        dst = os.path.join(d, "badly_formatted.js")
        shutil.copyfile(src, dst)
        # Set DENO_DIR to //js/ so we don't have to rely on an intenet
        # connection to download https://deno.land/std/prettier/main.ts
        deno_dir = os.path.join(root_path, "js")
        # TODO(kt3k) The below line should be run([deno_exe, "fmt", dst], ...)
        # It should be updated when the below issue is addressed
        # https://github.com/denoland/deno_std/issues/330
        run([os.path.join(root_path, deno_exe), "fmt", "badly_formatted.js"],
            cwd=d,
            merge_env={"DENO_DIR": deno_dir})
        with open(fixed_filename) as f:
            expected = f.read()
        with open(dst) as f:
            actual = f.read()
        if expected != actual:
            print "Expected didn't match actual."
            print "expected: ", json.dumps(expected)
            print "actual: ", json.dumps(actual)
            sys.exit(1)

    finally:
        shutil.rmtree(d)
    print green_ok()
Exemple #2
0
def fmt_test(deno_exe):
    sys.stdout.write("fmt_test...")
    sys.stdout.flush()
    d = mkdtemp()
    try:
        fixed_filename = os.path.join(tests_path, "badly_formatted_fixed.js")
        src = os.path.join(tests_path, "badly_formatted.js")
        dst = os.path.join(d, "badly_formatted.js")
        shutil.copyfile(src, dst)
        # Set DENO_DIR to //js/ so we don't have to rely on an intenet
        # connection to download https://deno.land/std/prettier/main.ts
        deno_dir = os.path.join(root_path, "js")
        run([deno_exe, dst, "--fmt"], merge_env={"DENO_DIR": deno_dir})
        with open(fixed_filename) as f:
            expected = f.read()
        with open(dst) as f:
            actual = f.read()
        if expected != actual:
            print "Expected didn't match actual."
            print "expected: ", json.dumps(expected)
            print "actual: ", json.dumps(actual)
            sys.exit(1)

    finally:
        shutil.rmtree(d)
    print green_ok()
Exemple #3
0
def wrap_test(test_name, test_method, *argv):
    sys.stdout.write(test_name + " ... ")
    try:
        test_method(*argv)
        print green_ok()
    except AssertionError:
        print red_failed()
        raise
Exemple #4
0
def test_no_color(deno_exe):
    sys.stdout.write("no_color test...")
    sys.stdout.flush()
    t = os.path.join(tests_path, "no_color.js")
    output = run_output([deno_exe, t], merge_env={"NO_COLOR": "1"})
    assert output.strip() == "noColor true"
    t = os.path.join(tests_path, "no_color.js")
    output = run_output([deno_exe, t])
    assert output.strip() == "noColor false"
    print green_ok()
Exemple #5
0
def test_no_color(deno_exe):
    sys.stdout.write("no_color test...")
    sys.stdout.flush()
    t = os.path.join(tests_path, "no_color.js")
    output = run_output([deno_exe, t], merge_env={"NO_COLOR": "1"})
    assert output.strip() == "noColor true"
    t = os.path.join(tests_path, "no_color.js")
    output = run_output([deno_exe, t])
    assert output.strip() == "noColor false"
    print green_ok()
Exemple #6
0
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()
Exemple #7
0
 def run(self):
     print('repl_test.py')
     test_names = [name for name in dir(self) if name.startswith("test_")]
     for t in test_names:
         self.__getattribute__(t)()
         sys.stdout.write(".")
         sys.stdout.flush()
     print(' {}\n'.format(green_ok()))
Exemple #8
0
 def run(self):
     print('repl_test.py')
     test_names = [name for name in dir(self) if name.startswith("test_")]
     for t in test_names:
         self.__getattribute__(t)()
         sys.stdout.write(".")
         sys.stdout.flush()
     print(' {}\n'.format(green_ok()))
Exemple #9
0
def fetch_test(deno_exe):
    sys.stdout.write("fetch_test...")
    sys.stdout.flush()

    deno_dir = mkdtemp()
    try:
        t = os.path.join(tests_path, "006_url_imports.ts")
        output = run_output([deno_exe, "fetch", t],
                            merge_env={"DENO_DIR": deno_dir})
        assert output == ""
        # Check that we actually did the prefetch.
        os.path.exists(
            os.path.join(deno_dir,
                         "deps/http/localhost_PORT4545/tests/subdir/mod2.ts"))
    finally:
        shutil.rmtree(deno_dir)

    print green_ok()
Exemple #10
0
def prefetch_test(deno_exe):
    sys.stdout.write("prefetch_test...")
    sys.stdout.flush()

    deno_dir = mkdtemp()
    try:
        t = os.path.join(tests_path, "006_url_imports.ts")
        output = run_output([deno_exe, "--prefetch", t],
                            merge_env={"DENO_DIR": deno_dir})
        assert output == ""
        # Check that we actually did the prefetch.
        os.path.exists(
            os.path.join(deno_dir,
                         "deps/http/localhost_PORT4545/tests/subdir/mod2.ts"))
    finally:
        shutil.rmtree(deno_dir)

    print green_ok()
Exemple #11
0
def prefetch_test(deno_exe):
    sys.stdout.write("prefetch_test...")
    sys.stdout.flush()

    # On Windows, set the base directory that mkdtemp() uses explicitly. If not,
    # it'll use the short (8.3) path to the temp dir, which triggers the error
    # 'TS5009: Cannot find the common subdirectory path for the input files.'
    temp_dir = os.environ["TEMP"] if os.name == 'nt' else None
    deno_dir = tempfile.mkdtemp(dir=temp_dir)
    try:
        t = os.path.join(tests_path, "006_url_imports.ts")
        output = run_output([deno_exe, "--prefetch", t],
                            merge_env={"DENO_DIR": deno_dir})
        assert output == ""
        # Check that we actually did the prefetch.
        os.path.exists(
            os.path.join(deno_dir,
                         "deps/http/localhost_PORT4545/tests/subdir/mod2.ts"))
    finally:
        shutil.rmtree(deno_dir)

    print green_ok()
Exemple #12
0
def fmt_test(deno_exe):
    sys.stdout.write("fmt_test...")
    sys.stdout.flush()
    d = mkdtemp()
    try:
        fixed_filename = os.path.join(tests_path, "badly_formatted_fixed.js")
        src = os.path.join(tests_path, "badly_formatted.js")
        dst = os.path.join(d, "badly_formatted.js")
        shutil.copyfile(src, dst)
        # Set DENO_DIR to //js/ so we don't have to rely on an intenet
        # connection to download https://deno.land/x/std/prettier/main.ts
        deno_dir = os.path.join(root_path, "js")
        run([deno_exe, dst, "--fmt", "--allow-read"],
            merge_env={"DENO_DIR": deno_dir})
        with open(fixed_filename) as f:
            expected = f.read()
        with open(dst) as f:
            actual = f.read()
        assert expected == actual
    finally:
        shutil.rmtree(d)
    print green_ok()
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()