Commit 6f0528591fd1a7b6efd174366c4bb6c9afb3e42a
1 parent
e44679ef
Exists in
master
and in
29 other branches
plugins-test: improve infra to allow running tests individually
Showing
1 changed file
with
72 additions
and
36 deletions
Show diff stats
lib/tasks/plugins_tests.rake
... | ... | @@ -25,51 +25,87 @@ def plugin_disabled_warning(plugin) |
25 | 25 | puts "E: you should enable #{plugin} plugin before running it's tests!" |
26 | 26 | end |
27 | 27 | |
28 | -def run_tests(name, files_glob) | |
29 | - files = Dir.glob(files_glob) | |
30 | - if files.empty? | |
31 | - puts "I: no tests to run (#{name})" | |
28 | +def task2ext(task) | |
29 | + (task == :selenium || task == :cucumber) ? :feature : :rb | |
30 | +end | |
31 | + | |
32 | +def task2profile(task, plugin) | |
33 | + if task == :cucumber | |
34 | + return plugin | |
35 | + elsif task == :selenium | |
36 | + return "#{plugin}_selenium" | |
32 | 37 | else |
33 | - sh 'testrb', '-Itest', *files | |
38 | + return 'default' | |
34 | 39 | end |
35 | 40 | end |
36 | 41 | |
37 | -def run_cucumber(name, profile, files_glob) | |
38 | - files = Dir.glob(files_glob) | |
39 | - if files.empty? | |
40 | - puts "I: no tests to run #{name}" | |
42 | +def filename2plugin(filename) | |
43 | + filename.split('/')[1] | |
44 | +end | |
45 | + | |
46 | +def task2folder(task) | |
47 | + result = case task.to_sym | |
48 | + when :units | |
49 | + :unit | |
50 | + when :functionals | |
51 | + :functional | |
52 | + when :integration | |
53 | + :integration | |
54 | + when :cucumber | |
55 | + :features | |
56 | + when :selenium | |
57 | + :features | |
58 | + end | |
59 | + | |
60 | + return result | |
61 | +end | |
62 | + | |
63 | +def run_test(name, files) | |
64 | + files = Array(files) | |
65 | + plugin = filename2plugin(files.first) | |
66 | + if name == :cucumber || name == :selenium | |
67 | + run_cucumber task2_profile(name, plugin), files | |
41 | 68 | else |
42 | - sh 'xvfb-run', 'ruby', '-S', 'cucumber', '--profile', profile.to_s, '--format', ENV['CUCUMBER_FORMAT'] || 'progress' , *files | |
69 | + run_testrb files | |
43 | 70 | end |
44 | 71 | end |
45 | 72 | |
46 | -def plugin_test_task(name, plugin, files_glob) | |
47 | - desc "Run #{name} tests for #{plugin_name(plugin)}" | |
48 | - task name => 'db:test:plugins:prepare' do |t| | |
49 | - if plugin_enabled?(plugin) | |
50 | - run_tests t.name, files_glob | |
51 | - else | |
52 | - plugin_disabled_warning(plugin) | |
73 | +def run_testrb(files) | |
74 | + sh 'testrb', '-Itest', *files | |
75 | +end | |
76 | + | |
77 | +def run_cucumber(profile, files) | |
78 | + sh 'xvfb-run', 'ruby', '-S', 'cucumber', '--profile', profile.to_s, '--format', ENV['CUCUMBER_FORMAT'] || 'progress' , *files | |
79 | +end | |
80 | + | |
81 | +def custom_run(name, files, run=:individually) | |
82 | + case run | |
83 | + when :all | |
84 | + run_test name, files | |
85 | + when :individually | |
86 | + files.each do |file| | |
87 | + run_test name, file | |
53 | 88 | end |
89 | + when :by_plugin | |
54 | 90 | end |
55 | 91 | end |
56 | 92 | |
57 | -def plugin_cucumber_task(name, plugin, files_glob) | |
58 | - desc "Run #{name} tests for #{plugin_name(plugin)}" | |
59 | - task name => 'db:test:plugins:prepare' do |t| | |
60 | - if plugin_enabled?(plugin) | |
61 | - run_cucumber t.name, plugin, files_glob | |
62 | - else | |
63 | - plugin_disabled_warning(plugin) | |
64 | - end | |
93 | +def run_tests(name, plugins, run=:individually) | |
94 | + plugins = Array(plugins) | |
95 | + glob = "plugins/{#{plugins.join(',')}}/test/#{task2folder(name)}/**/*.#{task2ext(name)}" | |
96 | + files = Dir.glob(glob) | |
97 | + if files.empty? | |
98 | + puts "I: no tests to run #{name}" | |
99 | + else | |
100 | + custom_run(name, files, run) | |
65 | 101 | end |
66 | 102 | end |
67 | 103 | |
68 | -def plugin_selenium_task(name, plugin, files_glob) | |
104 | +def plugin_test_task(name, plugin, run=:individually) | |
69 | 105 | desc "Run #{name} tests for #{plugin_name(plugin)}" |
70 | 106 | task name => 'db:test:plugins:prepare' do |t| |
71 | 107 | if plugin_enabled?(plugin) |
72 | - run_cucumber t.name, "#{plugin}_selenium", files_glob | |
108 | + run_tests(name, plugin, run) | |
73 | 109 | else |
74 | 110 | plugin_disabled_warning(plugin) |
75 | 111 | end |
... | ... | @@ -98,28 +134,28 @@ namespace :test do |
98 | 134 | namespace :noosfero_plugins do |
99 | 135 | all_plugins.each do |plugin| |
100 | 136 | namespace plugin do |
101 | - plugin_test_task :units, plugin, "plugins/#{plugin}/test/unit/**/*.rb" | |
102 | - plugin_test_task :functionals, plugin, "plugins/#{plugin}/test/functional/**/*.rb" | |
103 | - plugin_test_task :integration, plugin, "plugins/#{plugin}/test/integration/**/*.rb" | |
104 | - plugin_cucumber_task :cucumber, plugin, "plugins/#{plugin}/features/**/*.feature" | |
105 | - plugin_selenium_task :selenium, plugin, "plugins/#{plugin}/features/**/*.feature" | |
137 | + plugin_test_task :units, plugin | |
138 | + plugin_test_task :functionals, plugin | |
139 | + plugin_test_task :integration, plugin | |
140 | + plugin_test_task :cucumber, plugin | |
141 | + plugin_test_task :selenium, plugin | |
106 | 142 | end |
107 | 143 | |
108 | 144 | test_sequence_task(plugin, plugin, "#{plugin}:units", "#{plugin}:functionals", "#{plugin}:integration", "#{plugin}:cucumber", "#{plugin}:selenium") |
109 | 145 | end |
110 | 146 | |
111 | - { :units => :unit , :functionals => :functional , :integration => :integration }.each do |taskname,folder| | |
147 | + [:units, :functionals, :integration].each do |taskname| | |
112 | 148 | task taskname => 'db:test:plugins:prepare' do |t| |
113 | - run_tests t.name, "plugins/{#{enabled_plugins.join(',')}}/test/#{folder}/**/*.rb" | |
149 | + run_tests taskname, enabled_plugins | |
114 | 150 | end |
115 | 151 | end |
116 | 152 | |
117 | 153 | task :cucumber => 'db:test:plugins:prepare' do |t| |
118 | - run_cucumber t.name, :default, "plugins/{#{enabled_plugins.join(',')}}/test/features/**/*.features" | |
154 | + run_tests :cucumber, enabled_plugins | |
119 | 155 | end |
120 | 156 | |
121 | 157 | task :selenium => 'db:test:plugins:prepare' do |t| |
122 | - run_cucumber t.name, :selenium, "plugins/{#{enabled_plugins.join(',')}}/test/features/**/*.features" | |
158 | + run_tests :selenium, enabled_plugins | |
123 | 159 | end |
124 | 160 | |
125 | 161 | task :temp_enable_all_plugins do | ... | ... |