Skip to content
Snippets Groups Projects
Commit bbc76373 authored by Simon Rose's avatar Simon Rose
Browse files

Merge branch 'add_tests' into 'master'

E3-665: Add tests for KEEP_HEADER_SUBDIRS

See merge request e3/e3-require!67
parents 6281688b c58e08f8
No related branches found
No related tags found
No related merge requests found
import re import re
from pathlib import Path
import pytest import pytest
from .utils import TEST_MODULE_NAME, run_make from .utils import TEST_MODULE_NAME, get_env_var, run_make
MODULE_VERSION = "0.0.0+0" MODULE_VERSION = "0.0.0+0"
MODULE_VERSION_NO_BUILD = "0.0.0" MODULE_VERSION_NO_BUILD = "0.0.0"
...@@ -56,7 +57,7 @@ def test_patch(wrapper): ...@@ -56,7 +57,7 @@ def test_patch(wrapper):
E3_MODULE_VERSION=MODULE_VERSION, E3_MODULE_VERSION=MODULE_VERSION,
) )
assert rc == 0 assert rc == 0
assert "You are in the local source mode" in outs.decode("utf-8") assert "You are in the local source mode" in outs
rc, _, _ = run_make(wrapper, "patch", E3_MODULE_VERSION=MODULE_VERSION) rc, _, _ = run_make(wrapper, "patch", E3_MODULE_VERSION=MODULE_VERSION)
assert rc == 0 assert rc == 0
...@@ -85,7 +86,7 @@ def test_missing_dbd_file(wrapper): ...@@ -85,7 +86,7 @@ def test_missing_dbd_file(wrapper):
assert rc == 2 assert rc == 2
assert re.search( assert re.search(
RE_MISSING_FILE.format(filename=re.escape("../nonexistent.dbd")), RE_MISSING_FILE.format(filename=re.escape("../nonexistent.dbd")),
errs.decode("utf-8"), errs,
) )
...@@ -100,7 +101,7 @@ def test_missing_source_file(wrapper): ...@@ -100,7 +101,7 @@ def test_missing_source_file(wrapper):
assert rc == 2 assert rc == 2
assert re.search( assert re.search(
RE_MISSING_FILE.format(filename=re.escape("nonexistent.o")), RE_MISSING_FILE.format(filename=re.escape("nonexistent.o")),
errs.decode("utf-8"), errs,
) )
...@@ -110,4 +111,27 @@ def test_missing_requirement(wrapper): ...@@ -110,4 +111,27 @@ def test_missing_requirement(wrapper):
rc, _, errs = run_make(wrapper, "build") rc, _, errs = run_make(wrapper, "build")
assert rc == 2 assert rc == 2
assert "REQUIRED module 'foo' version '' does not exist" in errs.decode("utf-8") assert "REQUIRED module 'foo' version '' does not exist" in errs
def test_header_install_location(wrapper):
subdir = wrapper / TEST_MODULE_NAME / "db" / "subdir"
subdir.mkdir(parents=True)
extensions = ["h", "hpp", "hxx", "hh"]
with open(wrapper / f"{TEST_MODULE_NAME}.Makefile", "a") as f:
for ext in extensions:
f.write(f"HEADERS += db/subdir/header.{ext}\n")
f.write("KEEP_HEADER_SUBDIRS += db\n")
for ext in extensions:
(subdir / f"header.{ext}").touch()
rc, *_ = run_make(wrapper, "cellinstall")
assert rc == 0
cell_path = get_env_var(wrapper, "E3_MODULES_INSTALL_LOCATION")
for ext in extensions:
assert (Path(cell_path) / "include" / "subdir" / f"header.{ext}").is_file()
assert not (Path(cell_path) / "include" / f"header.{ext}").is_file()
...@@ -11,7 +11,7 @@ from .utils import run_make ...@@ -11,7 +11,7 @@ from .utils import run_make
def test_loc(wrapper): def test_loc(wrapper):
rc, _, errs = run_make(wrapper, "build", E3_MODULE_SRC_PATH="test-loc") rc, _, errs = run_make(wrapper, "build", E3_MODULE_SRC_PATH="test-loc")
assert rc == 2 assert rc == 2
assert 'Local source mode "-loc" has been deprecated' in errs.decode("utf-8") assert 'Local source mode "-loc" has been deprecated' in errs
def test_sitelibs(wrapper): def test_sitelibs(wrapper):
...@@ -34,11 +34,11 @@ include $(REQUIRE_CONFIG)/RULES_DEV ...@@ -34,11 +34,11 @@ include $(REQUIRE_CONFIG)/RULES_DEV
) )
rc, _, errs = run_make(wrapper, "build") rc, _, errs = run_make(wrapper, "build")
assert rc == 2 assert rc == 2
assert "RULES_E3 should only be loaded from RULES_SITEMODS" in errs.decode("utf-8") assert "RULES_E3 should only be loaded from RULES_SITEMODS" in errs
def test_incorrect_module_name(wrapper): def test_incorrect_module_name(wrapper):
module_name = "ADCore" module_name = "ADCore"
rc, _, errs = run_make(wrapper, "build", E3_MODULE_NAME=module_name) rc, _, errs = run_make(wrapper, "build", E3_MODULE_NAME=module_name)
assert rc == 2 assert rc == 2
assert f"E3_MODULE_NAME '{module_name}' is not valid" in errs.decode("utf-8") assert f"E3_MODULE_NAME '{module_name}' is not valid" in errs
...@@ -49,12 +49,27 @@ def run_make(path, *args, **kwargs): ...@@ -49,12 +49,27 @@ def run_make(path, *args, **kwargs):
test_env[kw] = kwargs[kw] test_env[kw] = kwargs[kw]
make_cmd = ["make", "-C", path] + list(args) make_cmd = ["make", "-C", path] + list(args)
p = subprocess.Popen( p = subprocess.Popen(
make_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=test_env make_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
env=test_env,
encoding="utf-8",
) )
outs, errs = p.communicate() outs, errs = p.communicate()
return p.returncode, outs, errs return p.returncode, outs, errs
def get_env_var(path, var: str):
"""
Fetch an environment variable from the module build environment
"""
_, out, _ = run_make(path, "cellvars")
for line in out.split("\n"):
if line.startswith(var):
return line.split("=")[1].strip()
return ""
def run_ioc_get_output(version, cell_path): def run_ioc_get_output(version, cell_path):
""" """
Run an IOC and try to load the test module Run an IOC and try to load the test module
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment