diff --git a/hy/cmdline.py b/hy/cmdline.py
index f4cb94e..dce1a07 100644
--- a/hy/cmdline.py
+++ b/hy/cmdline.py
@@ -31,6 +31,7 @@ import argparse
import code
import ast
import sys
+import os
import astor.codegen
@@ -244,7 +245,13 @@ def run_repl(hr=None, spy=False):
def run_icommand(source, spy=False):
hr = HyREPL(spy)
- hr.runsource(source, filename='', symbol='single')
+ if os.path.exists(source):
+ with open(source, "r") as f:
+ source = f.read()
+ filename = source
+ else:
+ filename = ''
+ hr.runsource(source, filename=filename, symbol='single')
return run_repl(hr)
diff --git a/tests/test_bin.py b/tests/test_bin.py
index 6436fa5..d78892d 100644
--- a/tests/test_bin.py
+++ b/tests/test_bin.py
@@ -79,6 +79,14 @@ def test_bin_hy_icmd():
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():
ret = run_cmd("hy -i \"(+ [] [])\" --spy", "(+ 1 1)")
assert ret[0] == 0
diff --git a/tests/test_files/icmd_test_file.hy b/tests/test_files/icmd_test_file.hy
new file mode 100644
index 0000000..bb3f4e8
--- /dev/null
+++ b/tests/test_files/icmd_test_file.hy
@@ -0,0 +1 @@
+(print "Hy!")