Skip to content

Commit

Permalink
Use the latest perltidy
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 25, 2025
1 parent 2376b90 commit a9e7e6b
Show file tree
Hide file tree
Showing 28 changed files with 1,696 additions and 655 deletions.
15 changes: 11 additions & 4 deletions examples/login/t/login.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ my $t = Test::Mojo->new('LoginApp');
$t->ua->max_redirects(1);

subtest 'Test login workflow' => sub {
$t->get_ok('/')->status_is(200)->element_exists('form input[name="user"]')->element_exists('form input[name="pass"]')
$t->get_ok('/')
->status_is(200)
->element_exists('form input[name="user"]')
->element_exists('form input[name="pass"]')
->element_exists('form input[type="submit"]');

$t->post_ok('/' => form => {user => 'sebastian', pass => 'secr3t'})->status_is(200)
$t->post_ok('/' => form => {user => 'sebastian', pass => 'secr3t'})
->status_is(200)
->text_like('html body' => qr/Welcome sebastian/);

$t->get_ok('/protected')->status_is(200)->text_like('a' => qr/Logout/);

$t->get_ok('/logout')->status_is(200)->element_exists('form input[name="user"]')
->element_exists('form input[name="pass"]')->element_exists('form input[type="submit"]');
$t->get_ok('/logout')
->status_is(200)
->element_exists('form input[name="user"]')
->element_exists('form input[name="pass"]')
->element_exists('form input[type="submit"]');
};

done_testing();
6 changes: 4 additions & 2 deletions lib/Mojolicious/Command/version.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ EOF

# Check latest version on CPAN
my $latest = eval {
$self->app->ua->max_redirects(10)->tap(sub { $_->proxy->detect })
->get('fastapi.metacpan.org/v1/release/Mojolicious')->result->json->{version};
$self->app->ua->max_redirects(10)
->tap(sub { $_->proxy->detect })
->get('fastapi.metacpan.org/v1/release/Mojolicious')
->result->json->{version};
} or return;

