# Path: luna/main.py
# def create_entry_point():
#     def entry_point(argv):
#         try:
#             filename = argv[1]
#         except IndexError:
#             print "You must supply a filename"
#             print (argv)
#             return 1
# 
#         file_, ext = argv[1].rsplit('.', 1)
#         """
#         if ext not in ('l', 'lc'):
#             print("Unsupported extension %s" %ext)
#             return 1
#         """
# 
#         if _needs_compilation(file_+'.lc', filename):
#             ret = os.system('luajit -b %s %s' %(filename, filename+'c'))
#             if ret:
#                 print("Error compiling %s using luajit" % filename)
#                 return 1
# 
#         if not ext.endswith('c'):
#             filename += 'c'
# 
#         flags, protos = Parser(filename).parse()
#         interpreter = Interpreter(flags, protos)
#         interpreter.run()
# 
#         return 0
#     return entry_point
# 
# Path: luna/tests/helpers.py
# def luabytecode_file(src):
#     f = test_file(src, suffix='.l')
#     compile_file(f)
#     return open(f.name+'c')
# 
# def test_file(src='', suffix=''):
#     f = tempfile.NamedTemporaryFile(suffix=suffix)
#     f.write(src)
#     f.flush()
#     return f


import os
from luna.main import create_entry_point
from luna.tests.helpers import luabytecode_file, test_file



ENTRY_POINT = create_entry_point()


class TestMain(object):
    def test_with_bytecode_file(self):
        f = luabytecode_file("x = 1")
        assert ENTRY_POINT(['', f.name]) == 0

    def test_with_lua_file(self):

# Path: luna/main.py
# def create_entry_point():
#     def entry_point(argv):
#         try:
#             filename = argv[1]
#         except IndexError:
#             print "You must supply a filename"
#             print (argv)
#             return 1
# 
#         file_, ext = argv[1].rsplit('.', 1)
#         """
#         if ext not in ('l', 'lc'):
#             print("Unsupported extension %s" %ext)
#             return 1
#         """
# 
#         if _needs_compilation(file_+'.lc', filename):
#             ret = os.system('luajit -b %s %s' %(filename, filename+'c'))
#             if ret:
#                 print("Error compiling %s using luajit" % filename)
#                 return 1
# 
#         if not ext.endswith('c'):
#             filename += 'c'
# 
#         flags, protos = Parser(filename).parse()
#         interpreter = Interpreter(flags, protos)
#         interpreter.run()
# 
#         return 0
#     return entry_point
# 
# Path: luna/tests/helpers.py
# def luabytecode_file(src):
#     f = test_file(src, suffix='.l')
#     compile_file(f)
#     return open(f.name+'c')
# 
# def test_file(src='', suffix=''):
#     f = tempfile.NamedTemporaryFile(suffix=suffix)
#     f.write(src)
#     f.flush()
#     return f


# Path: luna/tests/test_main.py
import os
from luna.main import create_entry_point
from luna.tests.helpers import luabytecode_file, test_file




ENTRY_POINT = create_entry_point()


class TestMain(object):
    def test_with_bytecode_file(self):
        f = luabytecode_file("x = 1")
        assert ENTRY_POINT(['', f.name]) == 0

    def test_with_lua_file(self):

        f = test_file("x = 1", suffix=".l")