class TF::EnvMatchTest

Constants

MATCHER

Public Instance Methods

execute(test, _stdout, _stderr, _stdboth, _status, env) click to toggle source
# File lib/plugins/tf/env_match_test.rb, line 8
def execute test, _stdout, _stderr, _stdboth, _status, env
  test =~ TF::EnvMatchTest::MATCHER
  variable, sign, value = $1.strip, $2, $3
  var_val = env[ variable ]
  if  !(var_val.nil?) && !(var_val.is_a?(String))
    $stderr.puts "Not a string: #{var_val}, type:#{var_val.class}." if ENV["TF_DEBUG"]
    return [ false, "failed: env #{variable} #{sign} /#{value}/ # not a string" ]
  end
  if ( sign == "=" ) ^ ( Regexp.new(value) =~ "#{var_val}" )
    [ false, "failed: env #{variable} #{sign} /#{value}/ # was '#{var_val}'" ]
  else
    [ true, "passed: env #{variable} #{sign} /#{value}/" ]
  end
end
matches?(test) click to toggle source
# File lib/plugins/tf/env_match_test.rb, line 4
def matches? test
  test =~ TF::EnvMatchTest::MATCHER
end