Giter Site home page Giter Site logo

test-pretty's Introduction

NAME

Test::Pretty - Smile Precure!

SYNOPSIS

use Test::Pretty;

DESCRIPTION

Test::Pretty is a prettifier for Test::More.

When you are writing a test case such as following:

use strict;
use warnings;
use utf8;
use Test::More;

subtest 'MessageFilter' => sub {
    my $filter = MessageFilter->new('foo');

    subtest 'should detect message with NG word' => sub {
        ok($filter->detect('hello from foo'));
    };
    subtest 'should not detect message without NG word' => sub {
        ok(!$filter->detect('hello world!'));
    };
};

done_testing;

This code outputs following result:

No, it's not readable. Test::Pretty makes this result to pretty.

You can enable Test::Pretty by

use Test::Pretty;

Or just add following option to perl interpreter.

-MTest::Pretty

After this, you can get a following pretty output.

And this module outputs TAP when $ENV{HARNESS_ACTIVE} is true or under the win32.

AUTHOR

Tokuhiro Matsuno <tokuhirom AAJKLFJEF@ GMAIL COM>

THANKS TO

Some code was taken from Test::Name::FromLine, thanks cho45++

SEE ALSO

Acme::PrettyCure

LICENSE

Copyright (C) Tokuhiro Matsuno

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

test-pretty's People

Contributors

akiym avatar charsbar avatar gunyarakun avatar lejeunerenard avatar mattn avatar moznion avatar neilb avatar omega avatar tokuhirom avatar valchonedelchev avatar zmughal avatar zoffixznet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

test-pretty's Issues

prettifies only Test::Simple/Test::More tests, but not arbitrary TAP

file simple.t

use Test::Simple tests => 1;
ok 1, 'some test';

file more.t

use Test::More;
ok 1, 'some test';
done_testing;

Running these tests produces the pretty output with colours, checkmarks and fat arrows around filenames – as expected.

$ prove -v -Pretty simple.t more.t

==> simple.t <==

✓  some test

ok

==> more.t <====

✓  some test

ok
All tests successful.
Files=2, Tests=2,  0 wallclock secs ( 0.03 usr  0.00 sys +  0.09 cusr  0.00 csys =  0.12 CPU)
Result: PASS

If TAP is generated in other ways, Test::Pretty fails to do its work.

file manual-tap.t

#!/usr/bin/perl
print <<'END'
ok 1 - some test
1..1
END

No colours/checkmarks:

$ prove -v -Pretty manual-tap.t

ok 1 - some test
1..1

ok
All 1 subtests passed

Non-Perl TAP generation:

file manual-tap.sh

#!/bin/sh
echo "ok 1 - some test"
echo "1..1"

No colours/checkmarks:

$ prove -v -Pretty -e sh manual-tap.sh

ok 1 - some test
1..1

Recorded TAP stream:

file manual-tap.tap

ok 1 - some test
1..1

No colours/checkmarks:

$ prove -v -Pretty -e cat manual-tap.tap

ok 1 - some test
1..1

Streaming TAP into pipe:

$ printf "ok 1 - some test\n1..1\n" | prove -v -Pretty -e 'cat -' /dev/null

Checkmark is missing.

==> /dev/null <==

ok 1 - some test
1..1
All tests successful.
Files=1, Tests=1,  0 wallclock secs ( 0.02 usr +  0.00 sys =  0.02 CPU)
Result: PASS

exception in subtest is ignored...

prove -Pretty -lv against following code will print All 1 subtests passed! But expect FAIL

use strict;
use warnings;

use Test::More;

subtest 'hoge' => sub {
    ok 1;

    die;

    ok 2;
};

done_testing;

overridden test functions clobber $@

#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

is(eval "die 'foo'", undef);
ok($@);

done_testing;

This passes without Test::Pretty, but fails with it.

Test::Builder::share is used, but this doesn't exist

This is what I get (and I have seen other CPANTester reports with this message as well):

