コード例 #1
0
 def add_package(self, package: Package, rewrite=False) -> bool:
     full_dir = join(self.path, self.get_package_path(package, True))
     ensure_dir(full_dir)
     info('add ' + package.fullname)
     path = package.path
     LocalCache.__copy_data(rewrite, full_dir, path, 'ebin')
     LocalCache.__copy_include(rewrite, full_dir, path)
     if package.config.with_source:
         LocalCache.__copy_data(rewrite, full_dir, path, 'src')
     if package.config.with_source and package.has_nifs:
         LocalCache.__copy_data(rewrite, full_dir, path, 'c_src')
     if os.path.exists(join(path, 'priv')):
         LocalCache.__copy_data(rewrite, full_dir, path, 'priv')
     enot_package = join(path, package.name + '.ep')
     if not os.path.isfile(enot_package):
         debug('generate missing package')
         package.generate_package()
     copy_file(join(path, 'enot_config.json'),
               join(full_dir, 'enot_config.json'))
     copy_file(enot_package, join(full_dir, package.name + '.ep'))
     resource = resource_filename(Requirement.parse(enot.APPNAME),
                                  'enot/resources/EmptyMakefile')
     debug('copy ' + resource + ' to ' + join(full_dir, 'Makefile'))
     copy_file(resource, join(full_dir, 'Makefile'))
     package.path = full_dir  # update package's dir to point to cache
     return True
コード例 #2
0
ファイル: test_tests.py プロジェクト: huangdaiyi/enot
    def test_unit_test_with_deps(self):
        app_dir = join(self.test_dir, 'test_app')
        dep_dir = join(app_dir, 'deps')
        set_deps(
            app_dir,  # root project depends on dep1
            [{
                'name': 'dep1',
                'url': 'https://github.com/comtihon/dep1',
                'tag': '1.0.0'
            }])
        create(dep_dir, {'<name>': 'dep1'})  # dep1 has dep_api:test/0
        with open(join(dep_dir, 'dep1', 'src', 'dep_api.erl'), 'w') as test:
            test.write('''
            -module(dep_api).
            -export([test/0]).
                          
            test() ->
                true.''')
        app_test_dir = join(app_dir, 'test')
        ensure_dir(app_test_dir)
        # dep_api:test/0 is used in unit test of root project
        with open(join(app_test_dir, 'common.erl'), 'w') as test:
            test.write('''
            -module(common).
            -include_lib("eunit/include/eunit.hrl").

            run_test() ->
               ?assertEqual(true, dep_api:test()).''')
        # Compile dep. I only do it in test, as in real life deps will be compiled and linked before running unit.
        dep = Package.from_path(join(dep_dir, 'dep1'))
        self.assertEqual(True, EnotCompiler(dep).compile())
        package = Package.from_path(app_dir)
        compiler = EnotCompiler(package)
        self.assertEqual(True, compiler.unit())
コード例 #3
0
 def fetch_package(self, dep: Package):
     temp_path = join(self.temp_dir, dep.name)
     info('fetch ' + temp_path)
     remove_dir(temp_path)
     vsn, need_lock = self.__get_vsn(dep)
     hash_str = LocalCache.fetch(dep.url, vsn, temp_path)
     dep.update_from_cache(temp_path)
     if need_lock:
         self.set_lock(dep, hash_str)
コード例 #4
0
ファイル: cache_man.py プロジェクト: huangdaiyi/enot
 def populate(self, dep: Package):
     if dep.url is not None and self.local_cache.exists(dep):  # local cache has this package
         path = join(self.local_cache.path, self.local_cache.get_package_path(dep))
         dep.update_from_cache(path)
         return
     for cache in self.remote_caches.values():
         if self.exists_remote(cache, dep):
             return
     self.local_cache.fetch_package(dep)
コード例 #5
0
 def __compare_and_select(self, dep: Package) -> list:
     pkg_vsn = self.packages[dep.name].git_vsn
     additional_deps = []
     if dep.git_vsn != pkg_vsn:  # It is not the same dep
         try:  # try to compare versions
             additional_deps = self.__compare_vsns(dep, pkg_vsn)
         except ValueError:  # not m.m.b version (may be tag vs branch). Just replace.
             warning('Skip ' + dep.name + ' (' + dep.git_vsn + '). Use ' +
                     pkg_vsn)
     dep.update_from_duplicate(self.packages[dep.name])
     return additional_deps
