示例#1
0
    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())
示例#2
0
 def test_list_installed(self, _, mock_conf, mock_conf_dir):
     mock_conf.return_value = self.conf_file
     mock_conf_dir.return_value = join(self.test_dir, 'conf')
     apps = ['test_app', 'test_app1', 'test_app2']
     # create packages, fill config with install steps
     for name in apps:
         create(self.test_dir, {'<name>': name})
         pack_path = join(self.test_dir, name)
         set_git_url(pack_path, 'http://github/comtihon/' + name)
         set_git_tag(pack_path, '1.0.0')
         test_install_dir = join(self.test_dir, 'test_install_' + name)
         modify_config(
             pack_path, {
                 'install': [{
                     'shell': 'mkdir ' + test_install_dir
                 }, {
                     'shell': 'cp ebin/*.* ' + test_install_dir
                 }]
             })
         self.__add_to_local(pack_path)
         self.assertEqual(True,
                          Controller().install('comtihon/' + name, None))
     installed_expected = [{
         'name': 'comtihon/' + app,
         'vsn': '1.0.0'
     } for app in apps]
     self.assertEqual(installed_expected, Controller().installed())
示例#3
0
 def test_dep_override_newer(self, mock_conf, mock_fetch):
     mock_conf.return_value = self.conf_file
     mock_fetch.side_effect = mock_fetch_package
     pack_path = join(self.test_dir, 'test_app')
     set_deps(pack_path, [{
         'name': 'dep2',
         'url': 'https://github.com/comtihon/dep2',
         'tag': '1.0.0'
     }, {
         'name': 'dep3',
         'url': 'https://github.com/comtihon/dep3',
         'tag': '1.0.1'
     }])
     create(self.tmp_dir, {'<name>': 'dep2'})
     dep_tmp_path = join(self.tmp_dir, 'dep2')
     set_deps(dep_tmp_path, [{
         'name': 'dep3',
         'url': 'https://github.com/comtihon/dep3',
         'tag': '1.0.0'
     }])
     create(self.tmp_dir, {'<name>': 'dep3'})
     builder = Builder.init_from_path(pack_path)
     builder.populate()
     self.assertEqual(['dep2', 'dep3'].sort(),
                      list(builder.packages.keys()).sort())
     self.assertEqual(mock_fetch.call_count, 2)
     self.assertEqual('1.0.0', builder.packages['dep2'].git_vsn)
     self.assertEqual('1.0.1', builder.packages['dep3'].git_vsn)
示例#4
0
 def test_update_erlang_relink_deps(self, mock_conf, _):
     mock_conf.return_value = self.conf_file
     pack_path = join(self.test_dir, 'test_app')
     set_deps(pack_path,
              [
                  {'name': 'dep_with_no_deps',
                   'url': 'https://github.com/comtihon/dep_with_no_deps',
                   'tag': '1.0.0'}
              ])
     create(self.tmp_dir, {'<name>': 'dep_with_no_deps'})
     dep_dir = join(self.tmp_dir, 'dep_with_no_deps')
     set_git_url(dep_dir, 'http://github/comtihon/dep_with_no_deps')
     set_git_tag(dep_dir, '1.0.0')  # This is not needed but pretend we really fetch it from git
     with patch.object(Static, 'get_erlang_version', return_value='18'):
         builder = Builder.init_from_path(pack_path)
         builder.populate()
         self.assertEqual(True, builder.build())
         dep_link_ebin = join(pack_path, 'deps', 'dep_with_no_deps', 'ebin')
         self.assertEqual(True, os.path.islink(dep_link_ebin))
         erl = Static.get_erlang_version()
         real_dep = join(self.cache_dir, 'comtihon', 'dep_with_no_deps', '1.0.0', erl, 'ebin')
         self.assertEqual(real_dep, os.readlink(dep_link_ebin))
     with patch.object(Static, 'get_erlang_version', return_value='22'):
         builder = Builder.init_from_path(pack_path)
         builder.populate()
         self.assertEqual(True, builder.build())
         dep_link_ebin = join(pack_path, 'deps', 'dep_with_no_deps', 'ebin')
         self.assertEqual(True, os.path.islink(dep_link_ebin))
         erl2 = Static.get_erlang_version()
         real_dep = join(self.cache_dir, 'comtihon', 'dep_with_no_deps', '1.0.0', erl2, 'ebin')
         self.assertEqual(real_dep, os.readlink(dep_link_ebin))
     self.assertNotEqual(erl, erl2)