my $msg = 'This version is up to date, have fun!';
Expand Down
9 changes: 7 additions & 2 deletions t/mojo/promise.t
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ subtest 'Resolved chained' => sub {
subtest 'Rejected chained' => sub {
my $promise = Mojo::Promise->new;
my @errors;
$promise->then(undef, sub {"$_[0]:1"})->then(sub {"$_[0]:2"}, sub {"$_[0]:fail"})->then(sub {"$_[0]:3"})
$promise->then(undef, sub {"$_[0]:1"})
->then(sub {"$_[0]:2"}, sub {"$_[0]:fail"})
->then(sub {"$_[0]:3"})
->then(sub { push @errors, "$_[0]:4" });
$promise->reject('tset');
Mojo::IOLoop->one_tick;
Expand Down Expand Up @@ -226,7 +228,10 @@ subtest 'Clone' => sub {
subtest 'Exception in chain' => sub {
my $promise = Mojo::Promise->new;
my (@results, @errors);
$promise->then(sub {@_})->then(sub {@_})->then(sub { die "test: $_[0]\n" })->then(sub { push @results, 'fail' })
$promise->then(sub {@_})
->then(sub {@_})
->then(sub { die "test: $_[0]\n" })
->then(sub { push @results, 'fail' })
->catch(sub { @errors = @_ });
$promise->resolve('works');
Mojo::IOLoop->one_tick;
Expand Down
6 changes: 4 additions & 2 deletions t/mojo/websocket.t
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,10 @@ subtest 'Promises' => sub {
$ua->websocket_p('/foo')->then(sub { $result = 'test failed' })->catch(sub { $result = shift })->wait;
is $result, 'WebSocket handshake failed', 'right result';
$result = undef;
$ua->websocket_p($ua->server->url->to_abs->scheme('wsss'))->then(sub { $result = 'test failed' })
->catch(sub { $result = shift })->wait;
$ua->websocket_p($ua->server->url->to_abs->scheme('wsss'))
->then(sub { $result = 'test failed' })
->catch(sub { $result = shift })
->wait;
is $result, 'Unsupported protocol: wsss', 'right result';
};

Expand Down
377 changes: 272 additions & 105 deletions t/mojolicious/app.t

Large diffs are not rendered by default.

19 changes: 14 additions & 5 deletions t/mojolicious/charset_lite_app.t
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,29 @@ my $t = Test::Mojo->new;
$t->post_ok('/' => form => {foo => 'yatta'})->status_is(200)->content_is('foo: yatta');

# Send raw Shift_JIS octets (like browsers do)
$t->post_ok('/' => form => {foo => $yatta_sjis} => charset => undef)->status_is(200)
->content_type_unlike(qr/application/)->content_type_like(qr/Shift_JIS/)->content_like(qr/$yatta/);
$t->post_ok('/' => form => {foo => $yatta_sjis} => charset => undef)
->status_is(200)
->content_type_unlike(qr/application/)
->content_type_like(qr/Shift_JIS/)
->content_like(qr/$yatta/);

# Send raw Shift_JIS octets (like browsers do, multipart message)
$t->post_ok('/' => {'Content-Type' => 'multipart/form-data'} => form => {foo => $yatta_sjis} => charset => undef)
->status_is(200)->content_type_like(qr/Shift_JIS/)->content_like(qr/$yatta/);
->status_is(200)
->content_type_like(qr/Shift_JIS/)
->content_like(qr/$yatta/);

# Send as string
$t->post_ok('/' => form => {foo => $yatta} => charset => 'shift_jis')->status_is(200)->content_type_like(qr/Shift_JIS/)
$t->post_ok('/' => form => {foo => $yatta} => charset => 'shift_jis')
->status_is(200)
->content_type_like(qr/Shift_JIS/)
->content_like(qr/$yatta/);

# Send as string (multipart message)
$t->post_ok('/' => {'Content-Type' => 'multipart/form-data'} => form => {foo => $yatta} => charset => 'shift_jis')
->status_is(200)->content_type_like(qr/Shift_JIS/)->content_like(qr/$yatta/);
->status_is(200)
->content_type_like(qr/Shift_JIS/)
->content_like(qr/$yatta/);

# Unicode renderer
$t->get_ok('/unicode')->status_is(200)->content_type_is('text/plain;charset=UTF-8')->content_is($yatta);
Expand Down
20 changes: 15 additions & 5 deletions t/mojolicious/dispatcher_lite_app.t
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ subtest 'Normal route' => sub {
};

subtest 'Normal static file' => sub {
$t->get_ok('/test.txt')->status_is(200)->header_is('Cache-Control' => 'max-age=3600, must-revalidate')
$t->get_ok('/test.txt')
->status_is(200)
->header_is('Cache-Control' => 'max-age=3600, must-revalidate')
->content_is("Normal static file!\n");
};

Expand All @@ -144,22 +146,30 @@ subtest 'Custom dispatcher' => sub {
};

subtest 'Static file' => sub {
$t->get_ok('/res.txt')->status_is(200)->header_is('Cache-Control' => 'max-age=3600, must-revalidate')
$t->get_ok('/res.txt')
->status_is(200)
->header_is('Cache-Control' => 'max-age=3600, must-revalidate')
->content_is("Static response!\n");
};

subtest ' Custom response' => sub {
$t->get_ok('/res.txt?route=1')->status_is(202)->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate')
$t->get_ok('/res.txt?route=1')
->status_is(202)
->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate')
->content_is('Custom response!');
};

subtest 'Conditional response' => sub {
$t->get_ok('/res.txt?route=1&res=1')->status_is(201)->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate')
$t->get_ok('/res.txt?route=1&res=1')
->status_is(201)
->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate')
->content_is('Conditional response!');
};

subtest 'Another custom dispatcher' => sub {
$t->get_ok('/custom_too')->status_is(200)->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate')
$t->get_ok('/custom_too')
->status_is(200)
->header_isnt('Cache-Control' => 'max-age=3600, must-revalidate')
->content_is('this works too');
};

Expand Down
37 changes: 27 additions & 10 deletions t/mojolicious/embedded_lite_app.t
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ subtest 'Stream from myapp.pl with Unicode prefix' => sub {
};

subtest 'URL from myapp.pl with Unicode prefix' => sub {
$t->get_ok('/x/♥/url/☃')->status_is(200)
$t->get_ok('/x/♥/url/☃')
->status_is(200)
->content_is('/x/%E2%99%A5/url/%E2%98%83.json -> /x/%E2%99%A5/%E2%98%83/stream!');
};

Expand Down Expand Up @@ -326,7 +327,9 @@ EOF
};

subtest 'Host from myapp.pl with domain' => sub {
$t->get_ok('/host' => {Host => 'mojolicious.org'})->status_is(200)->header_is('X-Message' => 'it works!')
$t->get_ok('/host' => {Host => 'mojolicious.org'})
->status_is(200)
->header_is('X-Message' => 'it works!')
->content_is('mojolicious.org');
};

Expand All @@ -344,7 +347,9 @@ EOF
};

subtest 'Host from myapp.pl with domain again' => sub {
$t->get_ok('/host' => {Host => 'mojolicious.org'})->status_is(200)->header_is('X-Message' => 'it works!')
$t->get_ok('/host' => {Host => 'mojolicious.org'})
->status_is(200)
->header_is('X-Message' => 'it works!')
->content_is('mojolicious.org');
};

Expand All @@ -362,17 +367,23 @@ EOF
};

subtest 'Host from myapp.pl with wildcard domain' => sub {
$t->get_ok('/host' => {Host => 'ExAmPlE.CoM'})->status_is(200)->header_is('X-Message' => 'it works!')
$t->get_ok('/host' => {Host => 'ExAmPlE.CoM'})
->status_is(200)
->header_is('X-Message' => 'it works!')
->content_is('ExAmPlE.CoM');
};

subtest 'Host from myapp.pl with wildcard domain again' => sub {
$t->get_ok('/host' => {Host => 'www.example.com'})->status_is(200)->header_is('X-Message' => 'it works!')
$t->get_ok('/host' => {Host => 'www.example.com'})
->status_is(200)
->header_is('X-Message' => 'it works!')
->content_is('www.example.com');
};

subtest 'Host from myapp.pl with wildcard domain again' => sub {
$t->get_ok('/host' => {Host => 'foo.bar.example.com'})->status_is(200)->header_is('X-Message' => 'it works!')
$t->get_ok('/host' => {Host => 'foo.bar.example.com'})
->status_is(200)
->header_is('X-Message' => 'it works!')
->content_is('foo.bar.example.com');
};

Expand All @@ -390,7 +401,9 @@ EOF
};

