|
1 | | -COCKROACHDB_TEST_HELPER = 'test/cases/helper_cockroachdb.rb' |
2 | | - |
3 | | -def test_files |
4 | | - env_activerecord_test_files || |
5 | | - env_cockroachdb_test_files || |
6 | | - only_activerecord_test_files || |
7 | | - only_cockroachdb_test_files || |
8 | | - all_test_files |
9 | | -end |
| 1 | +# frozen_string_literal: true |
10 | 2 |
|
11 | | -def env_activerecord_test_files |
12 | | - return unless ENV['TEST_FILES_AR'] && !ENV['TEST_FILES_AR'].empty? |
| 3 | +module RakeHelpers |
| 4 | + COCKROACHDB_TEST_HELPER = 'test/cases/helper_cockroachdb.rb' |
13 | 5 |
|
14 | | - @env_ar_test_files ||= ENV['TEST_FILES_AR']. |
15 | | - split(','). |
16 | | - map { |file| File.join ARTest::CockroachDB.root_activerecord, file.strip }. |
17 | | - sort. |
18 | | - prepend(COCKROACHDB_TEST_HELPER) |
19 | | -end |
| 6 | + module_function |
20 | 7 |
|
21 | | -def env_cockroachdb_test_files |
22 | | - return unless ENV['TEST_FILES'] && !ENV['TEST_FILES'].empty? |
| 8 | + # Look for TEST_FILES_AR or TEST_FILES env variables |
| 9 | + # to set specific tests, otherwise load every tests |
| 10 | + # from active_record and this adapter. |
| 11 | + def test_files |
| 12 | + ar_test_files = ENV.fetch('TEST_FILES_AR', '') |
| 13 | + cr_test_files = ENV.fetch('TEST_FILES', '') |
23 | 14 |
|
24 | | - @env_test_files ||= ENV['TEST_FILES'].split(',').map(&:strip) |
25 | | -end |
| 15 | + return all_test_file if ar_test_files.empty? && cr_test_files.empty? |
26 | 16 |
|
27 | | -def only_activerecord_test_files |
28 | | - return unless ENV['ONLY_TEST_AR'] |
29 | | - activerecord_test_files |
30 | | -end |
| 17 | + ar_test_files = ar_test_files. |
| 18 | + split(','). |
| 19 | + map { |file| File.join ARTest::CockroachDB.root_activerecord, file.strip }. |
| 20 | + then { _1.prepend(COCKROACHDB_TEST_HELPER) unless _1.empty? }. |
| 21 | + prepend(COCKROACHDB_TEST_HELPER) |
31 | 22 |
|
32 | | -def only_cockroachdb_test_files |
33 | | - return unless ENV['ONLY_TEST_COCKROACHDB'] |
34 | | - cockroachdb_test_files |
35 | | -end |
| 23 | + cr_test_files = cr_test_files.split(',').map(&:strip) |
36 | 24 |
|
37 | | -def all_test_files |
38 | | - activerecord_test_files + cockroachdb_test_files |
39 | | -end |
| 25 | + ar_test_files + cr_test_files |
| 26 | + end |
40 | 27 |
|
41 | | -def activerecord_test_files |
42 | | - Dir. |
43 | | - glob("#{ARTest::CockroachDB.root_activerecord}/test/cases/**/*_test.rb"). |
44 | | - reject{ |x| x =~ /\/adapters\/mysql2\// }. |
45 | | - reject{ |x| x =~ /\/adapters\/sqlite3\// }. |
46 | | - sort. |
47 | | - prepend(COCKROACHDB_TEST_HELPER) |
48 | | -end |
| 28 | + def all_test_files |
| 29 | + activerecord_test_files = Dir. |
| 30 | + glob("#{ARTest::CockroachDB.root_activerecord}/test/cases/**/*_test.rb"). |
| 31 | + reject { _1.match?(%r(/adapters/(?:mysql2|sqlite3)/) }. |
| 32 | + prepend(COCKROACHDB_TEST_HELPER) |
| 33 | + |
| 34 | + cockroachdb_test_files = Dir.glob('test/cases/**/*_test.rb') |
49 | 35 |
|
50 | | -def cockroachdb_test_files |
51 | | - Dir.glob('test/cases/**/*_test.rb') |
| 36 | + activerecord_test_files + cockroachdb_test_files |
| 37 | + end |
52 | 38 | end |
0 commit comments