Ejemplo n.º 1
0
    def test_error_compilation(self):
        ensure_dir(self.src_dir)
        with open(join(self.src_dir, 'proper.c'), 'w') as w:
            w.write('''
            #include "erl_nif.h"

            static ERL_NIF_TERM hello(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
            {
                return enif_make_string(env, "Hello world!", ERL_NIF_LATIN1)  // error here, forget terminator
            }
            
            static ErlNifFunc nif_funcs[] =
            {
                {"hello", 0, hello}
            };
            
            ERL_NIF_INIT(niftest,nif_funcs,NULL,NULL,NULL,NULL)
            ''')
        config = EnotConfig({'name': 'proper'})
        package = Package(self.test_dir, config, None)
        compiler = CCompiler(package)
        self.assertEqual(False, compiler.compile())
        self.assertEqual(
            False, os.path.exists(join(self.output_dir,
                                       self.test_name + '.so')))
Ejemplo n.º 2
0
def read_project(path: str, url=None) -> ConfigFile:
    files = get_files(path)
    if 'enot_config.json' in files:
        return EnotConfig.from_path(path, url=url)
    elif 'erlang.mk' in files:
        return ErlangMkConfig(path, url=url)
    elif 'rebar.config' in files:
        return RebarConfig(path, url=url)
    raise ValueError("Unknown build system in project " + path)
Ejemplo n.º 3
0
 def test_create(self):
     enot.__main__.create(self.test_dir, {'<name>': 'test_project'})
     project_dir = join(self.test_dir, 'test_project')
     src_dir = join(project_dir, 'src')
     self.assertEqual(
         True, os.path.exists(project_dir))  # project dir was created
     self.assertEqual(True, os.path.exists(src_dir))  # src dir was created
     config = EnotConfig.from_path(project_dir)
     self.assertEqual({}, config.deps)  # no deps
     self.assertEqual('test_project',
                      config.name)  # name was set and parsed properly
     self.assertEqual(
         '0.0.1', config.conf_vsn)  # version was set and parsed properly
Ejemplo n.º 4
0
 def test_error_compilation(self, mock_compiler):
     mock_compiler.return_value = True
     ensure_dir(self.src_dir)
     with open(join(self.src_dir, 'improper.erl'), 'w') as w:
         w.write('''
         -module(proper).
         -export([test/0]).
         test() -> syntax error here.
         do_smth(A) -> A + 1.
         ''')
     config = EnotConfig({'name': 'test'})
     package = Package(self.test_dir, config, None)
     compiler = EnotCompiler(package)
     self.assertEqual(False, compiler.compile())
     self.assertEqual(False,
                      os.path.exists(join(self.ebin_dir, 'improper.beam')))
Ejemplo n.º 5
0
 def test_defines_setting(self, mock_compiler):
     mock_compiler.return_value = True
     ensure_dir(self.src_dir)
     with open(join(self.src_dir, 'proper.erl'), 'w') as w:
         w.write('''
         -module(proper).
         -export([test/0]).
         test() -> io:format("~p~n", [?TEST_DEFINE]).
         ''')
     config = EnotConfig({'name': 'test'})
     package = Package(self.test_dir, config, None)
     compiler = EnotCompiler(package, 'TEST_DEFINE=test')
     self.assertEqual(True, compiler.compile())
     self.assertEqual(True,
                      os.path.exists(join(self.ebin_dir, 'proper.beam')))
     p = subprocess.Popen([
         'erl', '-pa', 'ebin', '-run', 'proper', 'test', '-run', 'init',
         'stop', '-noshell'
     ],
                          stdout=subprocess.PIPE,
                          cwd=self.ebin_dir)
     self.assertEqual(0, p.wait(5000))
     self.assertEqual('test\n', p.stdout.read().decode('utf8'))