From bc17ed3dec538e8124606bccaab3b33bf1b94665 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Fri, 7 Aug 2015 14:30:11 +0300 Subject: Ensure that we correctly parse bogus macro-definitions. We've always had an implicit rule in macro-definitions, that they end with a period. This meant that the first line is valid: FOO is bar.vm.bytemark.co.uk. However we'd expect this to fail: FOO is bar.vm.bytemark.co.uk A similar issue would arise if a macro-definition involved more than one host, only the first would be valid. We've fixed this now, such that the trailing period is optional. --- lib/custodian/parser.rb | 2 +- t/test-custodian-parser.rb | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/custodian/parser.rb b/lib/custodian/parser.rb index 1f59d26..a0f24c1 100644 --- a/lib/custodian/parser.rb +++ b/lib/custodian/parser.rb @@ -141,7 +141,7 @@ module Custodian val.push(line) if line.length > 0 end - elsif line =~ /\s(is|are)\s+(.*)\.+$/ + elsif line =~ /\s(is|are)\s+(.*)\.*$/ # # Literal list of hosts diff --git a/t/test-custodian-parser.rb b/t/test-custodian-parser.rb index aff1e9c..ddc1153 100755 --- a/t/test-custodian-parser.rb +++ b/t/test-custodian-parser.rb @@ -159,6 +159,60 @@ EOF end + # + # Test a macro-definition without a trailing period + # + def test_macros_lines_no_period + + parser = Custodian::Parser.new + + # + # Input text + # + text = <= 0 , + "We found the expected host: kvm1") + assert( one.find_index( "kvm2.vm.bytemark.co.uk" ) >= 0 , + "We found the expected host: kvm2") + + assert( two.kind_of? Array ) + assert( two.size() == 2, "Both targets are in the macro" ) + assert( two.find_index( "kvm1.vm.bytemark.co.uk" ) >= 0 , + "We found the expected host: kvm1") + assert( two.find_index( "kvm2.vm.bytemark.co.uk" ) >= 0 , + "We found the expected host: kvm2") + + end # -- cgit v1.2.1