示例#5
0
def mock_fetch_test_branch(url: str, _rev: str, path: str):
    splitted = path.split('/')
    [name] = splitted[-1:]
    create_path = '/'.join(splitted[:-1])
    create(create_path, {'<name>': name})
    set_git_url(path, url)
    return 'some_hash'
示例#6
0
 def test_project_with_test_dep_test_build(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'}
              ])
     set_deps(pack_path,
              [
                  {'name': 'test_dep',
                   'url': 'https://github.com/comtihon/test_dep',
                   'tag': '1.0.0'}
              ],
              'test_deps')
     create(self.tmp_dir, {'<name>': 'dep'})
     create(self.tmp_dir, {'<name>': 'test_dep'})
     builder = Builder.init_from_path(pack_path)
     builder.populate(include_test_deps=True)
     self.assertEqual(True, builder.build())
     for dep in ['dep', 'test_dep']:
         print('Check ' + dep)
         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))
示例#7
0
 def test_release_multiple_deps(self, mock_conf, _):
     mock_conf.return_value = self.conf_file
     pack_path = join(self.test_dir, 'test_app')
     set_deps(pack_path,
              [
                  {'name': 'dep_with_dep',
                   'url': 'https://github.com/comtihon/dep_with_dep',
                   'tag': '1.0.0'}
              ])
     create(self.tmp_dir, {'<name>': 'dep_with_dep'})
     dep_dir = join(self.tmp_dir, 'dep_with_dep')
     set_deps(dep_dir,
              [
                  {'name': 'dep',
                   'url': 'https://github.com/comtihon/dep',
                   'tag': '1.0.0'}
              ])
     create(self.tmp_dir, {'<name>': 'dep'})
     builder = Builder.init_from_path(pack_path)
     builder.populate()
     self.assertEqual(True, builder.build())
     path = ensure_tool(RelxTool())
     builder.system_config.cache.local_cache.add_tool('relx', path)
     self.assertEqual(True, builder.release())
     lib_dir = join(pack_path, '_rel', 'test_app', 'lib')
     self.assertEqual(True, os.path.exists(join(lib_dir, 'dep-0.0.1')))
     self.assertEqual(True, os.path.exists(join(lib_dir, 'dep_with_dep-0.0.1')))
示例#8
0
 def test_uninstall_package(self, _, mock_conf, mock_conf_dir):
     mock_conf.return_value = self.conf_file
     mock_conf_dir.return_value = join(self.test_dir, 'conf')
     # create package, fill config with install steps
     create(self.test_dir, {'<name>': 'test_app'})
     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')
     test_install_dir = join(self.test_dir, 'test_install')
     modify_config(
         pack_path, {
             'install': [{
                 'shell': 'mkdir ' + test_install_dir
             }, {
                 'shell': 'cp ebin/*.* ' + test_install_dir
             }],
             'uninstall': [{
                 'shell': 'rm -rf ' + test_install_dir
             }]
         })
     self.__add_to_local(pack_path)
     controller = Controller()
     self.assertEqual(True, controller.install('comtihon/test_app', None))
     self.assertEqual(True, os.path.isdir(test_install_dir))
     self.assertEqual(True, controller.uninstall('comtihon/test_app'))
     self.assertEqual(False, os.path.isdir(test_install_dir))
