source:
branches/UKMO/r5936_CO6_CO5_shelfdiagnostic/NEMOGCM/EXTERNAL/fcm/t/Fcm/Util/ClassLoader.t
@
7113
Last change on this file since 7113 was 7113, checked in by jcastill, 8 years ago | |
---|---|
File size: 1.2 KB |
Rev | Line | |
---|---|---|
[1980] | 1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | ################################################################################ | |
7 | # A class for testing the loader | |
8 | { | |
9 | package MyTestClass; | |
10 | ||
11 | sub new { | |
12 | my ($class) = @_; | |
13 | return bless(\do{my $annon_scalar}, $class); | |
14 | } | |
15 | } | |
16 | ||
17 | use Test::More qw{no_plan}; | |
18 | ||
19 | main(); | |
20 | ||
21 | sub main { | |
22 | use_ok('Fcm::Util::ClassLoader'); | |
23 | test_normal(); | |
24 | test_bad(); | |
25 | } | |
26 | ||
27 | ################################################################################ | |
28 | # Tests loading classes that should load OK | |
29 | sub test_normal { | |
30 | my $prefix = 'normal'; | |
31 | my @CLASSES = ( | |
32 | 'Fcm::CLI::Config', | |
33 | 'Fcm::Exception', | |
34 | 'Fcm::CLI::Config', # repeat | |
35 | 'MyTestClass', | |
36 | ); | |
37 | for my $class (@CLASSES) { | |
38 | ok(Fcm::Util::ClassLoader::load($class), "$prefix: load $class"); | |
39 | } | |
40 | } | |
41 | ||
42 | ################################################################################ | |
43 | # Tests loading classes that should fail | |
44 | sub test_bad { | |
45 | my $prefix = 'bad'; | |
46 | my @CLASSES = ('Foo', 'Bar', 'Baz', 'No::Such::Class', 'Foo'); | |
47 | for my $class (@CLASSES) { | |
48 | eval { | |
49 | Fcm::Util::ClassLoader::load($class); | |
50 | }; | |
51 | isa_ok($@, 'Fcm::Exception', "$prefix: load $class"); | |
52 | } | |
53 | } | |
54 | ||
55 | __END__ |
Note: See TracBrowser
for help on using the repository browser.