kentfredric / ideas

Draft ideas for things that are more organised and feedbacky than gists with mkdn as default
1 stars 0 forks source link

Path testing extension for Test::Deep #6

Open kentfredric opened 8 years ago

kentfredric commented 8 years ago
use Test::Deep;
use Test::Deep::Path qw( is_path );

cmp_deeply( $path, is_path->file->readable->executable );

Would be appropos of:

use Test::Deep
cmp_deeply( $path, code(sub{ 
   !-d $_[0] and return (0, $error_mess);
   -r $_[0] or return (0, $error_mess);
   -e $_[0] or return (0, $error_mess);
});

Would also imply "And" to all arguments by default.

why not just all and code things?

  1. all is documented to have plans for "iterate all items for error codes" behaviour, but this is very undesirable in cases where previous cases failing result in later cases fatalizing.

    This is a short-circuit test, the testing is stopped after the first failure, although in the future it may complete all tests so that diagnostics can be output for all failures. When reporting failure, the parts are counted from 1.

  2. It would be just gross doing

    cmp_deeply( $path, all( is_file, is_readable, is_executable ))

    P.S. Holy namespace poison batman.

  3. Handling all the right error messages manually sucks donkey dick

    cmp_deeply( $path, code(sub{ 
    not -e $_[0]  and return (0, "$_[0] does not exist");
    -d $_[0]  and return (0, "$_[0] is not a file");
    -r $_[0]  or return (0, "$_[0] is not readable");
    -x $_[0]  or return (0, "$_[0] is not executable");
    return 1;
    }));

    BS so bad it basically makes having Test::Deep here a waste of time.

exodist commented 8 years ago

Just a note, Test::Stream already has these capabilities: https://metacpan.org/pod/Test::Stream::Plugin::Compare#SET-BUILDERS http://test-more.github.io/Test-Stream/#compare-sets http://test-more.github.io/Test-Stream/#compare-custom