houseabsolute / File-LibMagic

Determine MIME types of data or files using libmagic
http://metacpan.org/release/File-LibMagic/
Other
7 stars 6 forks source link

macos: Failed test 'checktype_filename t/samples/foo.c' at t/oo-api.t #30

Open hakonhagland opened 1 year ago

hakonhagland commented 1 year ago

Hi, I am trying to install File::LibMagic on macOS 12.4, M1 using homebrew perl version 5.34.0, and installed version 5.43 of libmagic using brew install libmagic. Downloaded version 1.23 of File::LibMagic here: https://cpan.metacpan.org/authors/id/D/DR/DROLSKY/File-LibMagic-1.23.tar.gz

$ perl Makefile.PL --include /opt/homebrew/Cellar/libmagic/5.43/include --lib /opt/homebrew/Cellar/libmagic/5.43/lib
Checking for magic.h... Checking for cc... cc
yes
Checking for magic.h... (cached) yes
Checking for magic_open in -lmagic... yes
Checking for magic_version in -lmagic... yes
Checking for magic_setparam in -lmagic... yes
Checking for magic_getparam in -lmagic... yes
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for File::LibMagic
Writing MYMETA.yml and MYMETA.json

$ make

[...]

 $ make test
"/opt/homebrew/Cellar/perl/5.34.0/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- LibMagic.bs blib/arch/auto/File/LibMagic/LibMagic.bs 644
PERL_DL_NONLAZY=1 "/opt/homebrew/Cellar/perl/5.34.0/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/old-apis/*.t
t/00-report-prereqs.t ................... #
# Versions for all modules listed in MYMETA.json (including optional ones):
#
# === Configure Requires ===
#
#     Module              Want     Have
#     ------------------- ---- --------
#     Config::AutoConf     any    0.320
#     ExtUtils::CBuilder   any 0.280236
#     ExtUtils::MakeMaker  any     7.62
#
# === Build Requires ===
#
#     Module              Want Have
#     ------------------- ---- ----
#     ExtUtils::MakeMaker  any 7.62
#
# === Test Requires ===
#
#     Module              Want     Have
#     ------------------- ---- --------
#     Cwd                  any     3.80
#     ExtUtils::MakeMaker  any     7.62
#     File::Spec           any     3.80
#     File::Temp           any   0.2311
#     FindBin              any     1.52
#     Test::Fatal          any    0.016
#     Test::More          0.96 1.302183
#     base                 any     2.27
#     lib                  any     0.65
#
# === Test Recommends ===
#
#     Module         Want     Have
#     ---------- -------- --------
#     CPAN::Meta 2.120900 2.150010
#
# === Runtime Requires ===
#
#     Module       Want Have
#     ------------ ---- ----
#     Carp          any 1.52
#     Exporter      any 5.76
#     List::Util    any 1.63
#     Scalar::Util  any 1.63
#     XSLoader      any 0.30
#     strict        any 1.12
#     warnings      any 1.51
#
t/00-report-prereqs.t ................... ok
t/constructor-params.t .................. ok
t/old-apis/all-exports.t ................ ok
t/old-apis/complete-interface-errors.t .. ok
t/old-apis/complete-interface.t ......... ok
t/old-apis/easy-interface.t ............. ok
t/oo-api.t .............................. 1/? /Users/hakonhaegland/perl/install-cpan-modules/File-LibMagic-1.23/t/samples/magic, 2: Warning: using regular magic file `/usr/share/file/magic.mgc'
/usr/share/file/magic.mgc, 1: Warning: offset `�' invalid
Version=' invalidagic.mgc, 2: Warning: offset `
/usr/share/file/magic.mgc, 3: Warning: offset `' invalid
/usr/share/file/magic.mgc, 6: Warning: offset `Firmware v' invalid
/usr/share/file/magic.mgc, 12: Warning: offset `' invalid
Corel Corporation' invalid 13: Warning: offset `
/usr/share/file/magic.mgc, 15: Warning: offset `::[ frontEndVersion = ' invalid
/usr/share/file/magic.mgc, 16: Warning: offset `' invalid
' invalide/file/magic.mgc, 22: Warning: offset `
/usr/share/file/magic.mgc, 24: Warning: offset `' invalid
/usr/share/file/magic.mgc, 25: Warning: offset `East_Side_Invertationa' invalid
/usr/share/file/magic.mgc, 33: Warning: offset `Takahiro_Laboratories' invalid
/usr/share/file/magic.mgc, 34: Warning: offset `The_Incinerator_Plant' invalid
/usr/share/file/magic.mgc, 35: Warning: offset `<protocol bbn-m' invalid
/usr/share/file/magic.mgc, 36: Warning: offset `The_Seventh_Precinct' invalid
/usr/share/file/magic.mgc, 37: Warning: offset `the_Slipgate_Complex' invalid
/usr/share/file/magic.mgc, 38: Warning: offset `Castle_of_the_Damned' invalid
/usr/share/file/magic.mgc, 39: Warning: offset `the_Dismal_Oubliette' invalid
/usr/share/file/magic.mgc, 40: Warning: offset `Satan's_Dark_Delight' invalid
/usr/share/file/magic.mgc, 41: Warning: offset `The_Tower_of_Despair' invalid
/usr/share/file/magic.mgc, 42: Warning: offset `The_Elder_God_Shrine' invalid
/usr/share/file/magic.mgc, 43: Warning: offset `Shub-Niggurath's_Pit' invalid
/usr/share/file/magic.mgc, 44: Warning: offset `The_Gremlin's_Domain' invalid
/usr/share/file/magic.mgc, 45: Warning: offset `the_Edge_of_Oblivion' invalid
/usr/share/file/magic.mgc, 46: Warning: offset `Termination_Central' invalid
/usr/share/file/magic.mgc, 47: Warning: offset `Chambers_of_Torment' invalid
/usr/share/file/magic.mgc, 48: Warning: offset `The_House_of_Chthon' invalid
/usr/share/file/magic.mgc, 49: Warning: offset `The_Pumping_Station' invalid
/usr/share/file/magic.mgc, 51: Warning: offset `The_Underwater_Base' invalid
/usr/share/file/magic.mgc, 52: Warning: offset `' invalid
/usr/share/file/magic.mgc, 53: Warning: offset `The_Black_Cathedral' invalid
/usr/share/file/magic.mgc, 54: Warning: offset `Place_of_Two_Deaths' invalid
/usr/share/file/magic.mgc, 56: Warning: offset `the_Wizard's_Manse' invalid
/usr/share/file/magic.mgc, 57: Warning: offset `the_Crypt_of_Decay' invalid
/usr/share/file/magic.mgc, 58: Warning: offset `The_Abandoned_Base' invalid
/usr/share/file/magic.mgc, 59: Warning: offset `Claustrophobopolis' invalid
/usr/share/file/magic.mgc, 60: Warning: offset `the_Palace_of_Hate' invalid
/usr/share/file/magic.mgc, 61: Warning: offset `the_Tomb_of_Terror' invalid
/usr/share/file/magic.mgc, 62: Warning: offset `The_Door_To_Chthon' invalid
/usr/share/file/magic.mgc, 63: Warning: offset `the_Ebon_Fortress' invalid
/usr/share/file/magic.mgc, 64: Warning: offset `__________E' invalid
/usr/share/file/magic.mgc, 66: Warning: offset `Research_Facility' invalid
/usr/share/file/magic.mgc, 68: Warning: offset `the_Nameless_City' invalid
/usr/share/file/magic.mgc, 69: Warning: offset `the_Sewage_System' invalid
/usr/share/file/magic.mgc, 70: Warning: offset `the_Grisly_Grotto' invalid

