2013-05-08 13:04:35 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- encoding: utf-8 -*-
|
2018-01-01 16:38:33 +01:00
|
|
|
# Copyright 2018 the authors.
|
2017-04-27 23:16:57 +02:00
|
|
|
# This file is part of Hy, which is free software licensed under the Expat
|
|
|
|
# license. See the LICENSE.
|
|
|
|
|
2013-05-08 13:04:35 +02:00
|
|
|
import os
|
2017-03-24 17:03:12 +01:00
|
|
|
import re
|
2018-08-22 20:20:07 +02:00
|
|
|
import sys
|
2017-08-30 23:37:12 +02:00
|
|
|
import shlex
|
|
|
|
import subprocess
|
|
|
|
|
2018-08-20 06:29:29 +02:00
|
|
|
from hy.importer import cache_from_source
|
|
|
|
|
2017-06-21 00:30:13 +02:00
|
|
|
import pytest
|
2013-04-20 22:27:10 +02:00
|
|
|
|
2018-06-17 18:10:44 +02:00
|
|
|
from hy._compat import builtins
|
2017-08-30 23:37:12 +02:00
|
|
|
|
2013-04-20 22:27:10 +02:00
|
|
|
|
2014-11-06 04:01:10 +01:00
|
|
|
hy_dir = os.environ.get('HY_DIR', '')
|
|
|
|
|
|
|
|
|
2017-03-24 17:03:12 +01:00
|
|
|
def hr(s=""):
|
|
|
|
return "hy --repl-output-fn=hy.contrib.hy-repr.hy-repr " + s
|
|
|
|
|
|
|
|
|
2017-06-21 01:12:32 +02:00
|
|
|
def run_cmd(cmd, stdin_data=None, expect=0, dontwritebytecode=False):
|
2018-03-31 08:51:48 +02:00
|
|
|
env = dict(os.environ)
|
2017-06-21 01:12:32 +02:00
|
|
|
if dontwritebytecode:
|
|
|
|
env["PYTHONDONTWRITEBYTECODE"] = "1"
|
2018-03-31 08:51:48 +02:00
|
|
|
else:
|
|
|
|
env.pop("PYTHONDONTWRITEBYTECODE", None)
|
|
|
|
|
2017-08-30 23:37:12 +02:00
|
|
|
cmd = shlex.split(cmd)
|
|
|
|
cmd[0] = os.path.join(hy_dir, cmd[0])
|
|
|
|
p = subprocess.Popen(cmd,
|
2013-06-29 23:56:58 +02:00
|
|
|
stdin=subprocess.PIPE,
|
2013-05-08 13:04:35 +02:00
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
2017-06-18 00:36:48 +02:00
|
|
|
universal_newlines=True,
|
2017-08-30 23:37:12 +02:00
|
|
|
shell=False,
|
2017-06-21 01:12:32 +02:00
|
|
|
env=env)
|
2018-02-08 20:45:18 +01:00
|
|
|
output = p.communicate(input=stdin_data)
|
|
|
|
assert p.wait() == expect
|
|
|
|
return output
|
2013-04-24 15:21:42 +02:00
|
|
|
|
|
|
|
|
2017-04-10 02:27:51 +02:00
|
|
|
def rm(fpath):
|
|
|
|
try:
|
|
|
|
os.remove(fpath)
|
|
|
|
except (IOError, OSError):
|
|
|
|
try:
|
|
|
|
os.rmdir(fpath)
|
|
|
|
except (IOError, OSError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2013-04-24 15:21:42 +02:00
|
|
|
def test_bin_hy():
|
2017-03-17 17:31:54 +01:00
|
|
|
run_cmd("hy", "")
|
2013-04-24 15:21:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_stdin():
|
2017-03-17 17:31:54 +01:00
|
|
|
output, _ = run_cmd("hy", '(koan)')
|
|
|
|
assert "monk" in output
|
2013-04-24 15:21:42 +02:00
|
|
|
|
2017-03-24 17:03:12 +01:00
|
|
|
output, _ = run_cmd("hy --spy", '(koan)')
|
|
|
|
assert "monk" in output
|
2017-10-31 21:13:41 +01:00
|
|
|
assert "\n Ummon" in output
|
2017-03-24 17:03:12 +01:00
|
|
|
|
|
|
|
# --spy should work even when an exception is thrown
|
|
|
|
output, _ = run_cmd("hy --spy", '(foof)')
|
|
|
|
assert "foof()" in output
|
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_stdin_multiline():
|
|
|
|
output, _ = run_cmd("hy", '(+ "a" "b"\n"c" "d")')
|
|
|
|
assert "'abcd'" in output
|
|
|
|
|
|
|
|
|
2018-03-04 23:44:56 +01:00
|
|
|
def test_bin_hy_history():
|
2018-03-31 23:26:46 +02:00
|
|
|
output, _ = run_cmd("hy", '''(+ "a" "b")
|
|
|
|
(+ "c" "d")
|
|
|
|
(+ "e" "f")
|
|
|
|
(.format "*1: {}, *2: {}, *3: {}," *1 *2 *3)''')
|
|
|
|
assert "'*1: ef, *2: cd, *3: ab,'" in output
|
|
|
|
|
|
|
|
output, _ = run_cmd("hy", '''(raise (Exception "TEST ERROR"))
|
|
|
|
(+ "err: " (str *e))''')
|
|
|
|
assert "'err: TEST ERROR'" in output
|
2018-03-04 23:44:56 +01:00
|
|
|
|
|
|
|
|
2017-03-24 17:03:12 +01:00
|
|
|
def test_bin_hy_stdin_comments():
|
|
|
|
_, err_empty = run_cmd("hy", '')
|
|
|
|
|
|
|
|
output, err = run_cmd("hy", '(+ "a" "b") ; "c"')
|
|
|
|
assert "'ab'" in output
|
|
|
|
assert err == err_empty
|
|
|
|
|
|
|
|
_, err = run_cmd("hy", '; 1')
|
|
|
|
assert err == err_empty
|
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_stdin_assignment():
|
|
|
|
# If the last form is an assignment, don't print the value.
|
|
|
|
|
|
|
|
output, _ = run_cmd("hy", '(setv x (+ "A" "Z"))')
|
|
|
|
assert "AZ" not in output
|
|
|
|
|
|
|
|
output, _ = run_cmd("hy", '(setv x (+ "A" "Z")) (+ "B" "Y")')
|
|
|
|
assert "AZ" not in output
|
|
|
|
assert "BY" in output
|
|
|
|
|
|
|
|
output, _ = run_cmd("hy", '(+ "B" "Y") (setv x (+ "A" "Z"))')
|
|
|
|
assert "AZ" not in output
|
|
|
|
assert "BY" not in output
|
|
|
|
|
|
|
|
|
2017-03-24 17:03:55 +01:00
|
|
|
def test_bin_hy_stdin_as_arrow():
|
|
|
|
# https://github.com/hylang/hy/issues/1255
|
|
|
|
output, _ = run_cmd("hy", "(as-> 0 it (inc it) (inc it))")
|
|
|
|
assert re.match(r"=>\s+2L?\s+=>", output)
|
|
|
|
|
|
|
|
|
2017-03-24 19:09:30 +01:00
|
|
|
def test_bin_hy_stdin_error_underline_alignment():
|
|
|
|
_, err = run_cmd("hy", "(defmacro mabcdefghi [x] x)\n(mabcdefghi)")
|
|
|
|
assert "\n (mabcdefghi)\n ^----------^" in err
|
|
|
|
|
|
|
|
|
2017-03-31 01:10:34 +02:00
|
|
|
def test_bin_hy_stdin_except_do():
|
|
|
|
# https://github.com/hylang/hy/issues/533
|
|
|
|
|
|
|
|
output, _ = run_cmd("hy", '(try (/ 1 0) (except [ZeroDivisionError] "hello"))') # noqa
|
|
|
|
assert "hello" in output
|
|
|
|
|
|
|
|
output, _ = run_cmd("hy", '(try (/ 1 0) (except [ZeroDivisionError] "aaa" "bbb" "ccc"))') # noqa
|
|
|
|
assert "aaa" not in output
|
|
|
|
assert "bbb" not in output
|
|
|
|
assert "ccc" in output
|
|
|
|
|
|
|
|
output, _ = run_cmd("hy", '(if True (do "xxx" "yyy" "zzz"))')
|
|
|
|
assert "xxx" not in output
|
|
|
|
assert "yyy" not in output
|
|
|
|
assert "zzz" in output
|
|
|
|
|
|
|
|
|
2017-09-20 19:40:52 +02:00
|
|
|
def test_bin_hy_stdin_unlocatable_hytypeerror():
|
|
|
|
# https://github.com/hylang/hy/issues/1412
|
|
|
|
# The chief test of interest here is the returncode assertion
|
|
|
|
# inside run_cmd.
|
|
|
|
_, err = run_cmd("hy", """
|
|
|
|
(import hy.errors)
|
|
|
|
(raise (hy.errors.HyTypeError '[] (+ "A" "Z")))""")
|
|
|
|
assert "AZ" in err
|
|
|
|
|
|
|
|
|
2017-08-29 23:54:26 +02:00
|
|
|
def test_bin_hy_stdin_bad_repr():
|
|
|
|
# https://github.com/hylang/hy/issues/1389
|
|
|
|
output, err = run_cmd("hy", """
|
|
|
|
(defclass BadRepr [] (defn __repr__ [self] (/ 0)))
|
|
|
|
(BadRepr)
|
|
|
|
(+ "A" "Z")""")
|
|
|
|
assert "ZeroDivisionError" in err
|
|
|
|
assert "AZ" in output
|
|
|
|
|
|
|
|
|
2017-03-24 17:03:12 +01:00
|
|
|
def test_bin_hy_stdin_hy_repr():
|
|
|
|
output, _ = run_cmd("hy", '(+ [1] [2])')
|
|
|
|
assert "[1, 2]" in output.replace('L', '')
|
|
|
|
|
|
|
|
output, _ = run_cmd(hr(), '(+ [1] [2])')
|
|
|
|
assert "[1 2]" in output
|
|
|
|
|
|
|
|
output, _ = run_cmd(hr("--spy"), '(+ [1] [2])')
|
|
|
|
assert "[1]+[2]" in output.replace('L', '').replace(' ', '')
|
|
|
|
assert "[1 2]" in output
|
|
|
|
|
|
|
|
# --spy should work even when an exception is thrown
|
|
|
|
output, _ = run_cmd(hr("--spy"), '(+ [1] [2] (foof))')
|
|
|
|
assert "[1]+[2]" in output.replace('L', '').replace(' ', '')
|
|
|
|
|
2018-03-31 01:20:24 +02:00
|
|
|
def test_bin_hy_ignore_python_env():
|
|
|
|
os.environ.update({"PYTHONTEST": '0'})
|
|
|
|
output, _ = run_cmd("hy -c '(print (do (import os) (. os environ)))'")
|
|
|
|
assert "PYTHONTEST" in output
|
|
|
|
output, _ = run_cmd("hy -m tests.resources.bin.printenv")
|
|
|
|
assert "PYTHONTEST" in output
|
|
|
|
output, _ = run_cmd("hy tests/resources/bin/printenv.hy")
|
|
|
|
assert "PYTHONTEST" in output
|
|
|
|
|
|
|
|
output, _ = run_cmd("hy -E -c '(print (do (import os) (. os environ)))'")
|
|
|
|
assert "PYTHONTEST" not in output
|
|
|
|
os.environ.update({"PYTHONTEST": '0'})
|
|
|
|
output, _ = run_cmd("hy -E -m tests.resources.bin.printenv")
|
|
|
|
assert "PYTHONTEST" not in output
|
|
|
|
os.environ.update({"PYTHONTEST": '0'})
|
|
|
|
output, _ = run_cmd("hy -E tests/resources/bin/printenv.hy")
|
|
|
|
assert "PYTHONTEST" not in output
|
2013-04-24 15:21:42 +02:00
|
|
|
|
|
|
|
def test_bin_hy_cmd():
|
2017-03-17 17:31:54 +01:00
|
|
|
output, _ = run_cmd("hy -c \"(koan)\"")
|
|
|
|
assert "monk" in output
|
2013-04-24 15:21:42 +02:00
|
|
|
|
2017-03-17 17:31:54 +01:00
|
|
|
_, err = run_cmd("hy -c \"(koan\"", expect=1)
|
|
|
|
assert "Premature end of input" in err
|
2013-04-24 15:21:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_icmd():
|
2017-03-17 17:31:54 +01:00
|
|
|
output, _ = run_cmd("hy -i \"(koan)\"", "(ideas)")
|
2013-04-24 15:21:42 +02:00
|
|
|
assert "monk" in output
|
|
|
|
assert "figlet" in output
|
|
|
|
|
|
|
|
|
2015-02-27 11:59:00 +01:00
|
|
|
def test_bin_hy_icmd_file():
|
2017-03-17 17:31:54 +01:00
|
|
|
output, _ = run_cmd("hy -i resources/icmd_test_file.hy", "(ideas)")
|
2015-02-27 11:59:00 +01:00
|
|
|
assert "Hy!" in output
|
|
|
|
|
2018-08-22 22:21:17 +02:00
|
|
|
file_relative_path = os.path.realpath(os.path.split('tests/resources/relative_import.hy')[0])
|
|
|
|
|
|
|
|
output, _ = run_cmd("hy -i tests/resources/relative_import.hy None")
|
|
|
|
assert file_relative_path in output
|
2015-02-27 11:59:00 +01:00
|
|
|
|
2014-01-13 16:15:43 +01:00
|
|
|
def test_bin_hy_icmd_and_spy():
|
2017-03-17 17:31:54 +01:00
|
|
|
output, _ = run_cmd("hy -i \"(+ [] [])\" --spy", "(+ 1 1)")
|
2017-10-31 21:13:41 +01:00
|
|
|
assert "[] + []" in output
|
2014-01-13 16:15:43 +01:00
|
|
|
|
|
|
|
|
2013-06-29 23:56:58 +02:00
|
|
|
def test_bin_hy_missing_file():
|
2017-03-17 17:31:54 +01:00
|
|
|
_, err = run_cmd("hy foobarbaz", expect=2)
|
|
|
|
assert "No such file" in err
|
2013-06-29 23:56:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_file_with_args():
|
2017-03-17 17:31:54 +01:00
|
|
|
assert "usage" in run_cmd("hy tests/resources/argparse_ex.hy -h")[0]
|
|
|
|
assert "got c" in run_cmd("hy tests/resources/argparse_ex.hy -c bar")[0]
|
|
|
|
assert "foo" in run_cmd("hy tests/resources/argparse_ex.hy -i foo")[0]
|
|
|
|
assert "foo" in run_cmd("hy tests/resources/argparse_ex.hy -i foo -c bar")[0] # noqa
|
2013-06-29 23:56:58 +02:00
|
|
|
|
|
|
|
|
2013-07-26 07:33:14 +02:00
|
|
|
def test_bin_hyc():
|
2018-08-20 06:29:29 +02:00
|
|
|
_, err = run_cmd("hyc", expect=0)
|
|
|
|
assert err == ''
|
|
|
|
|
|
|
|
_, err = run_cmd("hyc -", expect=0)
|
|
|
|
assert err == ''
|
2017-03-17 17:31:54 +01:00
|
|
|
|
|
|
|
output, _ = run_cmd("hyc -h")
|
|
|
|
assert "usage" in output
|
|
|
|
|
2017-04-10 02:27:51 +02:00
|
|
|
path = "tests/resources/argparse_ex.hy"
|
|
|
|
output, _ = run_cmd("hyc " + path)
|
2017-03-17 17:31:54 +01:00
|
|
|
assert "Compiling" in output
|
2018-08-20 06:29:29 +02:00
|
|
|
assert os.path.exists(cache_from_source(path))
|
|
|
|
rm(cache_from_source(path))
|
2013-07-26 07:33:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hyc_missing_file():
|
2018-08-20 06:29:29 +02:00
|
|
|
_, err = run_cmd("hyc foobarbaz", expect=1)
|
2017-03-17 17:31:54 +01:00
|
|
|
assert "[Errno 2]" in err
|
2013-07-26 07:33:14 +02:00
|
|
|
|
|
|
|
|
2013-06-25 17:02:02 +02:00
|
|
|
def test_bin_hy_builtins():
|
2017-08-30 23:37:12 +02:00
|
|
|
# hy.cmdline replaces builtins.exit and builtins.quit
|
|
|
|
# for use by hy's repl.
|
2013-06-26 01:23:44 +02:00
|
|
|
import hy.cmdline # NOQA
|
2017-08-30 23:37:12 +02:00
|
|
|
# this test will fail if run from IPython because IPython deletes
|
|
|
|
# builtins.exit and builtins.quit
|
|
|
|
assert str(builtins.exit) == "Use (exit) or Ctrl-D (i.e. EOF) to exit"
|
|
|
|
assert type(builtins.exit) is hy.cmdline.HyQuitter
|
|
|
|
assert str(builtins.quit) == "Use (quit) or Ctrl-D (i.e. EOF) to exit"
|
|
|
|
assert type(builtins.quit) is hy.cmdline.HyQuitter
|
2014-03-11 19:37:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_main():
|
2017-03-17 17:31:54 +01:00
|
|
|
output, _ = run_cmd("hy tests/resources/bin/main.hy")
|
|
|
|
assert "Hello World" in output
|
2014-03-11 19:37:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_main_args():
|
2017-03-17 17:31:54 +01:00
|
|
|
output, _ = run_cmd("hy tests/resources/bin/main.hy test 123")
|
|
|
|
assert "test" in output
|
|
|
|
assert "123" in output
|
2014-03-11 19:37:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_main_exitvalue():
|
2017-03-17 17:31:54 +01:00
|
|
|
run_cmd("hy tests/resources/bin/main.hy exit1", expect=1)
|
2014-03-11 19:37:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_no_main():
|
2017-03-17 17:31:54 +01:00
|
|
|
output, _ = run_cmd("hy tests/resources/bin/nomain.hy")
|
|
|
|
assert "This Should Still Work" in output
|
2014-11-23 23:05:20 +01:00
|
|
|
|
|
|
|
|
2018-08-22 20:20:07 +02:00
|
|
|
@pytest.mark.parametrize('scenario', ["normal", "prevent_by_force",
|
|
|
|
"prevent_by_env", "prevent_by_option"])
|
|
|
|
@pytest.mark.parametrize('cmd_fmt', [['hy', '{fpath}'],
|
|
|
|
['hy', '-m', '{modname}'],
|
|
|
|
['hy', '-c', "'(import {modname})'"]])
|
2017-06-21 01:12:32 +02:00
|
|
|
def test_bin_hy_byte_compile(scenario, cmd_fmt):
|
2017-04-10 02:27:51 +02:00
|
|
|
|
|
|
|
modname = "tests.resources.bin.bytecompile"
|
|
|
|
fpath = modname.replace(".", "/") + ".hy"
|
2018-08-22 20:20:07 +02:00
|
|
|
|
|
|
|
if scenario == 'prevent_by_option':
|
|
|
|
cmd_fmt.insert(1, '-B')
|
|
|
|
|
|
|
|
cmd = ' '.join(cmd_fmt).format(**locals())
|
2017-06-21 00:30:13 +02:00
|
|
|
|
2018-08-20 06:29:29 +02:00
|
|
|
rm(cache_from_source(fpath))
|
2017-06-21 00:30:13 +02:00
|
|
|
|
2017-06-21 01:12:32 +02:00
|
|
|
if scenario == "prevent_by_force":
|
2017-06-21 00:30:13 +02:00
|
|
|
# Keep Hy from being able to byte-compile the module by
|
|
|
|
# creating a directory at the target location.
|
2018-08-20 06:29:29 +02:00
|
|
|
os.mkdir(cache_from_source(fpath))
|
2017-06-21 00:30:13 +02:00
|
|
|
|
|
|
|
# Whether or not we can byte-compile the module, we should be able
|
|
|
|
# to run it.
|
2018-08-22 20:20:07 +02:00
|
|
|
output, _ = run_cmd(cmd, dontwritebytecode=(scenario == "prevent_by_env"))
|
2017-06-21 00:30:13 +02:00
|
|
|
assert "Hello from macro" in output
|
|
|
|
assert "The macro returned: boink" in output
|
|
|
|
|
2017-06-21 01:12:32 +02:00
|
|
|
if scenario == "normal":
|
2017-06-21 00:30:13 +02:00
|
|
|
# That should've byte-compiled the module.
|
2018-08-20 06:29:29 +02:00
|
|
|
assert os.path.exists(cache_from_source(fpath))
|
2018-08-22 20:20:07 +02:00
|
|
|
elif scenario == "prevent_by_env" or scenario == "prevent_by_option":
|
2017-06-21 01:12:32 +02:00
|
|
|
# No byte-compiled version should've been created.
|
2018-08-20 06:29:29 +02:00
|
|
|
assert not os.path.exists(cache_from_source(fpath))
|
2017-06-21 00:30:13 +02:00
|
|
|
|
|
|
|
# When we run the same command again, and we've byte-compiled the
|
|
|
|
# module, the byte-compiled version should be run instead of the
|
|
|
|
# source, in which case the macro shouldn't be run.
|
|
|
|
output, _ = run_cmd(cmd)
|
2017-06-21 01:12:32 +02:00
|
|
|
assert ("Hello from macro" in output) ^ (scenario == "normal")
|
2017-06-21 00:30:13 +02:00
|
|
|
assert "The macro returned: boink" in output
|
2017-04-10 02:27:51 +02:00
|
|
|
|
|
|
|
|
2014-11-23 23:05:20 +01:00
|
|
|
def test_bin_hy_module_main():
|
2017-03-17 17:31:54 +01:00
|
|
|
output, _ = run_cmd("hy -m tests.resources.bin.main")
|
|
|
|
assert "Hello World" in output
|
2014-11-23 23:05:20 +01:00
|
|
|
|
|
|
|
|
2018-08-22 08:38:15 +02:00
|
|
|
def test_bin_hy_module_main_file():
|
|
|
|
output, _ = run_cmd("hy -m tests.resources.bin")
|
|
|
|
assert "This is a __main__.hy" in output
|
|
|
|
|
|
|
|
output, _ = run_cmd("hy -m .tests.resources.bin", expect=1)
|
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_file_main_file():
|
|
|
|
output, _ = run_cmd("hy tests/resources/bin")
|
|
|
|
assert "This is a __main__.hy" in output
|
|
|
|
|
|
|
|
|
2018-08-22 22:21:17 +02:00
|
|
|
def test_bin_hy_file_sys_path():
|
|
|
|
"""The test resource `relative_import.hy` will perform an absolute import
|
|
|
|
of a module in its directory: a directory that is not on the `sys.path` of
|
|
|
|
the script executing the module (i.e. `hy`). We want to make sure that Hy
|
|
|
|
adopts the file's location in `sys.path`, instead of the runner's current
|
|
|
|
dir (e.g. '' in `sys.path`).
|
|
|
|
"""
|
|
|
|
file_path, _ = os.path.split('tests/resources/relative_import.hy')
|
|
|
|
file_relative_path = os.path.realpath(file_path)
|
|
|
|
|
|
|
|
output, _ = run_cmd("hy tests/resources/relative_import.hy")
|
|
|
|
assert file_relative_path in output
|
|
|
|
|
|
|
|
|
2014-11-23 23:05:20 +01:00
|
|
|
def test_bin_hy_module_main_args():
|
2017-03-17 17:31:54 +01:00
|
|
|
output, _ = run_cmd("hy -m tests.resources.bin.main test 123")
|
|
|
|
assert "test" in output
|
|
|
|
assert "123" in output
|
2014-11-23 23:05:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_module_main_exitvalue():
|
2017-03-17 17:31:54 +01:00
|
|
|
run_cmd("hy -m tests.resources.bin.main exit1", expect=1)
|
2014-11-23 23:05:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_module_no_main():
|
2017-03-17 17:31:54 +01:00
|
|
|
output, _ = run_cmd("hy -m tests.resources.bin.nomain")
|
|
|
|
assert "This Should Still Work" in output
|
2018-08-22 20:20:07 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_sys_executable():
|
|
|
|
output, _ = run_cmd("hy -c '(do (import sys) (print sys.executable))'")
|
|
|
|
assert output.strip().endswith('/hy')
|
2018-09-05 05:19:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_file_no_extension():
|
|
|
|
"""Confirm that a file with no extension is processed as Hy source"""
|
|
|
|
output, _ = run_cmd("hy tests/resources/no_extension")
|
|
|
|
assert "This Should Still Work" in output
|
2018-10-23 20:41:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_bin_hy_circular_macro_require():
|
|
|
|
"""Confirm that macros can require themselves during expansion and when
|
|
|
|
run from the command line."""
|
|
|
|
|
|
|
|
# First, with no bytecode
|
|
|
|
test_file = "tests/resources/bin/circular_macro_require.hy"
|
|
|
|
rm(cache_from_source(test_file))
|
|
|
|
assert not os.path.exists(cache_from_source(test_file))
|
|
|
|
output, _ = run_cmd("hy {}".format(test_file))
|
|
|
|
assert "42" == output.strip()
|
|
|
|
|
|
|
|
# Now, with bytecode
|
|
|
|
assert os.path.exists(cache_from_source(test_file))
|
|
|
|
output, _ = run_cmd("hy {}".format(test_file))
|
|
|
|
assert "42" == output.strip()
|
|
|
|
|
|
|
|
def test_bin_hy_macro_require():
|
|
|
|
"""Confirm that a `require` will load macros into the non-module namespace
|
|
|
|
(i.e. `exec(code, locals)`) used by `runpy.run_path`.
|
|
|
|
In other words, this confirms that the AST generated for a `require` will
|
|
|
|
load macros into the unnamed namespace its run in."""
|
|
|
|
|
|
|
|
# First, with no bytecode
|
|
|
|
test_file = "tests/resources/bin/require_and_eval.hy"
|
|
|
|
rm(cache_from_source(test_file))
|
|
|
|
assert not os.path.exists(cache_from_source(test_file))
|
|
|
|
output, _ = run_cmd("hy {}".format(test_file))
|
|
|
|
assert "abc" == output.strip()
|
|
|
|
|
|
|
|
# Now, with bytecode
|
|
|
|
assert os.path.exists(cache_from_source(test_file))
|
|
|
|
output, _ = run_cmd("hy {}".format(test_file))
|
|
|
|
assert "abc" == output.strip()
|