Test-BOM
view release on metacpan or search on metacpan
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
0.001 2018-09-26 09:36:12 Europe/Berlin
[Added]
Initial version that introduces functions to test string and files for
byte-order-marks (BOM).
This is the Perl distribution Test-BOM.
Installing Test-BOM is straightforward.
## Installation with cpanm
If you have cpanm, you only need one line:
% cpanm Test::BOM
If it does not have permission to install modules to the current perl, cpanm
will automatically set up and install to a local::lib in your home directory.
See the local::lib documentation (https://metacpan.org/pod/local::lib) for
details on enabling it in your environment.
## Installing with the CPAN shell
Alternatively, if your CPAN shell is set up, you should just be able to do:
% cpan Test::BOM
## Manual installation
As a last resort, you can manually install it. Download the tarball, untar it,
then build it:
% perl Makefile.PL
% make && make test
Then install it:
% make install
If your perl is system-managed, you can create a local::lib in your home
directory to install modules to. For details, see the local::lib documentation:
https://metacpan.org/pod/local::lib
## Documentation
Test-BOM documentation is available as POD.
You can run perldoc from a shell to read the documentation:
% perldoc Test::BOM
# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.009.
Changes
INSTALL
LICENSE
MANIFEST
META.yml
Makefile.PL
README
cpanfile
dist.ini
lib/Test/BOM.pm
lib/Test/BOM.pm~
perlcritic.rc
t/author-critic.t
t/author-no-tabs.t
t/author-pod-coverage.t
t/author-pod-syntax.t
t/bom.t
t/bom.t~
t/release-changes_has_content.t
---
abstract: 'Test strings and files for byte order mark (BOM).'
author:
- 'Gregor Goldbach <glauschwuffel@gmail.com>'
build_requires:
Path::Tiny: '0'
Test::More: '0'
Test::Tester: '0'
perl: '5.006'
configure_requires:
ExtUtils::MakeMaker: '0'
perl: '5.006'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.009, CPAN::Meta::Converter version 2.150005'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Test-BOM
requires:
String::BOM: '0'
Test::Builder::Module: '0'
base: '0'
perl: '5.006'
strict: '0'
warnings: '0'
version: '0.001'
x_serialization_backend: 'YAML::Tiny version 1.69'
Makefile.PL view on Meta::CPAN
# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.009.
use strict;
use warnings;
use 5.006;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
"ABSTRACT" => "Test strings and files for byte order mark (BOM).",
"AUTHOR" => "Gregor Goldbach <glauschwuffel\@gmail.com>",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "Test-BOM",
"LICENSE" => "perl",
"MIN_PERL_VERSION" => "5.006",
"NAME" => "Test::BOM",
"PREREQ_PM" => {
"String::BOM" => 0,
"Test::Builder::Module" => 0,
"base" => 0,
"strict" => 0,
"warnings" => 0
},
"TEST_REQUIRES" => {
"Path::Tiny" => 0,
"Test::More" => 0,
"Test::Tester" => 0
},
"VERSION" => "0.001",
"test" => {
"TESTS" => "t/*.t"
}
);
my %FallbackPrereqs = (
"Path::Tiny" => 0,
"String::BOM" => 0,
"Test::Builder::Module" => 0,
"Test::More" => 0,
"Test::Tester" => 0,
"base" => 0,
"strict" => 0,
"warnings" => 0
);
unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
SYNOPSIS
use Test::More;
use Test::BOM
string_has_bom("\x00\x00\xfe\xff");
string_hasnt_bom("blargh");
file_has_bom('t/data/foo');
file_hasnt_bom('t/data/bar');
DESCRIPTION
This module helps you with testing for byte-order-marks in strings and
with byte-order-marks you might find what you need in the "SEE ALSO"
section below.
If you don't know anything about automated testing in Perl then you
should read about Test::More before preceding. This module uses the
Test::Builder framework.
Byte-order-marks are by definition to be found at the beginning of any
content, so the functions this module provides take a look at the start
of either a string or a file. It does this by using functions from
String::BOM and basically just wraps them for use with Test::Builder.
By default the following functions are imported into your namespace:
string_has_bom, string_hasnt_bom, file_has_bom, file_hasnt_bom.
FUNCTIONS
string_has_bom ($string)
Passes if the string has a BOM, fails if not.
string_hasnt_bom ($string)
Passes if string doesn't have a BOM, fails if it has.
file_has_bom ($filename)
Passes if the file has a BOM, fails if it doesn't.
file_hasnt_bom ($filename)
Passes if the file doesn't have a BOM, fails if it has.
SEE ALSO
There are some distributions that help you dealing with BOMs in
different ways:
String::BOM is used by this module to check for BOM.
File::BOM::Utils contains functions to check for, add and remove BOM
from files.
File::BOM can be used to actually read from files that have BOMs as
seamlessly as possible.
PPI::Token::BOM represents a BOM when using PPI to parse perl.
The distribution Dist::Zilla::Plugin::Web contains the module
Dist::Zilla::Plugin::Web::StripBOM that strips BOM from files.
Additional information about BOM and it's usage:
http://www.unicode.org/faq/utf_bom.html#BOM is the FAQ for the BOM from
the Unicode Consortium.
https://docs.microsoft.com/de-de/windows/desktop/Intl/using-byte-order-marks
explains how Microsoft wants the BOM to be used. Since this document
dates from 2018 (as of this writing) it's very likely to get in contact
with files containing BOM.
requires 'Dist::Zilla::Plugin::PodSyntaxTests';
requires 'Dist::Zilla::Plugin::PodWeaver';
requires 'Dist::Zilla::Plugin::ReadmeFromPod';
requires 'Dist::Zilla::Plugin::ShareDir';
requires 'Dist::Zilla::Plugin::Test::ChangesHasContent';
requires 'Dist::Zilla::Plugin::Test::NoTabs';
requires 'Dist::Zilla::Plugin::Test::Perl::Critic';
requires 'Dist::Zilla::PluginBundle::Basic';
requires 'Dist::Zilla::PluginBundle::Git';
requires 'Dist::Zilla::App::Command::cover';
requires 'String::BOM' => 0;
requires 'Test::Builder' => 0;
requires 'Test::Pod::Coverage' => 0;
requires 'Test::NoTabs' => 0;
on 'test' => sub {
requires 'Path::Tiny' => 0;
requires 'Test::Tester' => 0;
};
name = Test-BOM
version = 0.001
abstract = Test strings and files for byte order mark (BOM).
author = Gregor Goldbach <glauschwuffel@gmail.com>
main_module = lib/Test/BOM.pm
license = Perl_5
copyright_holder = Gregor Goldbach
[@Basic]
[AutoPrereqs]
[Prereqs]
[MinimumPerl]
[PkgVersion]
[CheckChangesHasContent]
lib/Test/BOM.pm view on Meta::CPAN
package Test::BOM;
$Test::BOM::VERSION = '0.001';
# ABSTRACT: Test strings and files for BOM
use strict;
use warnings;
use base qw(Test::Builder::Module);
our @EXPORT = qw(string_has_bom string_hasnt_bom file_has_bom file_hasnt_bom);
# We have subs of the same name, don't import them
use String::BOM qw();
my $CLASS = __PACKAGE__;
my $Tester = $CLASS->builder;
sub string_has_bom {
my ($string) = @_;
my $ok = String::BOM::string_has_bom($string);
$Tester->ok( $ok, q{string has BOM} );
unless ($ok) {
$Tester->diag('String was expected to have a BOM but did not.');
}
return $ok;
}
sub string_hasnt_bom {
my ($string) = @_;
my $ok = String::BOM::string_has_bom($string);
$Tester->ok( !$ok, q{string hasn't BOM} );
if ($ok) {
$Tester->diag('String was expected not to have a BOM but it has.');
}
return !$ok;
}
sub file_has_bom {
my ($string) = @_;
my $ok = String::BOM::file_has_bom($string);
$Tester->ok( $ok, q{file has BOM} );
unless ($ok) {
$Tester->diag('File was expected to have a BOM but did not.');
}
return $ok;
}
sub file_hasnt_bom {
my ($string) = @_;
my $ok = String::BOM::file_has_bom($string);
$Tester->ok( !$ok, q{file has BOM} );
if ($ok) {
$Tester->diag('File was expected to not have a BOM but it has.');
}
return !$ok;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Test::BOM - Test strings and files for BOM
=head1 VERSION
version 0.001
=head1 SYNOPSIS
use Test::More;
use Test::BOM
string_has_bom("\x00\x00\xfe\xff");
string_hasnt_bom("blargh");
file_has_bom('t/data/foo');
file_hasnt_bom('t/data/bar');
=head1 DESCRIPTION
This module helps you with testing for byte-order-marks in strings and files.
lib/Test/BOM.pm view on Meta::CPAN
If you came across this module while looking for other ways to deal with
byte-order-marks you might find what you need in the L</"SEE ALSO"> section
below.
If you don't know anything about automated testing in Perl then you should read
about L<Test::More> before preceding. This module uses the L<Test::Builder>
framework.
Byte-order-marks are by definition to be found at the beginning of any content,
so the functions this module provides take a look at the start of either a
string or a file. It does this by using functions from L<String::BOM> and basically just wraps them for use with L<Test::Builder>.
By default the following functions are imported into your namespace: C<string_has_bom>, C<string_hasnt_bom>, C<file_has_bom>, C<file_hasnt_bom>.
=head1 FUNCTIONS
=head2 string_has_bom ($string)
Passes if the string has a BOM, fails if not.
=head2 string_hasnt_bom ($string)
Passes if string doesn't have a BOM, fails if it has.
=head2 file_has_bom ($filename)
Passes if the file has a BOM, fails if it doesn't.
=head2 file_hasnt_bom ($filename)
Passes if the file doesn't have a BOM, fails if it has.
=head1 SEE ALSO
There are some distributions that help you dealing with BOMs in different ways:
=over 4
=item L<String::BOM> is used by this module to check for BOM.
=item L<File::BOM::Utils> contains functions to check for, add and remove BOM
from files.
=item L<File::BOM> can be used to actually read from files that have BOMs as seamlessly as possible.
=item L<PPI::Token::BOM> represents a BOM when using L<PPI> to parse perl.
=item The distribution L<Dist::Zilla::Plugin::Web> contains the module
L<Dist::Zilla::Plugin::Web::StripBOM> that strips BOM from files.
=back
Additional information about BOM and it's usage:
=over 4
=item L<http://www.unicode.org/faq/utf_bom.html#BOM> is the FAQ for the
BOM from the Unicode Consortium.
=item L<https://docs.microsoft.com/de-de/windows/desktop/Intl/using-byte-order-marks>
explains how Microsoft wants the BOM to be used. Since this document dates from
2018 (as of this writing) it's very likely to get in contact with files
containing BOM.
=back
=head1 AUTHOR
Gregor Goldbach <glauschwuffel@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Gregor Goldbach.
t/author-no-tabs.t view on Meta::CPAN
use strict;
use warnings;
# this test was generated with Dist::Zilla::Plugin::Test::NoTabs 0.15
use Test::More 0.88;
use Test::NoTabs;
my @files = (
'lib/Test/BOM.pm', 't/author-critic.t',
't/author-no-tabs.t', 't/author-pod-coverage.t',
't/author-pod-syntax.t', 't/bom.t',
't/bom.t~', 't/release-changes_has_content.t'
);
notabs_ok($_) foreach @files;
done_testing;
## Please see file perltidy.ERR
## Please see file perltidy.ERR
use strict;
use warnings;
use Test::Tester;
use Test::More;
use Test::BOM;
use Path::Tiny qw(tempfile path);
# http://www.unicode.org/faq/utf_bom.html#BOM
# http://search.cpan.org/perldoc?PPI::Token::BOM
our $boms = {
'UTF-32, big-endian' => "\x00\x00\xfe\xff",
'UTF-32, little-endian' => "\xff\xfe\x00\x00",
'UTF-16, big-endian' => "\xfe\xff",
'UTF-16, little-endian' => "\xff\xfe",
'UTF-8' => "\xef\xbb\xbf"
};
subtest 'test for BOM in strings' => sub {
for my $kind ( sort keys %$boms ) {
check_test( sub { string_has_bom( $boms->{$kind} ) }, { ok => 1 } );
}
check_test( sub { string_has_bom('no bom') }, { ok => 0 } );
};
subtest 'test if BOM is not in strings' => sub {
for my $kind ( sort keys %$boms ) {
check_test( sub { string_hasnt_bom( $boms->{$kind} ) }, { ok => 0 } );
}
check_test( sub { string_hasnt_bom('no bom') }, { ok => 1 } );
};
subtest 'test for BOM in files' => sub {
for my $bom ( sort values %$boms ) {
my $f = tempfile();
my $file = path($f)->stringify;
$f->append_raw($bom);
check_test( sub { file_has_bom($file) }, { ok => 1 } );
}
my $f = tempfile();
my $file = path($f)->stringify;
$f->append_raw('no bom');
check_test( sub { file_has_bom($file) }, { ok => 0 } );
};
subtest 'test if BOM is not in files' => sub {
for my $bom ( sort values %$boms ) {
my $f = tempfile();
my $file = path($f)->stringify;
$f->append_raw($bom);
check_test( sub { file_hasnt_bom($file) }, { ok => 0 } );
}
my $f = tempfile();
my $file = path($f)->stringify;
( run in 0.527 second using v1.01-cache-2.11-cpan-131fc08a04b )