subtest 'Host from myapp.pl with wildcard domain and Unicode prefix' => sub {
$t->get_ok('/♥/123/host' => {Host => 'foo-bar.de'})->status_is(200)->header_is('X-Message' => 'it works!')
$t->get_ok('/♥/123/host' => {Host => 'foo-bar.de'})
->status_is(200)
->header_is('X-Message' => 'it works!')
->content_is('foo-bar.de');
};

Expand All @@ -399,7 +412,9 @@ subtest 'Echo from myapp.pl with wildcard domain and Unicode prefix' => sub {
};

subtest 'Host from myapp.pl with wildcard domain and Unicode prefix again' => sub {
$t->get_ok('/♥/123/host' => {Host => 'www.foo-bar.de'})->status_is(200)->header_is('X-Message' => 'it works!')
$t->get_ok('/♥/123/host' => {Host => 'www.foo-bar.de'})
->status_is(200)
->header_is('X-Message' => 'it works!')
->content_is('www.foo-bar.de');
};

Expand All @@ -424,8 +439,10 @@ subtest 'Another invalid domain' => sub {
};

subtest 'Embedded WebSocket' => sub {
$t->websocket_ok('/x/♥/url_for')->send_ok('ws_test')
->message_ok->message_like(qr!^ws://127\.0\.0\.1:\d+/x/%E2%99%A5/url_for$!)->send_ok('index')
$t->websocket_ok('/x/♥/url_for')
->send_ok('ws_test')
->message_ok->message_like(qr!^ws://127\.0\.0\.1:\d+/x/%E2%99%A5/url_for$!)
->send_ok('index')
->message_ok->message_like(qr!^http://127\.0\.0\.1:\d+/x/%E2%99%A5$!)->finish_ok;
};

Expand Down
Loading

0 comments on commit a9e7e6b

Please sign in to comment.