Scan a directory to get the names of all the whiley source files in that directory. The list of file names can be used as input parameters to a JUnit test. If the system property test.name.contains is set, then the list of files returned will be filtered. Only file names that contain t
(String srcDir)
| 68 | * @param srcDir The path of the directory to scan. |
| 69 | */ |
| 70 | public static Collection<Object[]> findTestNames(String srcDir) { |
| 71 | final String suffix = ".whiley"; |
| 72 | ArrayList<Object[]> testcases = new ArrayList<>(); |
| 73 | for (File f : new File(srcDir).listFiles()) { |
| 74 | // Check it's a file |
| 75 | if (!f.isFile()) { |
| 76 | continue; |
| 77 | } |
| 78 | String name = f.getName(); |
| 79 | // Check it's a whiley source file |
| 80 | if (!name.endsWith(suffix)) { |
| 81 | continue; |
| 82 | } |
| 83 | // Get rid of ".whiley" extension |
| 84 | String testName = name.substring(0, name.length() - suffix.length()); |
| 85 | testcases.add(new Object[]{testName}); |
| 86 | } |
| 87 | // Sort the result by filename |
| 88 | Collections.sort(testcases, new Comparator<Object[]>() { |
| 89 | @Override |
| 90 | public int compare(Object[] o1, Object[] o2) { |
| 91 | return ((String) o1[0]).compareTo((String) o2[0]); |
| 92 | } |
| 93 | }); |
| 94 | return testcases; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Scan a directory to get the names of all the whiley test files |