Class: TF::OutputMatchTest

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins/tf/output_match_test.rb

Constant Summary collapse

MATCHER =
/^match(\[(stdout|stderr)\])?([!]?=)[~]?\/(.*)\/$/

Instance Method Summary collapse

Instance Method Details

#execute(test, _stdout, _stderr, _stdboth, _status, env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/plugins/tf/output_match_test.rb', line 8

def execute test, _stdout, _stderr, _stdboth, _status, env
  test =~ TF::OutputMatchTest::MATCHER
  _, type, sign, value = $1, $2, $3, $4
  test_val, match_type =
    case type
    when "stdout" then [ _stdout, "[#{type}]" ]
    when "stderr" then [ _stderr, "[#{type}]" ]
    when nil      then [ _stdboth, "" ]
    else return [ false, "failed: match[#{type}] #{sign} /#{value}/ # unknown output type" ]
    end
  if ( sign == "=" ) ^ ( Regexp.new(value) =~ "#{test_val}" )
    [ false, "failed: match#{match_type} #{sign} /#{value}/" ]
  else
    [ true, "passed: match#{match_type} #{sign} /#{value}/" ]
  end
end

#matches?(test) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/plugins/tf/output_match_test.rb', line 4

def matches? test
  test =~ TF::OutputMatchTest::MATCHER
end