[...]

/usr/share/file/magic.mgc, 3242: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3243: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3244: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3245: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3246: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3247: Warning: offset `�(���' invalid
/usr/share/file/magic.mgc, 3248: Warning: offset `�(���' invalid
/usr/share/file/magic.mgc, 3249: Warning: offset `�Z�' invalid
/usr/share/file/magic.mgc, 3250: Warning: offset `�p' invalid
/usr/share/file/magic.mgc, 3262: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3266: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3267: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3276: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3427: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3435: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3436: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3456: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3457: Warning: offset `[' invalid
/usr/share/file/magic.mgc, 3458: Warning: offset `' invalid
/usr/share/file/magic.mgc, 3459: Warning: offset `[' invalid
/usr/share/file/magic.mgc, 3463: Warning: offset `.' invalid
/usr/share/file/magic.mgc, 3476: Warning: offset `' invalid

        #   Failed test 'checktype_filename /Users/hakonhaegland/perl/install-cpan-modules/File-LibMagic-1.23/t/samples/foo.c'
        #   at t/oo-api.t line 154.
        #                   'text/plain; charset=us-ascii'
        #     doesn't match '(?^:text/x-c(?:; charset=us-ascii)?)'

        #   Failed test 'describe_filename /Users/hakonhaegland/perl/install-cpan-modules/File-LibMagic-1.23/t/samples/foo.c'
        #   at t/oo-api.t line 137.
        #          got: ASCII text
        #     expected: any one of ...
        #              ASCII C program text
        #              C source, ASCII text
        #              c program, ASCII text

        #   Failed test 'checktype_contents /Users/hakonhaegland/perl/install-cpan-modules/File-LibMagic-1.23/t/samples/foo.c'
        #   at t/oo-api.t line 170.
        #                   'text/plain; charset=us-ascii'
        #     doesn't match '(?^:text/x-c(?:; charset=us-ascii)?)'

        #   Failed test 'checktype_contents /Users/hakonhaegland/perl/install-cpan-modules/File-LibMagic-1.23/t/samples/foo.c as ref'
        #   at t/oo-api.t line 176.
        #                   'text/plain; charset=us-ascii'
        #     doesn't match '(?^:text/x-c(?:; charset=us-ascii)?)'

        #   Failed test 'describe_contents /Users/hakonhaegland/perl/install-cpan-modules/File-LibMagic-1.23/t/samples/foo.c'
        #   at t/oo-api.t line 137.
        #          got: ASCII text
        #     expected: any one of ...
        #              ASCII C program text
        #              C source, ASCII text
        #              c program, ASCII text

        #   Failed test 'describe_contents /Users/hakonhaegland/perl/install-cpan-modules/File-LibMagic-1.23/t/samples/foo.c as ref'
        #   at t/oo-api.t line 137.
        #          got: ASCII text
        #     expected: any one of ...
        #              ASCII C program text
        #              C source, ASCII text
        #              c program, ASCII text
        # Looks like you failed 6 tests of 6.

    #   Failed test 'old API with /Users/hakonhaegland/perl/install-cpan-modules/File-LibMagic-1.23/t/samples/foo.c'
    #   at t/oo-api.t line 138.

            #   Failed test 'description'
            #   at t/oo-api.t line 204.
            #          got: ASCII text
            #     expected: any one of ...
            #              ASCII C program text
            #              C source, ASCII text
            #              c program, ASCII text

            #   Failed test 'mime_type'
            #   at t/oo-api.t line 273.
            #          got: 'text/plain'
            #     expected: 'text/x-c'

            #   Failed test 'mime_with_encoding'
            #   at t/oo-api.t line 285.
            #                   'text/plain; charset=us-ascii'
            #     doesn't match '(?^:^text/x-c; charset=us-ascii$)'
            # Looks like you failed 3 tests of 4.

        #   Failed test 'info_from_filename'
        #   at t/oo-api.t line 206.

            #   Failed test 'description'
            #   at t/oo-api.t line 214.
            #          got: ASCII text
            #     expected: any one of ...
            #              ASCII C program text
            #              C source, ASCII text
            #              c program, ASCII text

            #   Failed test 'mime_type'
            #   at t/oo-api.t line 273.
            #          got: 'text/plain'
            #     expected: 'text/x-c'

            #   Failed test 'mime_with_encoding'
            #   at t/oo-api.t line 285.
            #                   'text/plain; charset=us-ascii'
            #     doesn't match '(?^:^text/x-c; charset=us-ascii$)'
            # Looks like you failed 3 tests of 4.

        #   Failed test 'info_from_string'
        #   at t/oo-api.t line 216.

            #   Failed test 'description'
            #   at t/oo-api.t line 225.
            #          got: ASCII text
            #     expected: any one of ...
            #              ASCII C program text
            #              C source, ASCII text
            #              c program, ASCII text

            #   Failed test 'mime_type'
            #   at t/oo-api.t line 273.
            #          got: 'text/plain'
            #     expected: 'text/x-c'

            #   Failed test 'mime_with_encoding'
            #   at t/oo-api.t line 285.
            #                   'text/plain; charset=us-ascii'
            #     doesn't match '(?^:^text/x-c; charset=us-ascii$)'
            # Looks like you failed 3 tests of 4.

        #   Failed test 'info_from_string as ref'
        #   at t/oo-api.t line 227.

            #   Failed test 'description'
            #   at t/oo-api.t line 233.
            #          got: ASCII text
            #     expected: any one of ...
            #              ASCII C program text
            #              C source, ASCII text
            #              c program, ASCII text

            #   Failed test 'mime_type'
            #   at t/oo-api.t line 273.
            #          got: 'text/plain'
            #     expected: 'text/x-c'

            #   Failed test 'mime_with_encoding'
            #   at t/oo-api.t line 285.
            #                   'text/plain; charset=us-ascii'
            #     doesn't match '(?^:^text/x-c; charset=us-ascii$)'
            # Looks like you failed 3 tests of 5.

        #   Failed test 'info_from_handle'
        #   at t/oo-api.t line 241.

            #   Failed test 'description'
            #   at t/oo-api.t line 252.
            #          got: ASCII text
            #     expected: any one of ...
            #              ASCII C program text
            #              C source, ASCII text
            #              c program, ASCII text

            #   Failed test 'mime_type'
            #   at t/oo-api.t line 273.
            #          got: 'text/plain'
            #     expected: 'text/x-c'

            #   Failed test 'mime_with_encoding'
            #   at t/oo-api.t line 285.
            #                   'text/plain; charset=us-ascii'
            #     doesn't match '(?^:^text/x-c; charset=us-ascii$)'
            # Looks like you failed 3 tests of 4.

        #   Failed test 'info_from_handle - handle from scalar ref'
        #   at t/oo-api.t line 256.
        # Looks like you failed 5 tests of 5.

    #   Failed test 'new API with /Users/hakonhaegland/perl/install-cpan-modules/File-LibMagic-1.23/t/samples/foo.c'
    #   at t/oo-api.t line 143.
    # Looks like you failed 2 tests of 4.

#   Failed test 'custom magic file'
#   at t/oo-api.t line 90.
# Looks like you failed 1 test of 3.
t/oo-api.t .............................. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/3 subtests
t/version.t ............................. # libmagic version 543
t/version.t ............................. ok

Test Summary Report
-------------------
t/oo-api.t                            (Wstat: 256 Tests: 3 Failed: 1)
  Failed test:  2
  Non-zero exit status: 1
Files=8, Tests=33,  1 wallclock secs ( 0.02 usr  0.01 sys +  0.33 cusr  0.06 csys =  0.42 CPU)
Result: FAIL
Failed 1/8 test programs. 1/33 subtests failed.
make: *** [test_dynamic] Error 255
autarch commented 1 year ago

I'm not sure what's going on here since I haven't used brew. Was the /usr/share/file/magic.mgc file installed by brew?

If it's like the one on my Linux system, the magic.mgc file should be 5-6MB in size and running file on it reports this:

$> file /usr/lib/file/magic.mgc 
/usr/lib/file/magic.mgc: magic binary file for file(1) cmd (version 14) (little endian)

I'd be curious to see the output for your file.

I'm guessing the test failures where it's checking for the content type are because it can't load this magic file.

sdondley commented 7 months ago

i'm seeing the same problem. Homebrew installed magic.mgc at this path: /homebrew/Cellar/libmagic/5.45/share/misc/magic.mgc

output of file command is /opt/homebrew/Cellar/libmagic/5.45/share/misc/magic.mgc: magic binary file for file(1) cmd (version 18) (little endian)

What do I do with it, exactly?

kstarsinic commented 1 week ago

Same problem here:

$ file /usr/share/file/magic.mgc
/usr/share/file/magic.mgc: magic binary file for file(1) cmd (version 16) (little endian)
$ uname -v
Darwin Kernel Version 24.0.0: Tue Sep 24 23:38:45 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T8122