コード例 #6
0
ファイル: test_deps.py プロジェクト: huangdaiyi/enot
def mock_fetch_package(dep: Package):
    test_dir = test.get_test_dir('deps_tests')
    tmp_path = join(os.getcwd(), test_dir, 'tmp')
    if dep.name == 'update_dep' and dep.git_vsn == '1.2.0':
        set_deps(join(tmp_path, dep.name), [{
            'name': 'dep3',
            'url': 'https://github.com/comtihon/dep3',
            'tag': '1.0.0'
        }])
    if dep.name == 'remove_dep' and dep.git_vsn == '1.2.0':
        set_deps(join(tmp_path, dep.name), [])
    dep.update_from_cache(join(tmp_path, dep.name))
コード例 #7
0
ファイル: test_local_cache.py プロジェクト: comtihon/enot
 def test_link_dep(self, mock_conf, _):
     mock_conf.return_value = self.conf_file
     pack_path = join(self.test_dir, 'test_app')
     set_deps(pack_path, [{
         'name': 'dep',
         'url': 'https://github.com/comtihon/dep',
         'tag': '1.0.0'
     }])
     create(self.tmp_dir, {'<name>': 'dep'})
     dep_tmp_path = join(self.tmp_dir, 'dep')
     set_git_url(dep_tmp_path, 'http://github/comtihon/dep')
     set_git_tag(dep_tmp_path, '1.0.0')
     builder = Builder.init_from_path(pack_path)
     builder.populate()
     self.assertEqual(True, builder.build())
     # dep was added to cache
     self.assertEqual(
         True,
         builder.system_config.cache.exists_local(
             Package.from_path(dep_tmp_path)))
     dep_link_ebin = join(pack_path, 'deps', 'dep', 'ebin')
     self.assertEqual(True, os.path.islink(dep_link_ebin))
     erl = Static.get_erlang_version()
     real_dep = join(self.cache_dir, 'comtihon', 'dep', '1.0.0', erl,
                     'ebin')
     self.assertEqual(real_dep, os.readlink(dep_link_ebin))
コード例 #8
0
ファイル: test_applications.py プロジェクト: huangdaiyi/enot
 def test_app_creating_duplucates(self):
     ensure_dir(self.src_dir)
     with open(join(self.src_dir, 'test.app.src'), 'w') as w:
         w.write(get_application(['test_dep1', 'test_dep2']))
     with open(join(self.test_dir, 'enot_config.json'), 'w') as w:
         w.write(get_package_conf([{'name': 'test_dep1',
                                    'url': "http://github/comtihon/test_dep1",
                                    'tag': "test_vsn"},
                                   {'name': 'test_dep3',
                                    'url': "http://github/comtihon/test_dep3",
                                    'tag': "test_vsn"}]))
     package = Package.from_path(self.test_dir)
     package_deps = [dep.name for dep in package.deps]
     self.assertEqual(2, len(package_deps))
     self.assertEqual(True, 'test_dep1' in package_deps)
     self.assertEqual(True, 'test_dep3' in package_deps)
     applications = package.app_config.applications
     self.assertEqual(2, len(package_deps))
     self.assertEqual(True, 'test_dep1' in applications)
     self.assertEqual(True, 'test_dep2' in applications)
     apps = package.apps
     self.assertEqual(3, len(apps))  # test_dep1, test_dep2, test_dep3
     self.assertEqual(True, 'test_dep1' in apps)
     self.assertEqual(True, 'test_dep2' in apps)
     self.assertEqual(True, 'test_dep3' in apps)
コード例 #9
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')))
コード例 #10
0
ファイル: test_tests.py プロジェクト: huangdaiyi/enot
    def test_collecting_units_recurse(self):
        test_dir = join(self.test_dir, 'test_app', 'test')
        ensure_dir(test_dir)
        with open(join(test_dir, 'level1.erl'), 'w') as test:
            test.write('''
            -module(level1).
            -include_lib("eunit/include/eunit.hrl").

           run_test() ->
               ?_assert(true).''')
        subdir = join(test_dir, 'sub')
        ensure_dir(subdir)
        with open(join(subdir, 'level2.erl'), 'w') as test:
            test.write('''
            -module(level2).
            -include_lib("eunit/include/eunit.hrl").

           run_test() ->
               ?_assert(true).''')
        package = Package.from_path(join(self.test_dir, 'test_app'))
        compiler = EnotCompiler(package)
        files = compiler._EnotCompiler__get_all_files(compiler.test_path,
                                                      'erl')
        self.assertEqual({
            'level1': test_dir,
            'level2': join(test_dir, 'sub')
        }, files)