示例#9
0
 def test_install_package(self, _, mock_conf, mock_conf_dir):
     mock_conf.return_value = self.conf_file
     mock_conf_dir.return_value = join(self.test_dir, 'conf')
     # create package, fill config with install steps
     create(self.test_dir, {'<name>': 'test_app'})
     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')
     test_install_dir = join(self.test_dir, 'test_install')
     modify_config(
         pack_path, {
             'install': [{
                 'shell': 'mkdir ' + test_install_dir
             }, {
                 'shell': 'cp ebin/*.* ' + test_install_dir
             }]
         })
     builder = self.__add_to_local(pack_path)
     controller = Controller()
     self.assertEqual(True, controller.local_cache.exists(builder.project))
     self.assertEqual(False, os.path.isdir(test_install_dir))
     # install and check installed actions result
     self.assertEqual(True, controller.install('comtihon/test_app', None))
     self.assertEqual(True, os.path.isdir(test_install_dir))
     installed = os.listdir(test_install_dir)
     self.assertEqual(
         ['test_app.app', 'test_app_app.beam', 'test_app_sup.beam'],
         sorted(installed))
示例#10
0
 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))
示例#11
0
 def test_change_tag_remove_using_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_with_dep',
                   'url': 'https://github.com/comtihon/dep_with_dep',
                   'tag': '1.0.0'},
                  {'name': 'dep',
                   'url': 'https://github.com/comtihon/dep',
                   'tag': '1.0.0'}
              ])
     create(self.tmp_dir, {'<name>': 'dep_with_dep'})
     dep_dir = join(self.tmp_dir, 'dep_with_dep')
     set_git_url(dep_dir, 'http://github/comtihon/dep_with_dep')
     set_git_tag(dep_dir, '1.0.0')
     set_deps(dep_dir,
              [
                  {'name': 'dep',
                   'url': 'https://github.com/comtihon/dep',
                   'tag': '1.0.0'}
              ])
     create(self.tmp_dir, {'<name>': 'dep'})
     builder = Builder.init_from_path(pack_path)
     builder.populate()
     self.assertEqual(True, builder.build())
     # Check all two deps linked to the project
     dep_link_ebin = join(pack_path, 'deps', 'dep_with_dep', 'ebin')
     self.assertEqual(True, os.path.islink(dep_link_ebin))
     erl = Static.get_erlang_version()
     real_dep = join(self.cache_dir, 'comtihon', 'dep_with_dep', '1.0.0', erl, 'ebin')
     self.assertEqual(real_dep, os.readlink(dep_link_ebin))
     dep_link_ebin = join(pack_path, 'deps', 'dep', 'ebin')
     self.assertEqual(True, os.path.islink(dep_link_ebin))
     real_dep = join(self.cache_dir, 'comtihon', 'dep', '1.0.0', erl, 'ebin')
     self.assertEqual(real_dep, os.readlink(dep_link_ebin))
     # Dep version was changed - dep_with_dep no longer uses dep
     set_deps(pack_path,
              [
                  {'name': 'dep_with_dep',
                   'url': 'https://github.com/comtihon/dep_with_dep',
                   'tag': '1.0.1'},
                  {'name': 'dep',
                   'url': 'https://github.com/comtihon/dep',
                   'tag': '1.0.0'}
              ])
     set_deps(dep_dir, [])
     set_git_tag(dep_dir, '1.0.1')
     builder = Builder.init_from_path(pack_path)
     builder.populate()
     self.assertEqual(True, builder.build())
     # Check dep is linked to project, as it is used by project
     dep_link_ebin = join(pack_path, 'deps', 'dep_with_dep', 'ebin')
     self.assertEqual(True, os.path.islink(dep_link_ebin))
     real_dep = join(self.cache_dir, 'comtihon', 'dep_with_dep', '1.0.1', erl, 'ebin')
     self.assertEqual(real_dep, os.readlink(dep_link_ebin))
     dep_link_ebin = join(pack_path, 'deps', 'dep', 'ebin')
     self.assertEqual(True, os.path.islink(dep_link_ebin))
