| 37 | | #my $config = Config::Pit::get("test", require => { |
| 38 | | # "foo" => "foo test", |
| 39 | | # "bar" => "bar test" |
| 40 | | #}); |
| 41 | | #p $config; |
| 42 | | # TODO |
| | 38 | |
| | 39 | # EDITOR |
| | 40 | # |
| | 41 | Config::Pit::set("test", data => {}); |
| | 42 | $ENV{EDITOR} = ""; |
| | 43 | Config::Pit::set("test"); |
| | 44 | is(ref($config), "HASH", "set with unset EDITOR"); |
| | 45 | |
| | 46 | sub temppath { |
| | 47 | return file(File::Temp->new()->filename) |
| | 48 | } |
| | 49 | |
| | 50 | my $exe = temppath(); |
| | 51 | my $tst = temppath(); |
| | 52 | |
| | 53 | my $fh = $exe->open("w", 0700) or die "open failed."; |
| | 54 | print $fh <<'EOF'; |
| | 55 | #!/usr/bin/env perl |
| | 56 | use strict; |
| | 57 | |
| | 58 | my $a = do { local $/; <ARGV> }; |
| | 59 | |
| | 60 | my $tst = $ENV{TEST_FILE}; |
| | 61 | open my $fh, ">$tst"; |
| | 62 | print $fh $a; |
| | 63 | close $fh; |
| | 64 | EOF |
| | 65 | undef $fh; |
| | 66 | chmod 0700, $exe; |
| | 67 | |
| | 68 | $ENV{EDITOR} = $exe; |
| | 69 | $ENV{TEST_FILE} = $tst; |
| | 70 | #system $exe, "Changes"; |
| | 71 | #p $tst->slurp; |
| | 72 | |
| | 73 | my $data = { |
| | 74 | foo => "0101", |
| | 75 | bar => "0202", |
| | 76 | }; |
| | 77 | |
| | 78 | Config::Pit::set("test", data => $data); |
| | 79 | Config::Pit::set("test"); |
| | 80 | |
| | 81 | my $result = LoadFile($tst); |
| | 82 | |
| | 83 | is($result->{foo}, $data->{foo}, "editor test"); |
| | 84 | is($result->{bar}, $data->{bar}, "editor test"); |
| | 85 | |
| | 86 | |
| | 87 | |