コード例 #11
0
 def test_update_from_cache(self):
     pack = Package.from_dep('my_dep', Dep('http://github/my_namespace/test_app', 'master', tag='1.0.0'))
     create(self.test_dir, {'<name>': 'my_dep'})
     pack.update_from_cache(join(self.test_dir, 'my_dep'))
     self.assertEqual('my_dep', pack.name)
     self.assertEqual('0.0.1', pack.vsn)
     self.assertEqual('1.0.0', pack.git_tag)
     self.assertEqual('http://github/my_namespace/test_app', pack.url)
     self.assertEqual([], pack.deps)
コード例 #12
0
ファイル: test_applications.py プロジェクト: huangdaiyi/enot
 def test_app_creating_new_app(self):
     ensure_dir(self.src_dir)
     with open(join(self.src_dir, 'test.app.src'), 'w') as w:
         w.write(get_application(['mnesia']))
     with open(join(self.test_dir, 'enot_config.json'), 'w') as w:
         w.write(get_package_conf([]))
     package = Package.from_path(self.test_dir)
     self.assertEqual([], package.deps)  # no package deps
     self.assertEqual(['mnesia'], package.apps)  # mnesia in applications to be inserted in app (from apps)
     self.assertEqual(['mnesia'], package.app_config.applications)  # mnesia in package apps (from app.src conf)
コード例 #13
0
 def test_init_from_package(self, mock_conf):
     mock_conf.return_value = self.conf_file
     create(self.test_dir, {'<name>': 'my_dep'})
     pack_path = join(self.test_dir, 'my_dep')
     builder = Builder.init_from_path(pack_path)
     self.assertEqual(True, builder.build())
     builder.package()
     pack = Package.from_package(join(pack_path, 'my_dep.ep'))
     self.assertEqual('my_dep', pack.name)
     self.assertEqual('0.0.1', pack.vsn)
     self.assertEqual([], pack.deps)
コード例 #14
0
ファイル: cache.py プロジェクト: huangdaiyi/enot
 def unpackage(
     self, package: Package
 ):  # TODO move me to package? use current dir + <something> instead of temp
     unpack_dir = join(self.temp_dir, package.fullname)
     enotpack = join(package.path, package.name + '.ep')
     ensure_empty(unpack_dir)
     info('Extract ' + enotpack)
     with tarfile.open(enotpack) as pack:
         pack.extractall(unpack_dir)
     package.path = unpack_dir  # update path pointer
     copy_file(enotpack, join(unpack_dir, package.name + '.ep'))
コード例 #15
0
ファイル: test_local_cache.py プロジェクト: comtihon/enot
 def test_package_exists(self, mock_conf):
     mock_conf.return_value = self.conf_file
     pack_path = join(self.test_dir, 'test_app')
     set_git_url(pack_path, 'http://github/comtihon/test_app')
     set_git_tag(pack_path, '1.0.0')
     pack = Package.from_path(pack_path)
     builder = Builder.init_from_path(pack_path)
     self.assertEqual(False, builder.system_config.cache.exists_local(pack))
     self.assertEqual(True, builder.build())
     builder.system_config.cache.add_package_local(pack)
     self.assertEqual(True, builder.system_config.cache.exists_local(pack))
コード例 #16
0
 def test_init_from_path(self):
     create(self.test_dir, {'<name>': 'test_app'})
     set_git_url(join(self.test_dir, 'test_app'), 'http://github/my_namespace/my_project')
     set_git_tag(join(self.test_dir, 'test_app'), '1.0.0')
     pack = Package.from_path(join(self.test_dir, 'test_app'))
     self.assertEqual('test_app', pack.name)
     self.assertEqual('0.0.1', pack.vsn)
     self.assertEqual('http://github/my_namespace/my_project', pack.url)
     self.assertEqual('1.0.0', pack.git_tag)
     self.assertEqual('master', pack.git_branch)
     self.assertEqual([], pack.deps)
コード例 #17
0
ファイル: test_applications.py プロジェクト: huangdaiyi/enot
 def test_app_creating_new_dep(self):
     ensure_dir(self.src_dir)
     with open(join(self.src_dir, 'test.app.src'), 'w') as w:
         w.write(get_application([]))
     with open(join(self.test_dir, 'enot_config.json'), 'w') as w:
         w.write(get_package_conf([{'name': 'test_dep',
                                    'url': "http://github/comtihon/test_dep",
                                    'tag': "test_vsn"}]))
     package = Package.from_path(self.test_dir)
     # test_dep in package deps (from package conf)
     self.assertEqual(['test_dep'], [dep.name for dep in package.deps])
     self.assertEqual(['test_dep'], package.apps)  # test_dep in applications to be inserted in app (from deps)
     self.assertEqual([], package.app_config.applications)  # no applications in app.src