示例#12
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)
示例#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
 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)
示例#15
0
 def test_link_with_deps(self, mock_conf, _):
     mock_conf.return_value = self.conf_file
     pack_path = join(self.test_dir, 'test_app')
     set_deps(pack_path, [{
         'name': 'dep_with_dep',
         'url': 'https://github.com/comtihon/dep_with_dep',
         'tag': '1.0.0'
     }])
     # Create, build and add dep.
     create(self.tmp_dir, {'<name>': 'dep'})
     dep_dep_path = join(self.tmp_dir, 'dep')
     set_git_url(dep_dep_path, 'https://github/comtihon/dep')
     set_git_tag(dep_dep_path, '1.0.0')
     dep_builder = Builder.init_from_path(dep_dep_path)
     # Build dep of dep and add to cache
     dep_builder.populate()
     self.assertEqual(True, dep_builder.build())
     dep_builder.system_config.cache.add_package_local(dep_builder.project)
     self.assertEqual(
         True,
         dep_builder.system_config.cache.exists_local(dep_builder.project))
     # Create, build and add dep with dep: dep
     create(self.tmp_dir, {'<name>': 'dep_with_dep'})
     dep_path = join(self.tmp_dir, 'dep_with_dep')
     set_git_url(dep_path, 'https://github/comtihon/dep_with_dep')
     set_git_tag(dep_path, '1.0.0')
     set_deps(dep_path, [{
         'name': 'dep',
         'url': 'https://github.com/comtihon/dep',
         'tag': '1.0.0'
     }])
     dep_builder = Builder.init_from_path(dep_path)
     dep_builder.populate()
     self.assertEqual(True, dep_builder.build())
     dep_builder.system_config.cache.add_package_local(dep_builder.project)
     self.assertEqual(
         True,
         dep_builder.system_config.cache.exists_local(dep_builder.project))
     builder = Builder.init_from_path(pack_path)
     builder.populate()
     self.assertEqual(True, builder.build())
     for dep in ['dep_with_dep',
                 'dep']:  # Dep and dep's dep are linked to the project
         print('Check ' + dep)
         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))
示例#16
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))
示例#17
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')))
示例#18
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)
示例#19
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'))
示例#20
0
 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_with_no_deps',
                   'url': 'https://github.com/comtihon/dep_with_no_deps',
                   'tag': '1.0.0'}
              ])
     create(self.tmp_dir, {'<name>': 'dep_with_no_deps'})
     builder = Builder.init_from_path(pack_path)
     builder.populate()
     self.assertEqual(True, builder.build())
     dep_link_ebin = join(pack_path, 'deps', 'dep_with_no_deps', 'ebin')
     self.assertEqual(True, os.path.islink(dep_link_ebin))
     erl = Static.get_erlang_version()
     real_dep = join(self.cache_dir, 'comtihon', 'dep_with_no_deps', '1.0.0', erl, 'ebin')
     self.assertEqual(real_dep, os.readlink(dep_link_ebin))
示例#21
0
 def test_deps_duplicates(self, mock_conf, mock_fetch):
     mock_conf.return_value = self.conf_file
     mock_fetch.side_effect = mock_fetch_package
     pack_path = join(self.test_dir, 'test_app')
     set_deps(pack_path, [{
         'name': 'dep1',
         'url': 'https://github.com/comtihon/dep1',
         'tag': '1.0.0'
     }, {
         'name': 'dep2',
         'url': 'https://github.com/comtihon/dep2',
         'tag': '1.0.0'
     }])
     create(self.tmp_dir, {'<name>': 'dep1'})
     dep_tmp_path = join(self.tmp_dir,
                         'dep1')  # Here dep1 and dep2 have common dep3
     set_deps(dep_tmp_path, [{
         'name': 'dep3',
         'url': 'https://github.com/comtihon/dep3',
         'tag': '1.0.0'
     }])
     create(self.tmp_dir, {'<name>': 'dep2'})
     dep_tmp_path = join(self.tmp_dir, 'dep2')
     set_deps(dep_tmp_path, [{
         'name': 'dep3',
         'url': 'https://github.com/comtihon/dep3',
         'tag': '1.0.0'
     }])
     create(self.tmp_dir, {'<name>': 'dep3'})
     builder = Builder.init_from_path(pack_path)
     builder.populate()
     self.assertEqual(['dep1', 'dep2', 'dep3'].sort(),
                      list(builder.packages.keys()).sort())
     self.assertEqual(mock_fetch.call_count,
                      3)  # dep3 was fetched only once
