File: 01_basic.t

package info (click to toggle)
libconfig-pit-perl 0.04-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 288 kB
  • sloc: perl: 4,097; makefile: 2
file content (91 lines) | stat: -rw-r--r-- 2,182 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use strict;
use warnings;

use Test::More tests => 17;
use File::Temp;
use Path::Class;
use YAML::Syck;

use Config::Pit;

use Data::Dumper;
sub p($) { warn Dumper shift }

my $dir = File::Temp->newdir();
$Config::Pit::directory    = dir($dir->dirname);
$Config::Pit::config_file  = $Config::Pit::directory->file("pit.yaml");
$Config::Pit::verbose      = 0;

my ($config, $p);

$config = Config::Pit::get("test");
is(ref($config), "HASH", "get returned value");
is(ref($config->{foo}), "");

$config = Config::Pit::set("test", data => {
		"foo" => "bar",
		"bar" => "baz",
});
is($config->{foo}, "bar", "set returned value");
is($config->{bar}, "baz", "set returned value");

$config = Config::Pit::get("test");
is($config->{foo}, "bar", "get returned value (after set)");
is($config->{bar}, "baz", "get returned value (after set)");

$config = pit_get("test");
is($config->{foo}, "bar", "get returned value (exported sub)");
is($config->{bar}, "baz", "get returned value (exported sub)");

$p = Config::Pit::switch("profile");
is($p, "default", "switch profile");
$config = pit_get("test");
is($config->{foo}, undef, "switch profile get value");
is($config->{bar}, undef, "switch profile get value");

$p = Config::Pit::switch();
is($p, "profile", "switch profile");
$config = pit_get("test");
is($config->{foo}, "bar", "switch profile get value");
is($config->{bar}, "baz", "switch profile get value");

# EDITOR
#
Config::Pit::set("test", data => {});
$ENV{EDITOR} = "";
Config::Pit::set("test");
is(ref($config), "HASH", "set with unset EDITOR");

my $suffix = $^O =~ /Win32/ ? '.bat' : '.pl'; 
sub temppath {
	return file(File::Temp->new()->filename . $suffix)
}

my $exe = temppath();
my $tst = temppath();

my $fh = $exe->open("w", 0700) or die "open failed.";
print $fh file("t/editor/exe$suffix")->slurp;
undef $fh;
chmod 0700, $exe;

$ENV{EDITOR}    = $exe;
$ENV{TEST_FILE} = $tst;
#system $exe, "Changes";
#p $tst->slurp;

my $data = {
	foo => "0101",
	bar => "0202",
};

Config::Pit::set("test", data => $data);
Config::Pit::set("test");

my $result = LoadFile($tst);

is($result->{foo}, $data->{foo}, "editor test");
is($result->{bar}, $data->{bar}, "editor test");