Permalink
Browse files

some file tests

  • Loading branch information...
Jan
Jan committed Jun 16, 2012
1 parent 688b6e3 commit 808e6a5f192bafa9b49ede69ade8b6ba194c0188
Showing with 51 additions and 0 deletions.
  1. +51 −0 t/file.t
View
@@ -0,0 +1,51 @@
+use strict;
+use warnings;
+
+use Test::More tests => 10;
+use Data::Dumper;
+
+use_ok 'Rex';
+use_ok 'Rex::Commands::File';
+use_ok 'Rex::Commands::Fs';
+Rex::Commands::File->import;
+Rex::Commands::Fs->import;
+
+file("test.txt",
+ content => "blah blah\nfoo bar");
+
+my $c = cat("test.txt");
+
+ok($c, "cat");
+ok($c =~ m/blah/, "file with content (1)");
+ok($c =~ m/bar/, "file with content (2)");
+
+Rex::Commands::Fs::unlink("test.txt");
+
+ok(! is_file("test.txt"), "file removed");
+
+file("test.txt",
+ content => "blah blah\nbaaazzzz",
+ mode => 777);
+
+my %stats = Rex::Commands::Fs::stat("test.txt");
+ok($stats{mode} eq "0777", "fs chmod ok");
+
+my $changed = 0;
+append_if_no_such_line("test.txt", "change", qr{change},
+ on_change => sub {
+ $changed = 1;
+ });
+
+ok($changed == 1, "something was changed in the file");
+
+append_if_no_such_line("test.txt", "change", qr{change},
+ on_change => sub {
+ $changed = 0;
+ });
+
+ok($changed == 1, "nothing was changed in the file");
+
+
+
+Rex::Commands::Fs::unlink("test.txt");
+

0 comments on commit 808e6a5

Please sign in to comment.