示例#22
0
 def test_deps_conflict(self, mock_conf, mock_fetch):
     mock_conf.return_value = self.conf_file
     mock_fetch.side_effect = mock_fetch_package
     pack_path = join(self.test_dir, 'test_app')
     set_deps(pack_path, [{
         'name': 'dep1',
         'url': 'https://github.com/comtihon/dep1',
         'tag': '1.0.0'
     }, {
         'name': 'dep2',
         'url': 'https://github.com/comtihon/dep2',
         'tag': '1.0.0'
     }, {
         'name': 'dep3',
         'url': 'https://github.com/comtihon/dep3',
         'tag': '2.0.0'
     }])
     create(self.tmp_dir, {'<name>': 'dep1'})
     create(self.tmp_dir, {'<name>': 'dep2'})
     dep_tmp_path = join(self.tmp_dir, 'dep2')
     set_deps(dep_tmp_path, [{
         'name': 'dep3',
         'url': 'https://github.com/comtihon/dep3',
         'tag': '1.0.0'
     }])
     create(self.tmp_dir, {'<name>': 'dep3'})
     builder = Builder.init_from_path(pack_path)
     try:  # builder population should fail, because of conflicting dependencies.
         builder.populate()
         populated = True
     except RuntimeError:
         populated = False
     self.assertEqual(False, populated)
示例#23
0
 def test_link_multiple_deps(self, mock_conf, _):
     mock_conf.return_value = self.conf_file
     pack_path = join(self.test_dir, 'test_app')
     set_deps(pack_path,
              [
                  {'name': 'a_with_dep_a2',
                   'url': 'https://github.com/comtihon/a_with_dep_a2',
                   'tag': '1.0.0'},
                  {'name': 'b_with_no_deps',
                   'url': 'https://github.com/comtihon/b_with_no_deps',
                   'tag': '1.0.0'}
              ])
     # Create dep A with dep A2 (in tmp, as if we download them from git)
     create(self.tmp_dir, {'<name>': 'a_with_dep_a2'})
     dep_a1_path = join(self.tmp_dir, 'a_with_dep_a2')
     set_deps(dep_a1_path, [{'name': 'a2_with_no_deps',
                             'url': 'https://github.com/comtihon/a2_with_no_deps',
                             'tag': '1.0.0'}])
     # Create dep B (in tmp, as if we download them from git)
     create(self.tmp_dir, {'<name>': 'b_with_no_deps'})
     # Create dep A2 (in tmp, as if we download them from git)
     create(self.tmp_dir, {'<name>': 'a2_with_no_deps'})
     # Compile test_project
     builder = Builder.init_from_path(pack_path)
     builder.populate()
     self.assertEqual(True, builder.build())
     for dep in ['a_with_dep_a2', 'b_with_no_deps', 'a2_with_no_deps']:
         print('Check ' + dep)
         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))
