Class: Testplan::Build

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

Class Method Summary collapse

Class Method Details

.build_platform_exec_strings(platform, format, execute_all_at_once) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/testplan.rb', line 41

def self.build_platform_exec_strings(platform, format, execute_all_at_once)
  envstring = make_env_string(platform)
  estrings = []

  if execute_all_at_once

    print "\nRunning all testcases at once with ENV: #{envstring}\n"

    exec_string = "#{envstring}bundle exec rake #{format.to_s} SPEC_OPTS=\""
    @@config[:platforms][platform][:cases].each do | acase |

      exec_string += " -e #{acase} "
      print "  - testcase #{acase}\n"
    end

    exec_string += "\""
    estrings << exec_string

  else
    @@config[:platforms][platform][:cases].each do | acase |

      exec_string = "#{envstring}bundle exec rake #{format.to_s} SPEC_OPTS=\"-e #{acase}\""
      print "\nRunning testcase #{acase} with ENV: #{envstring}\n"

      estrings << exec_string
    end
  end

  estrings
end

.execute_strings(exec_strings) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/testplan.rb', line 72

def self.execute_strings(exec_strings)
  exit_code = 0
  exec_strings.each do |estring|
    p estring
    exit_code += 1 unless system estring
  end

  if exit_code == 1
    raise 'At least one test failed'
  elsif exit_code > 1
    raise "There were #{exit_code} failed tests."
  end

  exit_code
end

.initObject



37
38
39
# File 'lib/testplan.rb', line 37

def self.init
  @@config = $initconf.call
end

.make_env_string(platform) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/testplan.rb', line 95

def self.make_env_string(platform)
  envarr = {}
  @@config[:platforms][platform].each do | k,v|
    envarr[k.to_s] = v unless k == :cases
  end

  case RbConfig::CONFIG['host_os']
  when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
    envstring = make_env_string_win(envarr)
  else
    envstring = make_env_string_unix(envarr)
  end

  envstring
end

.make_env_string_unix(envarr) ⇒ Object



111
112
113
114
115
116
117
# File 'lib/testplan.rb', line 111

def self.make_env_string_unix(envarr)
  envstr=''
  envarr.each do | varname,varvalue|
    envstr+= "#{varname.upcase}='#{varvalue}' "
  end
  return envstr
end

.make_env_string_win(envarr) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/testplan.rb', line 119

def self.make_env_string_win(envarr)
  envstr=''
  envarr.each do | varname,varvalue|
    envstr+= "set #{varname.upcase}=#{varvalue} &"
  end
  return envstr
end

.plan_in_format(plan, format, execute_all_at_once = false) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/testplan.rb', line 19

def self.plan_in_format(plan, format, execute_all_at_once = false)
  self.init
  validate_plan_name(plan)
  exec_strings = []
  @@config[:testplans][plan].each do |platform|
    exec_strings += self.build_platform_exec_strings(platform, format, execute_all_at_once)
  end

  return self.execute_strings(exec_strings)

end

.platform_in_format(platform, format, execute_all_at_once = false) ⇒ Object



31
32
33
34
35
# File 'lib/testplan.rb', line 31

def self.platform_in_format(platform, format, execute_all_at_once = false)
  self.init
  exec_strings = self.build_platform_exec_strings(platform, format, execute_all_at_once)
  return self.execute_strings(exec_strings)
end

.validate_plan_name(plan_name) ⇒ Object



89
90
91
92
93
# File 'lib/testplan.rb', line 89

def self.validate_plan_name(plan_name)
  if !@@config[:testplans].has_key?(plan_name)
     raise 'Plan name does not exist'
  end
end