File: openapi-compatibility.t

package info (click to toggle)
libjson-validator-perl 0.92%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 408 kB
  • ctags: 89
  • sloc: perl: 1,009; makefile: 6
file content (50 lines) | stat: -rw-r--r-- 1,088 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use Mojo::Base -strict;

use File::Spec;
use Mojo::Util;
use Test::More;

ok(
  module_calls_deprecated('JSON::Validator::OpenAPI'),
  "JSON::Validator::OpenAPI->validate_request is deprecated"
);


if (eval 'require Hash::MultiValue;1') {
  ok(
    !module_calls_deprecated('JSON::Validator::OpenAPI::Dancer2'),
    "JSON::Validator::OpenAPI::Dancer2->validate_request isn't deprecated"
  );
}
else {
  ok 1, 'Skipping JSON::Validator::OpenAPI::Dancer2 test';
}

ok(
  !module_calls_deprecated('JSON::Validator::OpenAPI::Mojolicious'),
  "JSON::Validator::OpenAPI::Mojolicious->validate_request isn't deprecated"
);

done_testing;

sub module_calls_deprecated {
  my $module = shift;

  my $called = 0;
  {
    no warnings 'redefine';
    *Mojo::Util::deprecated = sub { ++$called };
  }

  my $c      = {};
  my $schema = {parameters => [{name => 'foo', in => 'query', type => 'integer'}]};
  my $input  = {};

  eval "require $module" or die $@;

  eval {    # we don't care if this actually works out
    $module->new->validate_request($c, $schema, $input);
  };

  return $called;
}