From d896e42306c5c7761a14a2d88b6d2ed04401b03c Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Thu, 15 Nov 2012 08:17:13 +0000 Subject: Throw an exception if we attempt to redefine a macro. --- lib/custodian/parser.rb | 4 ++++ t/test-parser.rb | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/custodian/parser.rb b/lib/custodian/parser.rb index 7ed7a51..268dd3b 100755 --- a/lib/custodian/parser.rb +++ b/lib/custodian/parser.rb @@ -190,6 +190,10 @@ class MonitorConfig end + if ( is_macro?( name ) ) + raise ArgumentError, "The macro #{name} is already defined" + end + @MACROS[name] = val end diff --git a/t/test-parser.rb b/t/test-parser.rb index c3e782f..f405433 100755 --- a/t/test-parser.rb +++ b/t/test-parser.rb @@ -57,7 +57,6 @@ class TestParser < Test::Unit::TestCase assert_nothing_raised do MonitorConfig.new("/dev/null" ) end - end @@ -171,6 +170,41 @@ class TestParser < Test::Unit::TestCase + # + # Redefinining a macro should cause an error + # + def test_duplicate_macro + + + # + # Create the parser. + # + parser = MonitorConfig.new("/dev/null" ) + + + # + # With nothing loaded we should have zero macros - so the + # count of our macros hash should be zero + # + macros = parser.macros + assert( macros.empty? ) + assert( macros.size() == 0 ) + + + # + # Define a macro twice. The first will work, the second will fail + # + assert_nothing_raised do + parser.define_macro( "FOO is kvm1.vm.bytemark.co.uk and kvm2.vm.bytemark.co.uk." ) + end + + assert_raise ArgumentError do + parser.define_macro( "FOO is kvm1.vm.bytemark.co.uk and kvm2.vm.bytemark.co.uk." ) + end + end + + + # # Test that we can define macros with only a single host. -- cgit v1.2.1