示例#24
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')))
示例#25
0
    def test_release_non_otp_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_dir = join(self.tmp_dir, 'dep')
        ensure_dir(join(dep_dir, 'src'))
        with open(join(dep_dir, 'src', 'dep.erl'), 'w') as f:
            f.write('''
                    -module(dep).
                    -export([test/0]).
                    test() ->
                        ok.
                    ''')
        with open(join(dep_dir, 'src', 'dep.app.src'), 'w') as f:
            f.write('''
                    {application, dep, [
                      {description, ""},
                      {vsn, "0.0.1"},
                      {registered, []},
                      {applications, {{ app.std_apps + app.apps }}},
                      {modules, {{ modules }}}
                    ]}.
                    ''')
        builder = Builder.init_from_path(pack_path)
        builder.populate()
        self.assertEqual(True, builder.build())
        path = ensure_tool(RelxTool())
        builder.system_config.cache.local_cache.add_tool('relx', path)
        self.assertEqual(True, builder.release())
        lib_dir = join(pack_path, '_rel', 'test_app', 'lib')
        self.assertEqual(True, os.path.exists(join(lib_dir, 'dep-0.0.1')))
示例#26
0
 def test_override_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')
     set_prebuild(project_dir, [],
                  disable_prebuild=True,
                  override_conf=True)
     # root project has dep, which has some shell prebuild step
     set_deps(project_dir, [{
         'name': 'dep',
         'url': 'https://github.com/comtihon/dep',
         'tag': '1.0.0'
     }])
     create(self.tmp_dir, {'<name>': 'dep'})
     dep_path = join(self.tmp_dir, 'dep')
     set_git_url(dep_path, 'https://github/comtihon/dep')
     set_git_tag(dep_path, '1.0.0')
     test_file_path = join(project_dir, 'test_file')
     set_prebuild(dep_path, [{'shell': 'echo "test" > ' + test_file_path}])
     builder = Builder.init_from_path(project_dir)
     builder.populate()
     self.assertEqual(True, builder.build())
     self.assertEqual(False, os.path.exists(
         test_file_path))  # no dep's prebuild step was executed
示例#27
0
 def test_add_with_deps(self, mock_conf, _):
     mock_conf.return_value = self.conf_file
     # Create test_app with deps: A and B
     pack_path = join(self.test_dir, 'test_app')
     set_deps(pack_path,
              [
                  {'name': 'a_with_dep_a2',
                   'url': 'https://github.com/comtihon/a_with_dep_a2',
                   'tag': '1.0.0'},
                  {'name': 'b_with_no_deps',
                   'url': 'https://github.com/comtihon/b_with_no_deps',
                   'tag': '1.0.0'}
              ])
     # Create dep A with dep A2 (in tmp, as if we download them from git)
     create(self.tmp_dir, {'<name>': 'a_with_dep_a2'})
     dep_a1_path = join(self.tmp_dir, 'a_with_dep_a2')
     set_deps(dep_a1_path, [{'name': 'a2_with_no_deps',
                             'url': 'https://github.com/comtihon/a2_with_no_deps',
                             'tag': '1.0.0'}])
     set_git_url(dep_a1_path, 'http://github/comtihon/a2_with_no_deps')
     set_git_tag(dep_a1_path, '1.0.0')
     # Create dep B (in tmp, as if we download them from git)
     create(self.tmp_dir, {'<name>': 'b_with_no_deps'})
     dep_b_path = join(self.tmp_dir, 'b_with_no_deps')
     set_git_url(dep_b_path, 'http://github/comtihon/b_with_no_deps')
     set_git_tag(dep_b_path, '1.0.0')
     # Create dep A2 (in tmp, as if we download them from git)
     create(self.tmp_dir, {'<name>': 'a2_with_no_deps'})
     dep_a2_path = join(self.tmp_dir, 'a2_with_no_deps')
     set_git_url(dep_a2_path, 'http://github/comtihon/a2_with_no_deps')
     set_git_tag(dep_a2_path, '1.0.0')
     # Compile test_project
     builder = Builder.init_from_path(pack_path)
     self.assertEqual(False, builder.system_config.cache.exists_local(Package.from_path(dep_a1_path)))
     self.assertEqual(False, builder.system_config.cache.exists_local(Package.from_path(dep_b_path)))
     self.assertEqual(False, builder.system_config.cache.exists_local(Package.from_path(dep_a2_path)))
     builder.populate()
     self.assertEqual(True, builder.build())
     self.assertEqual(True, builder.system_config.cache.exists_local(Package.from_path(dep_a1_path)))
     self.assertEqual(True, builder.system_config.cache.exists_local(Package.from_path(dep_b_path)))
     self.assertEqual(True, builder.system_config.cache.exists_local(Package.from_path(dep_a2_path)))