Can't locate object method "share" via package "Test::Builder" at /home/mojolicious/.cpanm/work/1421662858.23845/Test-Pretty-0.30/blib/lib/Test/Pretty.pm line 234.

Test plans not handled properly

Test::Pretty doesn't seem to handle test plans as shown in the following examples:

Example 1

The following script erroneously reports a mismatch of tests planned and tests run.

#!/usr/bin/perl -w

use strict;
use warnings;
use Test::More tests => 3;
use Test::Pretty;

### Test::Pretty doesn't handle test plans properly.
###
### This file with Test::Pretty gives
###
###   1..3
###   o  Plain test
###     Subtest 1
###       o  Test 1-1
###       o  Test 1-2
###     Subtest 2
###       o  Test 2-1
###       o  Test 2-2
###     # Bad plan: 5 != 7
###
### while running this test without Test::Pretty shows
### that all plans planned are run:
###
###    1..3
###    ok 1 - Plain test
###        1..2
###        ok 1 - Test 1-1
###        ok 2 - Test 1-2
###    ok 2 - Subtest 1
###        1..2
###        ok 1 - Test 2-1
###        ok 2 - Test 2-2
###    ok 3 - Subtest 2

ok(1, "Plain test");
subtest "Subtest 1" => sub {
    plan tests => 2;

    ok(1, "Test 1-1");
    ok(1, "Test 1-2");
};

subtest "Subtest 2" => sub {
    plan tests => 2;

    ok(1, "Test 2-1");
    ok(1, "Test 2-2");
};
exit;

Example 2

The following script erroneously reports a mismatch of tests planned and tests run and in addition does not complain about the additional test run in subtest 1.

#!/usr/bin/perl -w

use strict;
use warnings;
use Test::More tests => 3;
use Test::Pretty;

### Test::Pretty doesn't handle test plans properly.
###
### This file with Test::Pretty gives
###
###   1..3
###   o  Plain test
###     Subtest 1
###       o  Test 1-1
###       o  Test 1-2
###     Subtest 2
###       o  Test 2-1
###       o  Test 2-2
###     # Bad plan: 5 != 6
###
### while running this test without Test::Pretty shows
### that all plans planned are run:
###
###    1..3
###    ok 1 - Plain test
###        1..1
###        ok 1 - Test 1-1
###        ok 2 - Test 1-2
###        # Looks like you planned 1 test but ran 2.
###    not ok 2 - Subtest 1
###    #   Failed test 'Subtest 1'
###    #   at ./Pretty2.t line 46.
###        1..2
###        ok 1 - Test 2-1
###        ok 2 - Test 2-2
###    ok 3 - Subtest 2
###    # Looks like you failed 1 test of 3.

ok(1, "Plain test");
subtest "Subtest 1" => sub {
    plan tests => 1;

    ok(1, "Test 1-1");
    ok(1, "Test 1-2");
};

subtest "Subtest 2" => sub {
    plan tests => 2;

    ok(1, "Test 2-1");
    ok(1, "Test 2-2");
};
exit;

Plack test suite fails.

prove -PPretty is so awesome. BTW looks like there's an issue with STDOUT capturing? Plack-Handler/cgi.t sometimes fails

use a different char for TODO failures?

I was thinking that a green X for a failing TODO might be neat? Or maybe an orange X? I can do the work if you can pick something that makes sense to you.

uninitialized value warnings

