2 # Copyright (C) 2011 Toni Gundogdu <legatvs@gmail.com>
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library 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 GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 use version
0.77 (); our $VERSION = version
->declare("0.1.0");
28 use vars
qw(@ISA @EXPORT @EXPORT_OK);
30 our @ISA = qw(Exporter);
33 use Getopt
::Long
qw(:config bundling);
41 Parse command line options, create object(s), etc. Make a note of
42 default values (e.g. assume quvi(1) to be found in the $PATH if
43 --quvi-path is not used.
48 my ($class, %args) = @_;
49 my $self = bless {}, $class;
55 'quvi_path|quvi-path|quvipath|q=s',
56 'quvi_basedir|quvi-basedir|quvibasedir|b=s',
57 'quvi_opts|quvi-opts|quviopts|o=s',
58 'json_file|json-file|jsonfile|j=s',
59 'dump_json|dump-json|dumpjson|J',
60 'data_root|data-root|dataroot|d=s',
62 'valgrind_path|valgrind-path|valgrindpath|v=s',
67 $config{quvi_path
} ||= 'quvi'; # Presume it is found in the $PATH.
68 $config{data_root
} ||= cwd
;
69 $self->{config
} = \
%config;
70 $self->{jobj
} = JSON
::XS
->new;
71 $ENV{QUVI_BASEDIR
} = $config{quvi_basedir
} if $config{quvi_basedir
};
76 # Reuse the JSON object instead of re-creating one for each test.
84 # A short-hand to access the parsed command line options.
92 # Find all occurences of '*.json' from the specified paths.
96 my ($self, @paths) = @_;
98 my $d = $self->{config
}{data_root
};
101 my $p = File
::Spec
->catfile($d, $_, '*.json');
102 @files = (@files, glob($p));
108 Read the specified JSON file. Prepend $config{data_root} to the file
109 path if requested, this is needed typically if read_json is called
110 without a preceeding call to find_json (e.g. t/redirect.t and
111 t/shortened.t skip find_json).
116 my ($self, $fpath, $prepend_data_root) = @_;
118 if ($prepend_data_root)
120 my $d = $self->{config
}{data_root
};
121 $fpath = File
::Spec
->catfile($d, $fpath);
125 open my $fh, "<", "$fpath" or croak
"$fpath: $!";
126 my $e = $self->{jobj
}->decode(join '', <$fh>);
129 # Ignore these by default.
130 my @ignore = qw(url thumbnail_url);
132 # Any aditional JSON keys to be ignored.
133 if ($self->{config
}{ignore
})
135 @ignore = (@ignore, split /,/, $self->{config
}{ignore
});
138 mark_ignored
($self, \
$e, @ignore);
143 Mark those JSON elements that are to be ignored in deep comparison.
144 Note that 'link' is a special case. We have to also assume that there
145 could be more than one 'link'.
150 my ($self, $json, @a) = @_;
153 while (my ($k, $v) = each(%{$$json}))
160 while (my ($kl, $vl) = each(%{$l}))
162 $$json->{$k}[$n]->{$kl} = ignore
()
170 $$json->{$k} = ignore
() if $k eq $i;
176 # Construct the command to run quvi.
180 my ($self, $url, @extra_args) = @_;
181 my $q = $self->{config
}{quvi_path
};
182 my $c = qq/$q "$url" /;
184 if ($self->{config
}{quvi_opts
})
186 $c .= ' ' . $self->{config
}{quvi_opts
};
190 $c .= join ' ', @extra_args if @extra_args;
195 # Run the quvi command.
199 my ($self, $cmd) = @_;
203 my $o = join '', qx/$cmd/;
207 if $r == 0 and $self->{config
}{dump_json
};
213 Run quvi(1) with the specified options. Return quvi exit status and
214 the output (printed to stdout).
220 _run_cmd
($self, _build_cmd
($self, @_));
223 # Same as above but run quvi through valgrind.
225 sub run_with_valgrind
228 my $c = _build_cmd
($self, @_);
229 if ($self->{config
}{valgrind_path
})
231 my $v = $self->{config
}{valgrind_path
};
232 $c = "libtool --mode=execute $v -q --leak-check=full "
233 . "--track-origins=yes --error-exitcode=1 $c";
240 # vim: set ts=2 sw=2 tw=72 expandtab: