File: workspace.t

package info (click to toggle)
libbadger-perl 0.16-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,400 kB
  • sloc: perl: 11,004; makefile: 9
file content (118 lines) | stat: -rw-r--r-- 3,714 bytes parent folder | download
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#============================================================= -*-perl-*-
#
# t/work/workspace.t
#
# Test the Badger::Workspace module.
#
# Copyright (C) 2008-2014 Andy Wardley.  All Rights Reserved.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
#========================================================================

use Badger
    lib => ' ../../lib',
    Utils => 'Bin';

use Badger::Test
    debug => 'Badger::Workspace',
    args  => \@ARGV;

eval "require Badger::Codec::YAML";
if ($@) {
    skip_all($@);
}
else {
    plan(25);
}

use Badger::Debug ':all';
use Badger::Workspace;
use constant WORKSPACE => 'Badger::Workspace';

my $workspace = WORKSPACE->new(
    root => Bin->dir( test_files => 'workspace1' ),
);

ok( $workspace, 'created workspace' );
is( $workspace->config('example.foo'), 'The Foo Item', 'got example.foo from config' );
is( $workspace->config('example.bar'), 'The Bar Item', 'got example.bar from config' );
is( $workspace->config('name'), 'Test Workspace', 'got workspace name from config' );

my $goodbye = $workspace->file('goodbye.txt');
ok( $goodbye, 'got goodbye.txt file' );
ok( $goodbye->exists, 'goodbye.txt file exists' );

my $txt = $goodbye->text;
chomp $txt;
is( $txt, 'Goodbye World!', 'got file text' );

my $greetings = $workspace->config('greetings');
ok( $greetings, 'got greetings config' );
is( $greetings->{ hello }, 'Hello World!', 'got hello greeting' );
is( $workspace->config('greetings.hello'), 'Hello World!', 'got greetings.hello' );


#-----------------------------------------------------------------------------
# 'dirs' config section in config/workspace.yaml maps 'first' and 'second'
# directories onto 'one' and 'two'
#-----------------------------------------------------------------------------

my $dir1 = $workspace->dir('first');
ok( $dir1, 'got first dir' );
is( $dir1->name, 'one', 'first dir is mapped to one' );


my $foo1 = $workspace->file('one/foo');
ok( $foo1, 'got one/foo' );

my $foo2 = $workspace->file('first/foo');
ok( $foo2, 'got first/foo' );
is( $foo1->text, $foo2->text, 'file contents match ' );

my $text = $foo2->text;
chomp($text);
is( $text, 'This is one/foo', $text );


#-----------------------------------------------------------------------------
# This workspace has a separate config/dirs.yaml file
#-----------------------------------------------------------------------------

my $workspace2 = WORKSPACE->new(
    root => Bin->dir( test_files => 'workspace2' ),
);

ok( $workspace2, 'got second workspace' );
my $five = $workspace2->file('charlie/five');
ok( $five, 'got charlie/five file' );

is( $five->parent->name, 'four', 'charlie dir is actually five' );

my $text2 = $five->text;
chomp($text2);
is( $text2, 'This is three/four/five', $text2 );


#-----------------------------------------------------------------------------
# Attach the second workspace to the first
#-----------------------------------------------------------------------------

$workspace2->attach($workspace);

my $greets2 = $workspace2->parent_config('greetings');
ok( $greets2, 'got greetings from parent config' );
is( $greets2->{ hello }, 'Hello World!', 'got parent hello greeting' );

my $greets3 = $workspace2->config('greetings');
ok( $greets3, 'got greetings config inherited from parent' );
is( $greets3->{ hello }, 'Hello World!', 'got hello greeting' );


# I had some inheritance rules in for a while, but it made things too
# complicated.  For now we assume that all configuration data can be inherited
# from a parent workspace
#ok( ! $workspace2->config('fruit'), 'no local or inherited fruit' );

ok( $workspace2->config('fruit'), 'inherited fruit' );