示例#28
0
 def test_deps_prefer_newer_new_dep(self, mock_conf, mock_fetch):
     mock_conf.return_value = self.conf_file
     mock_fetch.side_effect = mock_fetch_package
     pack_path = join(self.test_dir, 'test_app')
     set_deps(
         pack_path,
         [
             {
                 'name': 'update_dep',
                 'url': 'https://github.com/comtihon/update_dep',
                 'tag': '1.0.0'
             },  # has no deps in 1.0.0
             {
                 'name': 'dep2',
                 'url': 'https://github.com/comtihon/dep2',
                 'tag': '1.0.0'
             }  # dep2 has update_dep 1.2.0 in deps
         ])
     create(self.tmp_dir, {'<name>': 'dep2'})
     dep_tmp_path = join(self.tmp_dir, 'dep2')
     set_deps(
         dep_tmp_path,
         [{
             'name': 'update_dep',
             'url': 'https://github.com/comtihon/update_dep',
             'tag': '1.2.0'
         }  # has newer version then root
          ])
     create(self.tmp_dir, {
         '<name>': 'update_dep'
     })  # dep3 will be added as a dep in 1.2.0 (see mock_fetch_package)
     create(self.tmp_dir, {'<name>': 'dep3'})
     builder = Builder.init_from_path(pack_path)
     builder.populate()
     self.assertEqual(['update_dep', 'dep2', 'dep3'].sort(),
                      list(builder.packages.keys()).sort())
     self.assertEqual('1.0.0', builder.packages['dep2'].git_vsn)
     self.assertEqual('1.2.0', builder.packages['update_dep'].git_vsn)
     self.assertEqual('1.0.0', builder.packages['dep3'].git_vsn)
示例#29
0
 def test_circular_deps(self, mock_conf, mock_fetch):
     mock_conf.return_value = self.conf_file
     mock_fetch.side_effect = mock_fetch_package
     pack_path = join(self.test_dir, 'test_app')
     set_deps(pack_path, [{
         'name': 'dep1',
         'url': 'https://github.com/comtihon/dep1',
         'tag': '1.0.0'
     }, {
         'name': 'dep2',
         'url': 'https://github.com/comtihon/dep2',
         'tag': '1.0.0'
     }])
     create(self.tmp_dir, {'<name>': 'dep1'})
     create(self.tmp_dir, {'<name>': 'dep2'})
     dep_tmp_path = join(self.tmp_dir, 'dep2')
     set_deps(dep_tmp_path, [{
         'name': 'dep3',
         'url': 'https://github.com/comtihon/dep3',
         'tag': '1.0.0'
     }])
     create(self.tmp_dir, {'<name>': 'dep3'})
     dep_tmp_path = join(self.tmp_dir, 'dep3')
     set_deps(
         dep_tmp_path,  # dep3 require dep1, which was included in root.
         [{
             'name': 'dep1',
             'url': 'https://github.com/comtihon/dep1',
             'tag': '1.0.0'
         }])
     builder = Builder.init_from_path(pack_path)
     builder.populate()
     self.assertEqual(['dep1', 'dep2', 'dep3'].sort(),
                      list(builder.packages.keys()).sort())
     self.assertEqual(mock_fetch.call_count,
                      3)  # dep1 was fetched only once
示例#30
0
 def setUp(self):
     super().setUp()
     create(self.test_dir, {'<name>': 'test_app'})