New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
ConfigSystem.t in branches/UKMO/r5518_INGV1_WAVE-coupling/NEMOGCM/EXTERNAL/fcm/t/Fcm/CLI/Invoker – NEMO

source: branches/UKMO/r5518_INGV1_WAVE-coupling/NEMOGCM/EXTERNAL/fcm/t/Fcm/CLI/Invoker/ConfigSystem.t @ 7152

Last change on this file since 7152 was 7152, checked in by jcastill, 7 years ago

Initial implementation of wave coupling branch - INGV wave branch + UKMO wave coupling branch

  • Property svn:executable set to *
File size: 2.8 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6################################################################################
7# A mock Fcm::ConfigSystem object
8{
9    package MockConfigSystem;
10    use base qw{Fcm::ConfigSystem};
11
12    our $LATEST_INVOKED_INSTANCE;
13
14    ############################################################################
15    # Returns the arguments to the last invoke() call
16    sub get_invoke_args {
17        my ($self) = @_;
18        return $self->{invoke_args};
19    }
20
21    ############################################################################
22    # Does nothing but captures the arguments
23    sub invoke {
24        my ($self, %args) = @_;
25        $LATEST_INVOKED_INSTANCE = $self;
26        $self->{invoke_args} = \%args;
27        return 1;
28    }
29}
30
31use Cwd;
32use Test::More qw{no_plan};
33
34main();
35
36sub main {
37    my $class = 'Fcm::CLI::Invoker::ConfigSystem';
38    use_ok($class);
39    test_invoke($class);
40}
41
42################################################################################
43# Tests normal usage of invoke()
44sub test_invoke {
45    my ($class) = @_;
46    my $prefix = "invoke";
47    my %TEST = (
48        test1 => {
49            command            => 'pig',
50            options            => {'egg' => 1},
51            arguments          => ['bacon'],
52            expected_options   => {FOO => undef, BAR_BAZ => undef, EGGS => 1},
53            expected_arguments => 'bacon',
54        },
55        test2 => {
56            command            => 'pig',
57            options            => {'foo' => 1, 'bar-baz' => 1},
58            arguments          => [],
59            expected_options   => {FOO => 1, BAR_BAZ => 1, EGGS => undef},
60            expected_arguments => cwd(),
61        }
62    );
63    for my $key (keys(%TEST)) {
64        my $invoker = $class->new({
65            command            => $TEST{$key}{command},
66            options            => $TEST{$key}{options},
67            arguments          => $TEST{$key}{arguments},
68            impl_class         => 'MockConfigSystem',
69            cli2invoke_key_map => {
70                'foo' => 'FOO', 'bar-baz' => 'BAR_BAZ', 'egg' => 'EGGS',
71            },
72        });
73        isa_ok($invoker, 'Fcm::CLI::Invoker::ConfigSystem', "$prefix: $key");
74        $invoker->invoke();
75        my $config_system_instance = $MockConfigSystem::LATEST_INVOKED_INSTANCE;
76        isa_ok(
77            $config_system_instance,
78            'Fcm::ConfigSystem',
79            "$prefix: $key: Fcm::ConfigSystem",
80        );
81        is(
82            $config_system_instance->cfg()->src(),
83            $TEST{$key}{expected_arguments},
84            "$prefix: $key: cfg()->src()",
85        );
86        is_deeply(
87            $config_system_instance->get_invoke_args(),
88            $TEST{$key}{expected_options},
89            "$prefix: $key: invoke args",
90        );
91    }
92}
93
94__END__
Note: See TracBrowser for help on using the repository browser.