Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RT 103157 - t/oo-api.t failures under Mac OS #7

Closed
wants to merge 3 commits into from
Closed

RT 103157 - t/oo-api.t failures under Mac OS #7

wants to merge 3 commits into from

Conversation

trwyant
Copy link

@trwyant trwyant commented Oct 18, 2017

The problem here is that libmagic is not very forthcoming on what the default magic file is, so the test looks in the usual place. Apple has for reasons of their own modified the file command and the underlying magic file, which lives in the usual place. So we need a way to find the default magic file for the copy of libmagic that is actually being linked into File::LibMagic.

This pull request attempts to address this issue. The approach used is two-fold.

The first commit adds Apple's description of a C source file to the test, and under macOS 10.13 High Sierra is sufficient to get the test to pass. The offset errors appearing in earlier versions of macOS (as they style it now) appear to have gone away, and I think were cosmetic anyway.

The second commit scrapes the output of 'file -v' (after deleting $ENV{MAGIC}) to try to get a better idea of what the default magic file is. This is not ideal, and assumes the file command we are running goes with the libmagic we are linking against. But the API that would otherwise be more desirable for this is undocumented, which makes me nervous about using it in production code. The third commit simply tweaks the second in response to some perltidy errors.

This works back to 3.28, which is more than we need because libmagic
itself was not introduced until 4.0 (author date 2003-03-24). But we
have to delete $ENV{MAGIC} to get the answer we want, otherwise we may
just get the contents of that environment variable.

THe libmagic library contains magic_getpath() which can also be used to
access this information (again after deleting $ENV{MAGIC}). But this is
undocumentedm and was not introduced until 5.06 (author date
2011-04-14).
These were two 'no critic' annotations.

The failure to initialize an 'our' variable was annotated because I was
localizing $ENV{MAGIC} prior to deleting it.

The use of back ticks rather than IPC::Open3 may be less defensible, but
I annotated it because I did not want to introduce a new testing
dependency. Yes, IPC::Open3 is core, but I have before run into
repackagers who remove core modules from their Perl packages, and make
you re-install them if you want them.
@autarch
Copy link
Member

autarch commented Oct 22, 2017

What is the point of localizing the env var only to delete it?

@autarch
Copy link
Member

autarch commented Oct 22, 2017

I merged this from the CLI. Thanks!

@autarch autarch closed this Oct 22, 2017
@trwyant
Copy link
Author

trwyant commented Oct 23, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants