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

Fix failing tests with some versions of libmagic #5

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 11 additions & 9 deletions t/constructor-params.t
Expand Up @@ -24,15 +24,17 @@ use File::LibMagic;
my $info = File::LibMagic->new( follow_symlinks => 1 )
->info_from_filename($link_file);

is_deeply(
$info, {
description => 'PDF document, version 1.4',
mime_type => 'application/pdf',
encoding => 'binary',
mime_with_encoding => 'application/pdf; charset=binary',
},
'got expected info for symlink to PDF'
);
if(is(ref $info, 'HASH', 'is hash')) {
is_deeply([ sort keys %$info ],
[qw[ description encoding mime_type mime_with_encoding ]],
'keys');
is($info->{description}, 'PDF document, version 1.4', 'description');
is($info->{mime_type}, 'application/pdf', 'mime type');
like($info->{encoding}, qr/^(?:binary|unknown)$/, 'encoding');
like($info->{mime_with_encoding},
qr%^application/pdf; charset=(?:binary|unknown)$%,
'mime with charset');
}
}

{
Expand Down
14 changes: 7 additions & 7 deletions t/oo-api.t
Expand Up @@ -13,17 +13,17 @@ use File::LibMagic;
'foo.foo' => [
'ASCII text',
'text/plain',
'us-ascii',
qr/us-ascii/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this change addressing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to be consistent. Encoding is now a regex always.

],
'foo.c' => [
[ 'ASCII C program text', 'C source, ASCII text' ],
'text/x-c',
'us-ascii',
qr/us-ascii/,
],
'tiny.pdf' => [
'PDF document, version 1.4',
'application/pdf',
'binary',
qr/binary|unknown/,
],
);

Expand Down Expand Up @@ -224,15 +224,15 @@ sub _test_info {
'mime_type',
);

is(
like(
$info->{encoding},
$encoding,
qr/^(?:$encoding)$/,
'encoding'
);

is(
like(
$info->{mime_with_encoding},
"$mime; charset=$encoding",
qr/^$mime; charset=(?:$encoding)$/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parens here aren't doing anything, and turning this into a regex doesn't seem to change the test at all, from my reading. The regex as written would be identical to comparing two strings, unless the interpolated variables contain regex metacharacters. Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the qr/binary|unknown/ (line 26), it makes the tests pass on my machine.

'mime_with_encoding'
);
}
Expand Down