Test failures in File::LibMagic

My June assignment for the CPAN Pull Request Challenge was File::LibMagic. The module had 50 FAIL reports at CPAN Testers, so I decided to start from them.

The first thing I noticed about the failures was they all came from OpenBSD. It scared me a bit, as the only experience with the OS I had was the test failure reports for XML::XSH2 few years ago which I wasn’t able to reproduce on any other OS I could reach and which disappeared with the following releases of the module and the system, proving the underlying C libraries guilty of the problems.

I spent some time pondering two ways how to get access to OpenBSD—running it in a virtual machine, or getting an account at Devio.us. Both ways seemed complicated enough to postpone the problem until the very end of the month, when I had to do something to stay in the game.

Therefore, on the evening of June the 30th, I finally cloned the repository from GitHub. At first, I couldn’t run the tests at all, as I didn’t know what package contained the needed header file. There already was a magic.h under /usr/include/linux, but it wasn’t the right one. After several attempts, I found out I needed the file-devel package, which provided /usr/include/magic.h.

Before midnight, I was ready to run the tests—only to discover the OS was just a red herring, as I got exactly the same failures on my Linux box (OpenSUSE 13.1): for PDFs, the file type was reported correctly as application/pdf, but its charset was reported as unknown instead of the expected binary.

I changed the tests to check the charset with a regular expression instead of a string eq, and made it accept both possibilities for PDFs:

        qr%^application/pdf; charset=(?:binary|unknown)$%,
        'mime with charset');

All the tests passed on my machine, so I submitted a pull request.
Automated tests at Travis CI failed on PerlCritic, though: it didn't like the % as a regex delimiter (only // and {} are accepted, but / would need to be escaped in application/pdf, and I don’t like {} as delimiters, as newer Perl versions are more strict about backspacing curly braces in regexes). Well, let the author decide what to do…

Update: Merged!

Leave a comment

About E. Choroba

user-pic I blog about Perl.