1#!/usr/bin/perl 2# 05-readwrite.t 3# Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org> 4 5use Directory::Scratch; 6use Test::More tests=>15; 7use strict; 8use warnings; 9 10my $t = Directory::Scratch->new; 11ok($t->touch('foo')); 12is($t->read('foo'), q{}, "nothing in foo"); 13ok($t->write('foo', "this is a test")); 14is(scalar $t->read('foo'), "this is a test", 'read test'); 15is_deeply([$t->read('foo')], ["this is a test"]); 16 17ok($t->touch('bar', qw(this is a test))); 18is(scalar $t->read('bar'), "this\nis\na\ntest"); 19is_deeply([$t->read('bar')], [qw(this is a test)]); 20 21ok($t->touch('baz', "this already has a line")); 22ok($t->write('baz', "oh no, it went away")); 23is(scalar $t->read('baz'), "oh no, it went away"); 24ok($t->write('baz', qw(foo bar baz yay!))); 25is(scalar $t->read('baz'), "foo\nbar\nbaz\nyay!"); 26is_deeply([$t->read('baz')], [qw(foo bar baz yay!)]); 27 28eval { 29 $t->write('/made/up/filename', qw(foo bar)); 30}; 31ok(!$@, "didn't get an error"); 32