1# libquvi-scripts
2# Copyright (C) 2011  Toni Gundogdu <legatvs@gmail.com>
3#
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the GNU General Public License
6# as published by the Free Software Foundation; either version 2
7# of the License, or (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17# 02110-1301, USA.
18
19use warnings;
20use strict;
21
22use Test::More;
23
24eval "use JSON::XS";
25plan skip_all => "JSON::XS required for testing" if $@;
26
27eval "use Test::Deep";
28plan skip_all => "Test::Deep required for testing" if $@;
29
30use Test::Quvi;
31
32my $q = Test::Quvi->new;
33my $c = $q->get_config;
34
35plan skip_all =>
36  "URL required for testing, use ':: --url URL' or ('--json-file FILE')"
37  unless $c->{url}
38    or $c->{json_file};    # --url or --json-file (read URL from json)
39
40my $e;
41my $u = $c->{url};
42if (!$u)
43{
44  $e = $q->read_json($c->{json_file});
45  plan skip_all =>
46    "URL required, JSON did not contain 'page_url', use --url URL"
47    unless $e->{page_url};
48  $u = $e->{page_url};
49}
50
51my $t = 1;
52$t += 1 if $c->{json_file};
53plan tests => $t;
54
55my ($r, $o) = $q->run($u);
56is($r, 0, "quvi exit status == 0")
57  or diag $c->{url};
58if ($c->{json_file})
59{
60SKIP:
61  {
62    skip 'quvi exit status != 0', 1 if $r != 0;
63    my $f = $c->{json_file};
64    my $j = $q->get_json_obj;
65    cmp_deeply($j->decode($o), $e, "compare with $f")
66      or diag $c->{url};
67  }
68}
69