コード例 #18
0
ファイル: test_tests.py プロジェクト: huangdaiyi/enot
    def test_unit_test_fail(self):
        test_dir = join(self.test_dir, 'test_app', 'test')
        ensure_dir(test_dir)
        with open(join(test_dir, 'simple.erl'), 'w') as test:
            test.write('''
            -module(simple).
            -include_lib("eunit/include/eunit.hrl").

           run_test() ->
               ?assertEqual(true, false).''')
        package = Package.from_path(join(self.test_dir, 'test_app'))
        compiler = EnotCompiler(package)
        self.assertEqual(False, compiler.unit())
コード例 #19
0
 def test_disable_prebuild(self, mock_conf):
     mock_conf.return_value = self.conf_file
     create(self.tmp_dir, {'<name>': 'project'})
     project_dir = join(self.tmp_dir, 'project')
     test_file_path = join(project_dir, 'test_file')
     set_prebuild(project_dir, [{
         'shell': 'echo "test" > ' + test_file_path
     }],
                  disable_prebuild=True)
     self.assertEqual(False, os.path.exists(test_file_path))
     package = Package.from_path(project_dir)
     compiler = EnotCompiler(package)
     self.assertEqual(True, compiler.compile())
     self.assertEqual(False, os.path.exists(test_file_path))
コード例 #20
0
 def test_build_parse_transform_first(self, mock_conf):
     mock_conf.return_value = self.conf_file
     create(self.tmp_dir, {'<name>': 'project'})
     project_dir = join(self.tmp_dir, 'project')
     project_src = join(project_dir, 'src')
     with open(join(project_src, 'p_trans.erl'), 'w') as w:
         w.write('''
         -module(p_trans).
         -export([parse_transform/2]).
         
         -record(support, {add_fun = true, 
                           export = true}).
         
         parse_transform(AST, _Options) ->
           do_parse([], AST, #support{}).
           
         do_parse(AST, [], _) -> lists:reverse(AST);
         do_parse(AST, [F = {function, N, _, _, _} | Others], Support = #support{add_fun = true}) ->
           M = N - 1,
           AddedFun =
             {function, M, sum, 2,
               [{clause, M,
                 [{var, M, 'A'}, {var, M, 'B'}],
                 [],
                 [{op, M, '+', {var, M, 'A'}, {var, M, 'B'}}]}]},
           TurnedOff = Support#support{add_fun = false},
           do_parse([F | [AddedFun | AST]], Others, TurnedOff);
         do_parse(AST, [E = {attribute, N, export, _} | Others], Support = #support{export = true}) ->
           Export = [E | AST],
           Exported = {attribute, N + 1, export, [{sum, 2}]},
           TurnedOff = Support#support{export = false},
           do_parse([Exported | Export], Others, TurnedOff);
         do_parse(AST, [H | Others], Support) ->
           do_parse([H | AST], Others, Support).
         ''')
     with open(join(project_src, 'a_module.erl'), 'w') as w:
         w.write('''
         -module(a_module).
         
         -compile([{parse_transform, p_trans}]).
         
         -export([hello/0]).
         
         hello() -> hello.
         ''')
     package = Package.from_path(project_dir)
     compiler = EnotCompiler(package)
     self.assertEqual(True, compiler.compile())
     self.assertEqual(True, os.path.exists(join(project_dir, 'ebin')))
コード例 #21
0
 def test_update_from_package(self, mock_conf):
     mock_conf.return_value = self.conf_file
     create(self.test_dir, {'<name>': 'my_dep'})
     pack_path = join(self.test_dir, 'my_dep')
     builder = Builder.init_from_path(pack_path)
     self.assertEqual(True, builder.build())
     builder.package()
     pack = Package.from_dep('my_dep', Dep('http://github/my_namespace/test_app', 'master', tag='1.0.0'))
     pack.update_from_package(join(pack_path, 'my_dep.ep'))
     self.assertEqual('my_dep', pack.name)
     self.assertEqual('0.0.1', pack.vsn)
     self.assertEqual('1.0.0', pack.git_tag)
     self.assertEqual('master', pack.git_branch)
     self.assertEqual('http://github/my_namespace/test_app', pack.url)
     self.assertEqual([], pack.deps)
