Permalink
Browse files

Fix tests on XDG systems, add way to turn XDF off

  • Loading branch information...
1 parent 6b7c90d commit b602b0f44fcfdee0c8c72484debe14a91e7fe99c @frioux committed Dec 14, 2012
Showing with 38 additions and 11 deletions.
  1. +2 −0 Changes
  2. +6 −0 bin/adenosine
  3. +6 −1 lib/App/Adenosine.pm
  4. +24 −10 t/basic.t
View
@@ -2,6 +2,8 @@ Revision history for {{$dist->name}}
{{$NEXT}}
+ * Fix tests when user has an XDG system, and add a way to turn XDG off
+
2.001002 2012-12-13 15:07:41 CST6CDT
* Fix exports in bash
View
@@ -446,6 +446,12 @@ The following would work if you didn't want to configure C<::Rainbow>
- ::Stopwatch
- ::Rainbow
+Another option allows the user to disable the XDG based directory structure
+(typically F<~/.config>). Simply put the following in your
+F<~/.adenosinerc.yml>:
+
+ enable_xdg: 0
+
=head1 Working With JSON or XML Data
JSON REST web services require some special tools to make them accessible
View
@@ -19,6 +19,10 @@ our $verb_regex = '(?:HEAD|OPTIONS|GET|DELETE|PUT|POST|TRACE)';
sub verbose { $_[0]->{verbose} }
sub plugins { @{$_[0]->{plugins}} }
+sub enable_xdg {
+ return $_[0]->{enable_xdg} if exists $_[0]->{enable_xdg};
+ return 1
+}
sub _plugin_name {
my ($self, $name) = @_;
@@ -136,7 +140,8 @@ SHELL
sub config_location {
my $loc;
- if (my $h = $ENV{XDG_CONFIG_HOME}) {
+ if ($_[0]->enable_xdg and $ENV{XDG_CONFIG_HOME}) {
+ my $h = $ENV{XDG_CONFIG_HOME};
$loc = "$h/resty"
} else {
$loc = "$ENV{HOME}/.resty"
View
@@ -10,42 +10,46 @@ use Test::Fatal;
$ENV{PATH} = "t/bin:$ENV{PATH}";
$ENV{EDITOR} = 'bluh';
my $c = "$ENV{HOME}/.resty/c/google.com";
-
+my @noxdg = (enable_xdg => 0);
subtest 'plugins must be an arrayref' => sub {
like(exception {
TestAdenosine->new({
argv => ['http://google.com'],
plugins => 'fail',
+ @noxdg
})
}, qr/plugins must be an arrayref/, 'scalar');
like(exception {
TestAdenosine->new({
argv => ['http://google.com'],
plugins => {},
+ @noxdg
})
}, qr/plugins must be an arrayref/, 'hashref');
};
-TestAdenosine->new({ argv => ['http://google.com'] });
+TestAdenosine->new({ argv => ['http://google.com'], @noxdg });
is($TestAdenosine::stdout, "http://google.com*\n", 'http no *');
is($TestAdenosine::uri_base, "http://google.com*", 'uri_base set');
cmp_deeply(\@TestAdenosine::extra_options, [], 'extra options set');
-TestAdenosine->new({ argv => ['google.com', '-v', '-H', 'Foo: Bar'] });
+TestAdenosine->new({ argv => ['google.com', '-v', '-H', 'Foo: Bar'], @noxdg });
is($TestAdenosine::stdout, "http://google.com*\n", 'just domain');
is($TestAdenosine::uri_base, "http://google.com*", 'uri_base set');
cmp_deeply(\@TestAdenosine::extra_options, ['-v', '-H', 'Foo: Bar'], 'extra options set');
TestAdenosine->new({
argv => [],
plugins => [Plugin1->new],
+ @noxdg,
});
is($TestAdenosine::stdout, "http://google.com*\n", 'no args');
cmp_deeply(\@TestAdenosine::extra_options, ['-v', '-H', 'Foo: Bar'], 'extra options remain');
TestAdenosine->new({
argv => ['https://google.com/user/*/1'],
plugins => [qw(Plugin1)],
+ @noxdg,
});
is($TestAdenosine::stdout, "https://google.com/user/*/1\n", 'https + *');
is($TestAdenosine::uri_base, "https://google.com/user/*/1", 'uri_base set');
@@ -80,7 +84,7 @@ $TestAdenosine::curl_stdout = <<'BLUU2';
{"some":"json"}
BLUU2
-my $exit_code = TestAdenosine->new({ argv => ['GET'] });
+my $exit_code = TestAdenosine->new({ argv => ['GET'], @noxdg });
cmp_deeply(\@TestAdenosine::curl_options, [
qw(curl -sLv -X GET -b), $c, '-c', $c, '-H', 'Accept: text/html',
'https://google.com/user//1',
@@ -92,7 +96,8 @@ ok(!$exit_code, '200 means exit with 0');
$TestAdenosine::curl_stderr =~ s[(< HTTP/1\.1 )2][${1}5];
$exit_code = TestAdenosine->new({
argv => [qw(GET 1 -v)],
- plugins => [{ '::Plugin2' => {} }]
+ plugins => [{ '::Plugin2' => {} }],
+ @noxdg,
});
cmp_deeply(\@TestAdenosine::curl_options, [
qw(curl -sLv -X GET -b), $c, '-c', $c, '-H', 'Accept: text/html',
@@ -102,36 +107,45 @@ is($exit_code, 5, '500 exits correctly');
is($TestAdenosine::stderr, "'curl' '-sLv' '-X' 'GET' '-b' '$c' '-c' '$c' '-H' 'Accept: text/html' 'https://google.com/user/1/1'
$TestAdenosine::curl_stderr", '-v works');
-TestAdenosine->new({ argv => [qw(POST 2), '{"foo":"bar"}'] });
+TestAdenosine->new({ argv => [qw(POST 2), '{"foo":"bar"}'], @noxdg });
cmp_deeply(\@TestAdenosine::curl_options, [
qw(curl -sLv {"foo":"bar"} -X POST -b ), $c, '-c', $c, qw(
--data-binary -u foo:bar https://google.com/user/2/1),
], 'POST 2 $data');
-TestAdenosine->new({ argv => [qw(POST 2), '-V'] });
+TestAdenosine->new({ argv => [qw(POST 2), '-V'], @noxdg });
cmp_deeply(\@TestAdenosine::curl_options, [
qw(curl -sLv), '["frew","bar","baz"]', qw(-X POST -b ), $c, '-c', $c, qw(
--data-binary -u foo:bar https://google.com/user/2/1),
], 'POST -V $data');
-TestAdenosine->new({ argv => [qw(HEAD -u)] });
+TestAdenosine->new({ argv => [qw(HEAD -u)], @noxdg });
cmp_deeply(\@TestAdenosine::curl_options, [
qw(curl -sLv -X HEAD -b), $c, '-c', $c, qw(
-u -I https://google.com/user//1),
], 'HEAD adds -I');
-TestAdenosine->new({ argv => [qw(GET -q foo&bar)] });
+TestAdenosine->new({ argv => [qw(GET -q foo&bar)], @noxdg });
cmp_deeply(\@TestAdenosine::curl_options, [
qw(curl -sLv -X GET -b), $c, '-c', $c, qw(
-H ), 'Accept: text/html', 'https://google.com/user//1?foo%26bar',
], 'GET escaped');
-TestAdenosine->new({ argv => [qw(GET -Q -q foo&bar)] });
+TestAdenosine->new({ argv => [qw(GET -Q -q foo&bar)], @noxdg });
cmp_deeply(\@TestAdenosine::curl_options, [
qw(curl -sLv -X GET -b), $c, '-c', $c, qw(
-H ), 'Accept: text/html', 'https://google.com/user//1?foo&bar',
], 'GET not escaped');
+{
+local $ENV{XDG_CONFIG_HOME} = "$ENV{HOME}/.config";
+my $c = "$ENV{XDG_CONFIG_HOME}/resty/c/google.com";
+TestAdenosine->new({ argv => [qw(GET foo)], });
+cmp_deeply(\@TestAdenosine::curl_options, [
+ qw(curl -sLv -X GET -b), $c, '-c', $c, qw(
+ -H ), 'Accept: text/html', 'https://google.com/user/foo/1',
+], 'GET not escaped');
+}
done_testing;
BEGIN {

0 comments on commit b602b0f

Please sign in to comment.