[Build] `testFontStyleOfStyledFont` causes builds to fail with default Maven configuration on OSX 13.0 and higher
Describe the bug
On OS X Ventura (13.0) or later, the Courier font is missing its OS/2 table, probably due to licensing decisions made by Apple.
This causes the testFontStyleOfStyledFont test to fail:
https://github.com/LibrePDF/OpenPDF/blob/0a92bcc7ea9a41f919e093f774a3104865d92a42/openpdf/src/test/java/com/lowagie/text/pdf/fonts/FontTest.java#L81-L92
To Reproduce
Run mvn clean install on OSX 13.0 or newer. The build will fail due to an exception com.lowagie.text.DocumentException: Table 'OS/2' does not exist in /System/Library/Fonts/Courier.ttc in testFontStyleOfStyledFont.
Setting maven.test.failure.ignore to true allows you to build the project but, for obvious reasons, this is a bad workaround for anything other than trivial changes.
Expected behavior
It would be nice if this test failed gracefully if the font is not present or readable on the system.
System
(please complete the following information)
- OS: [e.g. iOS] macOS 14.4.1
- Used font: Courier
- OpenPDF version: 2.0.2 (master branch - 0a92bcc7ea9a41f919e093f774a3104865d92a42)
- Java version: openjdk 21.0.2
Your real name
Kurt Boberg
Which version of maven are you using:
mvn -version
@asturio 3.9.6
I'd like to find a font provided by all OS. Are there any other Mac-Users who can confirm, that this test also fails on their computer? Which font could be used instead. Alternatively, the test could be disabled on MacOS.
Just checked, that courier is also bundled with OpenPDF. So even a more strange behavior here.
The call of FontFactory.registerDirectories(); was made only in one of the tests. It could be, that the order of the tests are different in MacOS, and this call is necessary for all.
I just commited a little change. @kurt-r2c, can you please try, if the test passes now?
I'm also a Mac-user and can confirm that the aforementioned test still fails consistently on MacOs 14.6.1.
The test contains the beforeAll() with FontFactory.registerDirectories(); call, so this doesn't seem to fix this issue. It indeed seems that the Courier font of the os is not compatible with the tests or the styles expectations.
Building it on Mac requires skipping this test. Unfortunately I'm not sure of any font to be consistently used on all os. Such a dependency on the local os setup will probably always cause flakey tests, since they may break after any update or change of the os.
Sorry for not having a solution for this issue. maven can be a bitch. On other systems I had the experience (not exactly with OpenPDF), that sometimes the result of a test may vary, whether you run it individually in your IDE, or all the test from your IDE (without maven) or from the command line. If you find a solution for this, just drop a PR. I'll be glad merge it.
If nothing can solve this problem, we may ignore the test on MacOS. Maybe you can try using: org.junit.jupiter.api.condition.DisabledOnOs