コード例 #22
0
    def test_proper_project_compilation(self):
        create(self.test_dir, {'<name>': 'proper'})
        project_dir = join(self.test_dir, 'proper')
        ensure_dir(join(project_dir, 'c_src'))
        with open(join(project_dir, 'c_src/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);
            }
            
            static ErlNifFunc nif_funcs[] =
            {
                {"hello", 0, hello}
            };
            
            ERL_NIF_INIT(proper,nif_funcs,NULL,NULL,NULL,NULL)
            ''')
        with open(join(project_dir, 'src/proper.erl'), 'w') as w:
            w.write('''
            -module(proper).

            -export([init/0, hello/0]).
            
            init() ->
                  erlang:load_nif("priv/proper", 0),
                  io:format("~p~n", [hello()]).
            
            hello() ->
                  "NIF library not loaded".
            ''')
        package = Package.from_path(project_dir)
        compiler = EnotCompiler(package)
        self.assertEqual(True, compiler.compile())
        self.assertEqual(True,
                         os.path.exists(join(project_dir, 'priv/proper.so')))
        self.assertEqual(True,
                         os.path.exists(join(project_dir, 'ebin/proper.beam')))
        p = subprocess.Popen([
            'erl', '-pa', 'ebin', '-run', 'proper', 'init', '-run', 'init',
            'stop', '-noshell'
        ],
                             stdout=PIPE,
                             cwd=project_dir)
        self.assertEqual(0, p.wait(5000))
        self.assertEqual('"Hello world!"\n', p.stdout.read().decode('utf8'))
コード例 #23
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')))
コード例 #24
0
 def uninstall(self, fullname: str) -> bool:
     packages = self.__search_by_name(fullname)
     if not packages:
         warning(fullname + ' not installed')
         return False
     for package in packages:
         vsn = package['vsn']
         erlang_vsns = self.local_cache.get_erl_versions(fullname, package['vsn'])
         [latest_erl] = erlang_vsns[-1:]
         pack = Package.from_path(join(self.local_cache.path, fullname, vsn, latest_erl))
         if not pack.uninstall():
             warning('Can\'t uninstall package ' + fullname + ': ' + vsn)
             return False
         info(fullname + ': ' + vsn + ' uninstalled')
         self.__remove_from_installed(fullname, vsn)
     return True
コード例 #25
0
ファイル: test_applications.py プロジェクト: huangdaiyi/enot
 def test_app_creating_new_app_and_dep(self):
     ensure_dir(self.src_dir)
     with open(join(self.src_dir, 'test.app.src'), 'w') as w:
         w.write(get_application(['mnesia']))
     with open(join(self.test_dir, 'enot_config.json'), 'w') as w:
         w.write(get_package_conf([{'name': 'test_dep',
                                    'url': "http://github/comtihon/test_dep",
                                    'tag': "test_vsn"}]))
     package = Package.from_path(self.test_dir)
     # test_dep in package deps (from package conf)
     self.assertEqual(['test_dep'], [dep.name for dep in package.deps])
     self.assertEqual(['mnesia'], package.app_config.applications)  # mnesia in package apps (from app.src conf)
     apps = package.apps
     self.assertEqual(2, len(apps))  # mnesia and test_dep will go to app file
     self.assertEqual(True, 'test_dep' in apps)
     self.assertEqual(True, 'mnesia' in apps)
コード例 #26
0
ファイル: test_tests.py プロジェクト: huangdaiyi/enot
 def test_common_test_fail(self):
     test_dir = join(self.test_dir, 'test_app', 'test')
     ensure_dir(test_dir)
     with open(join(test_dir, 'common_SUITE.erl'), 'w') as test:
         test.write('''
         -module(common_SUITE).
         -include_lib("common_test/include/ct.hrl").
         -export([all/0]).
         -export([test/1]).
          
         all() -> [test].
          
         test(_Config) ->
             1 = 2.''')
     package = Package.from_path(join(self.test_dir, 'test_app'))
     compiler = EnotCompiler(package)
     self.assertEqual(False, compiler.common('test/logs'))
コード例 #27
0
ファイル: test_local_cache.py プロジェクト: huangdaiyi/enot
 def test_add_from_package(self, mock_conf):
     mock_conf.return_value = self.conf_file
     pack_path = join(self.test_dir, 'test_app')
     set_git_url(pack_path, 'http://github/comtihon/test_app')
     set_git_tag(pack_path, '1.0.0')
     builder = Builder.init_from_path(pack_path)
     self.assertEqual(True, builder.build())
     builder.package()
     new_package_path = join(self.test_dir, 'test_app.ep')
     # remove source project, test should work only with enot package
     copy_file(join(pack_path, 'test_app.ep'), new_package_path)
     remove_dir(pack_path)
     package = Package.from_package(new_package_path)
     self.assertEqual(False, builder.system_config.cache.exists_local(package))
     # local cache is used here to determine tmp dir
     local_cache = builder.system_config.cache.local_cache
     builder.system_config.cache.add_fetched(local_cache, package)
     self.assertEqual(True, builder.system_config.cache.exists_local(package))
コード例 #28
0
 def test_write_app_file_from_src(self):
     ensure_dir(self.src_dir)
     with open(join(self.src_dir, 'proper.erl'), 'w') as w:
         w.write('''
         -module(proper).
         -export([test/0]).
         test() -> do_smth(1).
         do_smth(A) -> A + 1.
         ''')
     with open(join(self.src_dir, 'proper.app.src'), 'w') as w:
         w.write('''
         {application, proper,
           [
             {description, ""},
             {vsn, "{{ app.vsn }}"},
             {registered, []},
             {modules, {{ modules }}},
             {applications, {{ app.std_apps + app.apps }}},
             {mod, {proper_app, []}},
             {env, []}
           ]}.
         ''')
     with open(join(self.test_dir, 'enot_config.json'), 'w') as w:
         w.write('''{
         \"name\":\"proper\",
         \"app_vsn\":\"1.0.0\",
         \"deps\": [{\"name\": \"test_dep\",
                     \"url\": \"http://github/comtihon/test_dep\",
                     \"tag\": \"test_vsn\"}]
         }''')
     package = Package.from_path(self.test_dir)
     compiler = EnotCompiler(package)
     self.assertEqual(True, compiler.compile())
     self.assertEqual(True, os.path.exists(self.ebin_dir))
     ls = listdir(self.ebin_dir)
     self.assertEqual(True, 'proper.beam' in ls)
     self.assertEqual(True, 'proper.app' in ls)
     self.assertEqual(2, len(ls))
     (name, vsn, deps, _) = parse_app_config(self.ebin_dir, '.app')
     self.assertEqual('proper', name)
     self.assertEqual('1.0.0', vsn)
     self.assertEqual(deps, ['kernel', 'stdlib', 'test_dep'])
コード例 #29
0
    def test_error_project_compilation(self):
        create(self.test_dir, {'<name>': 'proper'})
        project_dir = join(self.test_dir, 'proper')
        ensure_dir(join(project_dir, 'c_src'))
        with open(join(project_dir, 'c_src/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
            }
            
            static ErlNifFunc nif_funcs[] =
            {
                {"hello", 0, hello}
            };
            
            ERL_NIF_INIT(proper,nif_funcs,NULL,NULL,NULL,NULL)
            ''')
        with open(join(project_dir, 'src/proper.erl'), 'w') as w:
            w.write('''
            -module(proper).

            -export([init/0, hello/0]).
            
            init() ->
                  erlang:load_nif("priv/proper", 0),
                  io:format("~p~n", [hello()]).
            
            hello() ->
                  "NIF library not loaded".
            ''')
        package = Package.from_path(project_dir)
        compiler = EnotCompiler(package)
        self.assertEqual(False, compiler.compile())
        self.assertEqual(False,
                         os.path.exists(join(project_dir, 'priv/proper.so')))
        self.assertEqual(False,
                         os.path.exists(join(project_dir, 'ebin/proper.beam')))
コード例 #30
0
ファイル: test_tests.py プロジェクト: huangdaiyi/enot
    def test_collecting_units(self):
        test_dir = join(self.test_dir, 'test_app', 'test')
        ensure_dir(test_dir)
        with open(join(test_dir, 'first.erl'), 'w') as test:
            test.write('''
            -module(first).
            -include_lib("eunit/include/eunit.hrl").

           run_test() ->
               ?_assert(true).''')
        with open(join(test_dir, 'second.erl'), 'w') as test:
            test.write('''
            -module(second).
            -include_lib("eunit/include/eunit.hrl").

           run_test() ->
               ?_assert(true).''')
        package = Package.from_path(join(self.test_dir, 'test_app'))
        compiler = EnotCompiler(package)
        files = compiler._EnotCompiler__get_all_files(compiler.test_path,
                                                      'erl')
        self.assertEqual({'first': test_dir, 'second': test_dir}, files)