Ejemplo n.º 1
0
    def test_fmt(self):
        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 the temp dir to test an initial fetch of prettier.
            # TODO(ry) This make the test depend on internet access which is not
            # ideal. We should have prettier in the repo already, and we could
            # fetch it instead through tools/http_server.py.
            deno_dir = d

            result = run_output(
                [os.path.join(root_path, self.deno_exe), "fmt", dst],
                cwd=d,
                merge_env={"DENO_DIR": deno_dir},
                exit_on_fail=True,
                quiet=True)
            self.assertEqual(result.code, 0)
            with open(fixed_filename) as f:
                expected = f.read()
            with open(dst) as f:
                actual = f.read()
            self.assertEqual(expected, actual)
        finally:
            shutil.rmtree(d)
Ejemplo n.º 2
0
    def test_fmt(self):
        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 the temp dir to test an initial fetch of prettier.
            # TODO(ry) This make the test depend on internet access which is not
            # ideal. We should have prettier in the repo already, and we could
            # fetch it instead through tools/http_server.py.
            deno_dir = d

            # TODO(kt3k) Below can be run([deno_exe, "fmt", dst], ...)
            # once the following issue is addressed:
            # https://github.com/denoland/deno_std/issues/330
            run([
                os.path.join(root_path, self.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()
            self.assertEqual(expected, actual)
        finally:
            shutil.rmtree(d)
Ejemplo n.º 3
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()
Ejemplo n.º 4
0
Archivo: fmt_test.py Proyecto: uvd/deno
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()
Ejemplo n.º 5
0
    def test_deno_dir(self):
        deno_dir = mkdtemp()
        if os.path.isdir(deno_dir):
            rmtree(deno_dir)

        # Run deno with no env flag
        self.run_deno()
        assert not os.path.isdir(deno_dir)
Ejemplo n.º 6
0
 def test_fetch(self):
     deno_dir = mkdtemp()
     try:
         t = os.path.join(tests_path, "006_url_imports.ts")
         output = run_output([self.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)
Ejemplo n.º 7
0
    def test_deno_dir(self):
        deno_dir = mkdtemp()
        if os.path.isdir(deno_dir):
            rmtree(deno_dir)

        # Run deno with no env flag
        self.run_deno()
        assert not os.path.isdir(deno_dir)

        # Run deno with DENO_DIR env flag
        self.run_deno(deno_dir)
        assert os.path.isdir(deno_dir)
        assert os.path.isdir(os.path.join(deno_dir, "deps"))
        assert os.path.isdir(os.path.join(deno_dir, "gen"))
        rmtree(deno_dir)
Ejemplo n.º 8
0
 def test_fetch(self):
     deno_dir = mkdtemp()
     try:
         t = os.path.join(tests_path, "006_url_imports.ts")
         result = run_output([self.deno_exe, "fetch", t],
                             quiet=True,
                             merge_env={"DENO_DIR": deno_dir})
         self.assertEqual(result.out, "")
         self.assertEqual(result.code, 0)
         # Check that we actually did the prefetch.
         os.path.exists(
             os.path.join(
                 deno_dir,
                 "deps/http/localhost_PORT4545/cli/tests/subdir/mod2.ts"))
     finally:
         shutil.rmtree(deno_dir)
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 11
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()