Run file using hy -i

Add test for -i using file
This commit is contained in:
Nathan Woodrow 2015-02-27 20:59:00 +10:00
parent a3775316e7
commit a3ad4df6a1
3 changed files with 17 additions and 1 deletions

View File

@ -31,6 +31,7 @@ import argparse
import code import code
import ast import ast
import sys import sys
import os
import astor.codegen import astor.codegen
@ -244,7 +245,13 @@ def run_repl(hr=None, spy=False):
def run_icommand(source, spy=False): def run_icommand(source, spy=False):
hr = HyREPL(spy) hr = HyREPL(spy)
hr.runsource(source, filename='<input>', symbol='single') if os.path.exists(source):
with open(source, "r") as f:
source = f.read()
filename = source
else:
filename = '<input>'
hr.runsource(source, filename=filename, symbol='single')
return run_repl(hr) return run_repl(hr)

View File

@ -79,6 +79,14 @@ def test_bin_hy_icmd():
assert "figlet" in output assert "figlet" in output
def test_bin_hy_icmd_file():
ret = run_cmd("hy -i test_files/icmd_test_file.hy", "(ideas)")
assert ret[0] == 0
output = ret[1]
assert "Hy!" in output
def test_bin_hy_icmd_and_spy(): def test_bin_hy_icmd_and_spy():
ret = run_cmd("hy -i \"(+ [] [])\" --spy", "(+ 1 1)") ret = run_cmd("hy -i \"(+ [] [])\" --spy", "(+ 1 1)")
assert ret[0] == 0 assert ret[0] == 0

View File

@ -0,0 +1 @@
(print "Hy!")