/
githubmirror
/
device-mapper-test-suite
Обзор
Документация
Войти
/
githubmirror
/
device-mapper-test-suite
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
lib/dmtest/test-utils.rb
49 строк
1 KB
Joe Thornber
fluff
17 ноя 2015, 13:50
17 ноя 2015, 13:50
68eaa2b
Код
Авторство
О чём код?
# Utils to help define tests module TestUtils # We often want to define a set of tests with different start # parameters. Rather than laboriously defining them all you can # just give this class method the sets of arguments you want to # range over and it'll define all the test methods for you. # # eg, # define_test_across(:thin_on_striped, [1, 2, 3], [:ext4, :xfs]) # # will define these tests # # test_thin_on_striped_1_ext4 # test_thin_on_striped_1_xfs # test_thin_on_striped_2_ext4 # test_thin_on_striped_2_xfs # test_thin_on_striped_3_ext4 # test_thin_on_striped_3_xfs def define_tests_across(method, *args) cartprod(*args).each do |perm| method_name = "#{method}_#{perm.join('_')}" define_test(method_name) do send(method, *perm) end end end def define_test(method, &block) method_name = "test_#{method}" define_method(method_name, &block) end private def cartprod(*args) result = [[]] while [] != args t, result = result, [] b, *args = args t.each do |a| b.each do |n| result << a + [n] end end end result end end