From 12c4f9bbd0b11fdaf91cfd4deb440c6b084e2da2 Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 24 Feb 2025 15:08:36 +0100 Subject: [PATCH] feat: test ensuring no trivial rebuilds (#1863) * feat: test ensuring no trivial rebuilds * Fix test on Windows --- testsuite/drivers/helpers.py | 8 +++++ testsuite/tests/build/no-rebuild/test.py | 30 +++++++++++++++++++ testsuite/tests/build/no-rebuild/test.yaml | 5 ++++ .../tests/crate_config/no-rebuilds/test.py | 3 +- 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 testsuite/tests/build/no-rebuild/test.py create mode 100644 testsuite/tests/build/no-rebuild/test.yaml diff --git a/testsuite/drivers/helpers.py b/testsuite/drivers/helpers.py index 9ae92a69..a1911836 100644 --- a/testsuite/drivers/helpers.py +++ b/testsuite/drivers/helpers.py @@ -296,6 +296,7 @@ def neutral_path(path : str) -> str: """ return path.replace('\\', '/') + def which(exec : str) -> str: """ Return the full path to an executable if it can be found in PATH, or "" @@ -307,6 +308,13 @@ def which(exec : str) -> str: return shutil.which(exec) +def exe_name(exec : str) -> str: + """ + Return the executable name with ".exe" appended on Windows. + """ + return f"{exec}.exe" if on_windows() else exec + + class FileLock(): """ A filesystem-level lock for tests executed from different threads but diff --git a/testsuite/tests/build/no-rebuild/test.py b/testsuite/tests/build/no-rebuild/test.py new file mode 100644 index 00000000..812a8bc8 --- /dev/null +++ b/testsuite/tests/build/no-rebuild/test.py @@ -0,0 +1,30 @@ +""" +Ensure that no rebuild happens when `alr build` is invoked twice. Reports like +https://github.com/alire-project/alire/issues/1798 hint at a problem in gprbuild +itself, but this should not arise at least on simple crates. + +This test differs from crate_config/no-rebuilds in that here we have dependencies. +""" + +from drivers.alr import alr_with, init_local_crate, run_alr +from drivers.asserts import assert_substring +from drivers.helpers import exe_name + +# Basic check in which building twice should not trigger a rebuild + +init_local_crate() +alr_with("libhello") +run_alr("build") +p = run_alr("build", quiet=False) +assert_substring (f'gprbuild: "{exe_name("xxx")}" up to date', p.out) + +# Check that removing and re-adding a dependency does not trigger a rebuild +# (since the build folders already exist). + +run_alr("with", "--del", "libhello") +run_alr("with", "libhello") +p = run_alr("build", quiet=False) +assert_substring (f'gprbuild: "{exe_name("xxx")}" up to date', p.out) + + +print("SUCCESS") diff --git a/testsuite/tests/build/no-rebuild/test.yaml b/testsuite/tests/build/no-rebuild/test.yaml new file mode 100644 index 00000000..78b8b224 --- /dev/null +++ b/testsuite/tests/build/no-rebuild/test.yaml @@ -0,0 +1,5 @@ +driver: python-script +build_mode: shared +indexes: + basic_index: + in_fixtures: true diff --git a/testsuite/tests/crate_config/no-rebuilds/test.py b/testsuite/tests/crate_config/no-rebuilds/test.py index 7715f9c2..1ff17724 100644 --- a/testsuite/tests/crate_config/no-rebuilds/test.py +++ b/testsuite/tests/crate_config/no-rebuilds/test.py @@ -2,9 +2,8 @@ Ensure that no unnecessary rebuilds happend due to crate config generation """ -from drivers.alr import alr_with, init_local_crate, run_alr +from drivers.alr import init_local_crate, run_alr from drivers.asserts import assert_match -from drivers.helpers import prepend_to_file init_local_crate() run_alr("build") # First build -- 2.39.5