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