rrthomas / libpaper

Library and command-line tools for configuring and getting information on paper sizes
GNU Lesser General Public License v2.1
9 stars 11 forks source link

Test failures on macOS because you haven't set DYLD_LIBRARY_PATH #52

Closed ryandesign closed 10 months ago

ryandesign commented 10 months ago

All tests fail on macOS:

FAIL: default-size-environment.sh
FAIL: default-size-user.sh
SKIP: default-size-lc_paper.sh
FAIL: default-size-system-papersize.sh
FAIL: default-size-system-paperspecs.sh
FAIL: default-size-user-paperspecs.sh
FAIL: default-size-no-default-paper.sh
FAIL: unit-pt.sh
FAIL: unit-pt-equals.sh
FAIL: unit-mm.sh
FAIL: unit-in.sh
FAIL: unit-invalid.sh
FAIL: all-sizes.sh
FAIL: zero-arguments.sh
FAIL: one-argument.sh
FAIL: two-arguments.sh
FAIL: paperspecs-invalid.sh
FAIL: no-home.sh
FAIL: paper-unknown.sh
FAIL: bad-width.sh
FAIL: bad-height.sh
FAIL: unknown-option.sh
FAIL: option-requires-argument.sh
============================================================================
Testsuite summary for libpaper 2.1.2
============================================================================
# TOTAL: 23
# PASS:  0
# SKIP:  1
# XFAIL: 0
# FAIL:  22
# XPASS: 0
# ERROR: 0
============================================================================
See tests/test-suite.log
Please report to rrt@sc3d.org
============================================================================

because your test programs link with libpaper.dylib by the absolute path where it will eventually be installed but it has not been installed there yet:

Termination Reason:    Namespace DYLD, Code 1 Library missing
Library not loaded: '/opt/local/lib/libpaper.2.dylib'
Referenced from: '/opt/local/var/macports/*/paper'
Reason: tried: '/opt/local/lib/libpaper.2.dylib' (no such file), '' (no such file), '' (no such file)
(terminated at launch; ignore backtrace)

and if it did exist at that location you wouldn't want to use it because it could be a different version than the one you just built and your test programs might not be compatible with that version of the library.

To use the just-built version of the library in your tests, you must set the DYLD_LIBRARY_PATH environment variable to the path of the directory where libpaper.dylib is located in the build tree so that the test programs can find it. You must set it right at the point where you run the programs that link with the library; you cannot set it from a higher-level script or Makefile because DYLD environment variables are not passed to subprocesses.

Your programs and library are built with libtool which provides you with wrapper scripts which handle this for you but your test suite ignores those wrapper scripts and instead uses make install to install the software to a temporary location and run it from there, at which point it becomes your responsibility to set DYLD_LIBRARY_PATH to make that possible.

ryandesign commented 10 months ago

My preliminary patch is:

--- tests/Makefile.am.orig  2023-10-14 12:27:15.000000000 -0500
+++ tests/Makefile.am   2024-01-16 02:35:24.000000000 -0600
@@ -89,6 +89,7 @@
    export prefix=$(prefix); \
    export sysconfdir=$(sysconfdir); \
    export bindir=$(bindir); \
+   export libdir=$(libdir); \
    export abs_srcdir=$(abs_srcdir); \
    export DIFF=$(DIFF); \
    export PATH_CONVERT=$(PATH_CONVERT); \
--- tests/run-test.orig 2023-04-12 12:28:24.000000000 -0500
+++ tests/run-test  2024-01-16 01:55:41.000000000 -0600
@@ -105,6 +105,7 @@
 cd ..
 ${MAKE} install DESTDIR="$test_dir"
 export PATH="$test_dir/$bindir:$PATH"
+export DYLD_LIBRARY_PATH="$test_dir/$libdir"
 cd "$test_dir"

 # Set up paper configuration

however that only fixes eight of the tests. Six of the remaining tests are failing due to #35; for the final eight failures, I'm not sure of the cause yet.

rrthomas commented 10 months ago

Thanks very much for filing this issue and trying to fix it.

I'm a bit puzzled, because CI runs the tests on macOS, and they pass. Could you possibly look at .github/workflows/c-cpp.yml and see if there's anything I do there (no "tricks" that I can see) that would make a difference? In particular, did you configure with --enable-relocatable?

ryandesign commented 10 months ago

Right, you're using --enable-relocatable which makes the problem go away.

https://github.com/rrthomas/libpaper/blob/c1a157b863fc210ef12735e6b9f576597b1083a8/build-aux/build.sh#L9

I'm intentionally not using that flag.

rrthomas commented 10 months ago

Ah, that makes sense. In that case, I'd be happy to merge your patch above, as it's simple and a step towards running the tests on all platforms without --enable-relocatable, which would be an improvement.

ryandesign commented 10 months ago

Ok, I submitted a PR for it, which will close this issue, and I'll file a new issue for the remaining test failures since they seem to have a different cause.