[BACK]Return to dudelicious.t CVS log [TXT][DIR] Up to [local] / todotxt / Text-Todo / t

Annotation of todotxt/Text-Todo/t/dudelicious.t, Revision 1.4

1.3       andrew      1: #!perl
                      2: use Test::More;    # tests => 3;
                      3:
                      4: use strict;
                      5: use warnings;
                      6:
                      7: use File::Temp qw/ tempdir /;
                      8: use File::Copy qw/ cp /;
                      9: use File::Spec;
1.1       andrew     10:
                     11: BEGIN {
1.3       andrew     12:     eval "use Test::Mojo";
                     13:     plan skip_all => "Test::Mojo required for testing dudelicious" if $@;
                     14:
                     15: }
1.1       andrew     16:
1.3       andrew     17: my $todo_dir = tempdir( 'todo-XXXXXXXXX', CLEANUP => 1, TMPDIR => 1 );
                     18: $ENV{DUDELICIOUS_HOME} = $todo_dir;
                     19:
                     20: foreach my $file qw( todo1.txt todo.list.txt dudelicious.conf ) {
                     21:     cp( File::Spec->catfile( 't',       $file ),
                     22:         File::Spec->catfile( $todo_dir, $file ),
                     23:     ) || die "Couldn't cp [$todo_dir]/[$file]: $!";
1.1       andrew     24: }
                     25:
1.3       andrew     26: require File::Spec->catfile( 'bin', 'dudelicious.pl' );
                     27: Dudelicious->import;
                     28: Dudelicious->app->log->level('error');
1.1       andrew     29:
                     30: my $t = Test::Mojo->new;
                     31:
1.3       andrew     32:
1.4     ! andrew     33: foreach my $p (
        !            34:     '/',
        !            35:     '/l/todo1',
        !            36:     '/l/todo1.html',
        !            37:     '/l/todo1.txt',
        !            38:     '/l/todo1.json',
        !            39:     '/l/todo1/e/1',
        !            40:     '/l/todo1/e/1.html',
        !            41:     '/l/todo1/e/1.json',
        !            42:     '/l/todo1/t',
        !            43:     '/l/todo1/t.txt',
        !            44:     '/l/todo1/t.json',
        !            45: ) {
        !            46:     my ($volume, $directories, $file) = File::Spec->splitpath($p);
        !            47:     $file ||= 'index.html';
        !            48:
        !            49:     if ($file !~ /\.[^.]+$/xms) {
        !            50:         $file .= '.html';
        !            51:     }
        !            52:
        !            53:
        !            54:     my $f = File::Spec->catfile( 't', 'dudelicious', $volume, $directories,
        !            55:         $file);
        !            56:
        !            57:     SKIP: {
        !            58:         skip "$f does not exist", 3 if ! -e $f;
        !            59:         diag( "Getting [$f] from [$p]" );
        !            60:         $t->get_ok($p)->status_is(200)->content_is( slurp( $f ) );
        !            61:     }
1.3       andrew     62: }
                     63:
1.4     ! andrew     64: done_testing();
        !            65:
        !            66:
        !            67: sub slurp {
        !            68:     my ($file) = @_;
1.3       andrew     69:
1.4     ! andrew     70:     local $/;
        !            71:     open my $fh, '<', $file or die $file . ': ' . $!;
        !            72:     my $content = <$fh>;
        !            73:     close $fh;
1.3       andrew     74:
1.4     ! andrew     75:     return $content;
1.3       andrew     76: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>