#! /usr/bin/env perl # -*- perl -*-
use
JSON
qw(decode_json)
;
my
%assets
;
$assets
{
'a'
} = {
name
=>
'a'
,
content
=>
'this is a'
};
$assets
{
'b'
} = {
name
=>
'b'
,
content
=>
'this is b'
};
my
$site
= TestSite->new(
name
=>
'config-defaults'
,
assets
=> \
%assets
,
);
my
(
$stdout
,
$expected
);
$stdout
=
tie
*STDOUT
,
'MemStream'
;
ok (Qgoda::CLI->new([
'dump'
])->dispatch);
untie
*STDOUT
;
my
$json
= decode_json
$stdout
->buffer;
is
ref
$json
,
'ARRAY'
;
is 2,
@$json
;
is
'HASH'
,
ref
$json
->[0];
is
'HASH'
,
ref
$json
->[1];
$json
= [
sort
{
$a
->{name} cmp
$b
->{name}}
@$json
];
is
'a'
,
$json
->[0]->{name};
is
'b'
,
$json
->[1]->{name};
$stdout
=
tie
*STDOUT
,
'MemStream'
;
ok (Qgoda::CLI->new([
'dump'
,
'--output-format=json'
])->dispatch);
untie
*STDOUT
;
my
$json2
= decode_json
$stdout
->buffer;
$json2
= [
sort
{
$a
->{name} cmp
$b
->{name}}
@$json2
];
is_deeply
$json2
,
$json
;
$stdout
=
tie
*STDOUT
,
'MemStream'
;
ok (Qgoda::CLI->new([
'dump'
,
'--output-format=yaml'
])->dispatch);
untie
*STDOUT
;
my
$yaml
= Load
$stdout
->buffer;
$yaml
= [
sort
{
$a
->{name} cmp
$b
->{name}}
@$yaml
];
is_deeply
$yaml
,
$json
;
$stdout
=
tie
*STDOUT
,
'MemStream'
;
ok (Qgoda::CLI->new([
'dump'
,
'--output-format=storable'
])->dispatch);
untie
*STDOUT
;
my
$storable
= thaw
$stdout
->buffer;
$storable
= [
sort
{
$a
->{name} cmp
$b
->{name}}
@$storable
];
is_deeply
$storable
,
$json
;
$stdout
=
tie
*STDOUT
,
'MemStream'
;
ok (Qgoda::CLI->new([
'dump'
,
'--output-format'
,
'perl'
])->dispatch);
untie
*STDOUT
;
my
$Qgoda1
;
my
$perl
=
eval
$stdout
->buffer;
$perl
= [
sort
{
$a
->{name} cmp
$b
->{name}}
@$perl
];
is_deeply
$storable
,
$json
;
eval
{ Qgoda::CLI->new([
'dump'
,
'--output-format'
,
'python'
])->dispatch };
ok $@;
$site
->tearDown;
done_testing;