diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2760b50c9d4369e703a54be8bb6a2618a970b951..c25b2900a5a9c3e6819b1909ac7aad697955e33e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,6 +63,8 @@ test require: stage: test before_script: - source $(pwd)/epics/base-*/require/*/bin/activate + # We need to allow file:// protocol for all of the tests to work + - git config --global procotol.file.allow always script: - make test needs: diff --git a/tests/build_system/test_convenience_features.py b/tests/build_system/test_convenience_features.py index 290aca1ceca9f0f6893ba2b1388219022e9823a1..ebac137a69753e37ea8504ae08326423ab8d6451 100644 --- a/tests/build_system/test_convenience_features.py +++ b/tests/build_system/test_convenience_features.py @@ -17,9 +17,3 @@ def test_warning_msg_if_building_from_sitemods(wrapper): assert ( "It is ill-advised to build a module from the module install location." in errs ) - - -def test_info_msg_if_local_mode(wrapper): - rc, outs, _ = wrapper.run_make("init") - assert rc == 0 - assert "You are in the local source mode" in outs diff --git a/tests/build_system/test_make_clean.py b/tests/build_system/test_make_clean.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/build_system/test_make_init.py b/tests/build_system/test_make_init.py new file mode 100644 index 0000000000000000000000000000000000000000..6dd83ad63d518243d9111fc55c35cd9dcab22abf --- /dev/null +++ b/tests/build_system/test_make_init.py @@ -0,0 +1,85 @@ +import shutil +import subprocess + +import pytest + + +def set_up_git_submodule(main, sub) -> None: + # remove local dir with dbd-file and add fake repo as submodule + shutil.rmtree(main.module_dir) + subprocess.run( + ["git", "init"], + cwd=main.wrapper_dir, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + # we allow file:// as protocol in order to not get a fatal error like + # fatal: transport 'file' not allowed + # see https://lore.kernel.org/git/000001d91c8b$6a26cd60$3e746820$@nexbridge.com/T/ + subprocess.run( + [ + "git", + "-c", + "protocol.file.allow=always", + "submodule", + "add", + f"file://{sub.module_dir.as_posix()}", + main.name, + ], + cwd=main.wrapper_dir, + ) + main.write_var_to_makefile( + main.config_module, + "EPICS_MODULE_TAG", + "fake-tag", + ) + + +def test_error_if_epics_module_tag_set_but_no_submodule(wrapper): + wrapper.write_var_to_makefile( + wrapper.config_module, + "EPICS_MODULE_TAG", + "whatever", + ) + rc, _, stderr = wrapper.run_make("init") + assert rc != 0 + assert stderr + + +@pytest.mark.skipif( + subprocess.run( + ["git", "config", "get", "protocol.file.allow"], stdout=subprocess.PIPE + ) + .stdout.decode() + .strip() + != "always", + reason="file protocol must be allowed", +) +def test_init_inits_without_error_if_defined(wrapper, module): + set_up_git_submodule(wrapper, module) + + rc, *_ = wrapper.run_make("init") + assert rc == 0 + + +def test_init_fetches_submodule_files(wrapper, module): + set_up_git_submodule(wrapper, module) + + _ = wrapper.run_make("init") + assert len(list((wrapper.wrapper_dir / wrapper.name).iterdir())) > 0 + + +def test_init_checks_out_version_in_epics_module_tag(wrapper, module): + set_up_git_submodule(wrapper, module) + + _ = wrapper.run_make("init") + res = subprocess.run( + ["git", "describe", "--tags"], cwd=wrapper.module_dir, stdout=subprocess.PIPE + ) + assert res.stdout.decode().strip() == "fake-tag" + + +def test_info_msg_if_local_mode(wrapper): + rc, outs, _ = wrapper.run_make("init") + assert rc == 0 + assert "You are in the local source mode" in outs diff --git a/tests/conftest.py b/tests/conftest.py index 4d62bf0f4416f98e3f572f34548ec6389d91319b..9fdf3851a8e6b2105f06e02c8b6b6caad1616e9b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,6 +22,34 @@ def wrapper(wrapper_factory): return wrapper_factory.create() +@pytest.fixture() +def module(tmp_path): + return Module(tmp_path) + + +class Module: + def __init__(self, tmp_test_dir: Path): + self.name = "module-" + "".join(choice(ascii_lowercase) for _ in range(16)) + self.module_dir = tmp_test_dir / self.name + self.module_dir.mkdir() + + # set up fake repo + fake_file = self.module_dir / "random-file-to-commit" + fake_file.write_text("whatever") + for cmd in [ + "git init", + "git add .", + "git commit -m message -q", + "git tag fake-tag", + ]: + subprocess.run( + cmd.split(), + cwd=self.module_dir, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + + class Wrapper: def __init__( self,