$ perl -MTest::Pretty -Ilib t/basic.t
Use of uninitialized value $lineno in subtraction (-) at /home/doy/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Test/Pretty.pm line 39.
Use of uninitialized value $line in substitution (s///) at /home/doy/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Test/Pretty.pm line 40.
✓  basic test
Use of uninitialized value $lineno in subtraction (-) at /home/doy/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Test/Pretty.pm line 39.
Use of uninitialized value $line in substitution (s///) at /home/doy/perl5/perlbrew/perls/perl-5.16.0/lib/site_perl/5.16.0/Test/Pretty.pm line 40.
✓  no exceptions for basic test

This is when running tests from the Text::Handlebars test suite. It probably has something to do with the fiddling around I'm doing with $Test::Builder::Level.

subtest return value is wrong

With a test like:

use Test::More;

subtest 'Test subtest return value' => sub {
    ok 1;
    ok 0; # whole subtest has failed!
    ok 1;
} and diag "SUCCESS!";

done_testing;

The subtest should return a false value, but under Test::Pretty it returns true (from the last expression in the subtest). Running perl -MTest::Pretty test.t prints "SUCCESS!" which is a change of behaviour from standard Test behaviour.

Test does not fails on bad plan

It does not checks test count. I mean

Looks like you planned 2 tests but ran 1.

checks.

Issue was reported by Norbert Gruener.

Test fail when pass() receives arguments inside of subtest block

Following test fails by "Modification of a read-only value attempted at .perl/lib/perl5/Test/Pretty.pm line 122." error. The test passes without use Test::Pretty.

use strict;
use warnings;

use Test::More;
use Test::Pretty;

subtest 'Test' => sub {
    pass 'A';
};

done_testing;
  • Test::Pretty VERSION 0.24
  • Test::More VERSION 0.98
  • Perl VERSION 5.12.3

work with `prove -l t`

I often point prove at an entire test directory (e.g. prove -l t,) and I noticed that Test::Pretty does not format anything in this case. It would be great if it could handle this situation!

Support Colors under Windows cmd.exe

@zoffixznet noticed problems using Test::Pretty with windows and mentioned it in irc:

23:08 < Zoffix> (in fact, even after I install Test-Pretty on Windows, it's outputting trash instead of pretty unicode, even when I do chcp 65001, which supposedly switches the
terminal to utf8)

and posted two screenshots both in Windows 7:

I believe the issue is that cmd.exe doesn't respect ANSI Color Codes and not necessarily an issue of encoding (thought could be investigated as well). Here is an excerpt from the Term::ANSIColor docs:

Note that not all displays are ISO 6429-compliant, or even X3.64-compliant (or are even attempting to be so). This module will not work as expected on displays that do not honor these escape sequences, such as cmd.exe, 4nt.exe, and command.com under either Windows NT or Windows 2000. They may just be ignored, or they may display as an ESC character followed by some apparent garbage.

Perhaps a different module should be used or a fallback module/method for windows only?

I am willing to look into this myself when I find the time. :)

fork() on strawberry perl crashes interpreter in fork.t

to see error in automated test please checkout:
http://www.cpantesters.org/cpan/report/9b5aad6d-6fc6-1014-aa23-111fa794d5e7

it is failing on fork.t, on main::(fork.t:8): my $pid = fork();
https://raw.githubusercontent.com/tokuhirom/Test-Pretty/master/t/fork.t

Apparently strawberry perl's implementation of fork() leaves something to be desired.

not that you'll glean much from the data, here is the stack trace for the perl process using proc explorer.
ntdll.dll!ZwWaitForMultipleObjects+0xa
KERNELBASE.dll!WaitForMultipleObjectsEx+0xed
KERNEL32.DLL!WaitForMultipleObjects+0xf
KERNEL32.DLL!WerpLaunchAeDebug+0x2373
KERNEL32.DLL!WerpLaunchAeDebug+0x1d97
KERNELBASE.dll!UnhandledExceptionFilter+0x1c7
ntdll.dll!memset+0xbbf7
ntdll.dll!_C_specific_handler+0x87
ntdll.dll!_chkstk+0x9d
ntdll.dll!RtlRaiseException+0xedb
ntdll.dll!KiUserExceptionDispatcher+0x2e
encoding.dll+0x36da
perl518.dll!PerlIOBase_dup+0xa3
encoding.dll+0x1493
perl518.dll!PerlIOBase_dup+0x53
encoding.dll+0x1493
perl518.dll!PerlIOBuf_dup+0x70
perl518.dll!Perl_fp_dup+0x45
perl518.dll!PerlIO_list_free+0x327
perl518.dll!perl_clone_using+0xac6
perl518.dll!Perl_get_re_arg+0x3d3f
perl518.dll!Perl_setdefout+0x74c4
perl518.dll!Perl_runops_standard+0x16
perl518.dll!perl_run+0x379
perl518.dll!RunPerl+0x168
perl.exe+0x13d7
perl.exe+0x14f8
KERNEL32.DLL!BaseThreadInitThunk+0xd
ntdll.dll!RtlUserThreadStart+0x1d

skipping fork() by wrapping a $^O in might resolve this error so that installation with tests work.
if ($^O ne 'MSWin32') {

Thanks!
--dave

Broken by Test::Builder alphas

Test-More/test-more#505

This module will break with the new Test::Builder alphas that are already in blead.

The module overrides Test::Builder methods in ways that do not preserve their API, this cannot feasibly be supported. It also directly accesses singleton hash elements that have had proper API's for a long time (test counts).

It is worth noting that the alphas provide api's that would make it possible to implement this module without overriding anything in other modules. If interested ping me and I can provide the basic code for changing the output from Test::*, but I cannot implement the entire module over again for you.

dubious, test returned 1 when prove run with -Pretty

Tried this on my dist https://github.com/sharyanto/perl-SHARYANTO-Utils .

$ prove -Pretty t/detect_http_ua_simple.t | dux lins " " --format text-simple

  User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.12011-10-16 20:23:00
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  User-Agent Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  User-Agent Opera/9.20 (Windows NT 6.0; U; en)
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  User-Agent Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/18.6.872.0 Safari/535.2 UNTRUSTED/1.0 3gpp-gba UNTRUSTED/1.0
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  User-Agent Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:50
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  User-Agent Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; DROID BIONIC Build/5.5.1_84_DBN-55) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  User-Agent BlackBerry9530/4.7.0.76 Profile/MIDP-2.0 Configuration/CLDC-1.1 VendorID/126
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  User-Agent User-Agent: Opera/9.80 (J2ME/MIDP; Opera Mini/6.1.25378/25.692; U; en) Presto/2.5.25 Version/10.54
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 800)
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  User-Agent NokiaN90-1/3.0545.5.1 Series60/2.8 Profile/MIDP-2.0 Configuration/CLDC-1.1
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  Accept text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
    ✓  doesnt die
    ✓  gui
    ✓  not text browser
    ✓  browser
  User-Agent Links (2.5; Linux 3.2.0-1-amd64 x86_64; GNU C 4.6.2;OC text)
    ✓  doesnt die
    ✓  not gui
    ✓  text browser
    ✓  browser
  User-Agent ELinks/0.9.3 (textmode; Linux 2.6.11 i686; 79x24)
    ✓  doesnt die
    ✓  not gui
    ✓  text browser
    ✓  browser
  User-Agent Lynx/2.8.8dev.9 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.12.14
    ✓  doesnt die
    ✓  not gui
    ✓  text browser
    ✓  browser
  User-Agent w3m/0.5.1
    ✓  doesnt die
    ✓  not gui
    ✓  text browser
    ✓  browser
  User-Agent Googlebot/2.1 ( http://www.googlebot.com/bot.html) 
    ✓  doesnt die
    ✓  not gui
    ✓  not text browser
    ✓  not browser
  User-Agent curl/7.23.1 (x86_64-pc-linux-gnu) libcurl/7.23.1 OpenSSL/1.0.0f zlib/1.2.3.4 libidn/1.23 libssh2/1.2.8 librtmp/2.3
    ✓  doesnt die
    ✓  not gui
    ✓  not text browser
    ✓  not browser
  Accept */*
    ✓  doesnt die
    ✓  not gui
    ✓  not text browser
    ✓  not browser

not ok
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/1 subtests 

But ok without -Pretty:

$ prove t/detect_http_ua_simple.t; echo $?
t/detect_http_ua_simple.t .. ok    
All tests successful.
Files=1, Tests=19,  0 wallclock secs ( 0.01 usr  0.00 sys +  0.01 cusr  0.00 csys =  0.02 CPU)
Result: PASS
0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.