Trog-Config.t 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. use strict;
  2. use warnings;
  3. use Test::More;
  4. use Test::MockModule qw{strict};
  5. use Test::Deep;
  6. use Test::Fatal qw{exception};
  7. use FindBin;
  8. use lib "$FindBin::Bin/../lib";
  9. use Test::MockFile;
  10. require_ok('Trog::Config') or BAIL_OUT("Can't find SUT");
  11. subtest 'theme_dir' => sub {
  12. my $cust_cfg = Test::MockFile->file("config/main.cfg");
  13. my $mocked_cfg = Test::MockFile->file( "config/default.cfg", "[general]\ntheme=zippy\n" );
  14. my @mocked_dirs = map { Test::MockFile->new_dir($_) } qw{www www/themes www/themes/zippy};
  15. is( Trog::Config::theme_dir(), "themes/zippy", "Got expected theme_dir when directory existent" );
  16. pop @mocked_dirs;
  17. is( Trog::Config::theme_dir(), "themes/zippy", "Caching works" ); # would die if this did not
  18. unlink "config/default.cfg"; # The mocker ain't terribly smart. Maybe a bug?
  19. undef $mocked_cfg;
  20. $mocked_cfg = Test::MockFile->file( "config/default.cfg", "[general]\ntheme=dippy\n" );
  21. push @mocked_dirs, Test::MockFile->dir( "www/themes/dippy" );
  22. is( Trog::Config::theme_dir(1), "", "Got expected theme_dir when directory not existent and cache popped" );
  23. };
  24. # So far no test for get, but the above actually exercises most of it anyways, so eh
  25. done_testing();