author-classSafety.t 975 B

1234567891011121314151617181920212223242526272829
  1. use strict;
  2. use warnings;
  3. use TestRail::API;
  4. use Test::More;
  5. use Test::Fatal;
  6. use Class::Inspector;
  7. my $tr = TestRail::API->new('http://hokum.bogus','bogus','bogus',1);
  8. #Call instance methods as class and vice versa
  9. like( exception {$tr->new();}, qr/.*must be called statically.*/, "Calling constructor on instance dies");
  10. my @methods = Class::Inspector->methods('TestRail::API');
  11. my @excludeModules = qw{Scalar::Util Carp Clone Try::Tiny JSON::XS HTTP::Request LWP::UserAgent Types::Serialiser Data::Validate::URI};
  12. my @tmp = ();
  13. my @excludedMethods = ();
  14. foreach my $module (@excludeModules) {
  15. @tmp = Class::Inspector->methods($module);
  16. push(@excludedMethods,@{$tmp[0]});
  17. }
  18. foreach my $method (@{$methods[0]}) {
  19. next if grep {$method eq $_} qw{new buildStepResults};
  20. next if grep {$_ eq $method} @excludedMethods;
  21. like( exception {TestRail::API->$method}, qr/.*called by an instance.*/ , "Calling $method requires an instance");
  22. }
  23. done_testing();