Class: TF

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

Defined Under Namespace

Classes: CommentTestInput, EnvArrTest, EnvMatchTest, EnvTypeTest, Environment, ErrorSummaryOutput, OutputMatchTest, Plugins, StatsOutput, StatusTest, TextOutput

Instance Method Summary collapse

Constructor Details

#initializeTF

Returns a new instance of TF.



17
18
19
20
21
# File 'lib/tf.rb', line 17

def initialize
  @ruby = File.join(RbConfig::CONFIG["bindir"],RbConfig::CONFIG["ruby_install_name"])
  @plugins = TF::Plugins.instance
  @failures = 0
end

Instance Method Details

#env(shell) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/tf.rb', line 43

def env shell
  TF::Environment.parse_env(
    shell.execute(
      TF::Environment.show_env_command
    )[0].split(/\n/)
  )
end

#process(input_files) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/tf.rb', line 35

def process input_files
  @plugins.output_plugins(:start_processing)
  input_files.each do |plugin,file|
    process_test( plugin.load(file) )
  end
  @plugins.output_plugins(:end_processing)
end

#process_command_tests(_stdout, _stderr, _stdboth, _status, env, tests) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/tf.rb', line 85

def process_command_tests _stdout, _stderr, _stdboth, _status, env, tests
  tests.each do |test|
    plugin = @plugins.test_plugins.find{|_plugin| _plugin.matches? test }
    if plugin.nil?
      status, msg = false, "Could not find plugin for test '#{test}'."
    else
      status, msg = plugin.execute(test, _stdout, _stderr, _stdboth, _status, env)
    end
    @failures+=1 unless status
    @plugins.output_plugins(:test_processed, test, status, msg)
  end
end

#process_test(test) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/tf.rb', line 51

def process_test test
  name, commands, execution_shell = test[:name], test[:commands], test[:shell]
  shell = Session::Sh.new(:prog => execution_shell)
  _env = env(shell)
  @plugins.output_plugins(:start_test, test, _env)
  commands.each do |line|
    command, tests = line[:cmd], line[:tests]
    @plugins.output_plugins(:start_command, line)
    _stdout  = StringIO.new
    _stderr  = StringIO.new
    _stdboth = StringIO.new
    shell.execute "#{command}" do |out, err|
      if out
        @plugins.output_plugins(:command_out, out)
        _stdout  << out
        _stdboth << out
      end
      if err
        @plugins.output_plugins(:command_err, err)
        _stderr  << err
        _stdboth << err
      end
    end
    _status = shell.status
    _env = env(shell)
    @plugins.output_plugins(:end_command, line, _status, _env)
    process_command_tests _stdout.string, _stderr.string, _stdboth.string, _status, _env, tests
  end
  @plugins.output_plugins(:end_test, test)
rescue SystemExit, Interrupt
  shell.close!
  raise
end

#run_tests(args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tf.rb', line 23

def run_tests args
  @plugins.load(%w( all_test ))
  input_files, not_processed = @plugins.parse_args(args)
  if not_processed.size > 0
    $stderr.puts "No plugin recognized this option '#{not_processed*" "}'."
    exit 1
  end
  @plugins.load(%w( ErrorSummaryOutput )) if @plugins.output_plugins.empty?
  process(input_files)
  @failures == 0
end