Scan a directory to get the names of all the whiley test files in that directory. The list of file names can be used as input parameters to a JUnit test. @param srcDir The path of the directory to scan.
(String srcDir)
| 102 | * @param srcDir The path of the directory to scan. |
| 103 | */ |
| 104 | public static Collection<Object[]> findTestFiles(String srcDir) { |
| 105 | final String suffix = ".test"; |
| 106 | ArrayList<Object[]> testcases = new ArrayList<>(); |
| 107 | for (File f : new File(srcDir).listFiles()) { |
| 108 | // Check it's a file |
| 109 | if (!f.isFile()) { |
| 110 | continue; |
| 111 | } |
| 112 | String name = f.getName(); |
| 113 | // Check it's a whiley source file |
| 114 | if (!name.endsWith(suffix)) { |
| 115 | continue; |
| 116 | } |
| 117 | // Get rid of ".whiley" extension |
| 118 | String testName = name.substring(0, name.length() - suffix.length()); |
| 119 | testcases.add(new Object[]{testName}); |
| 120 | } |
| 121 | // Sort the result by filename |
| 122 | Collections.sort(testcases, new Comparator<Object[]>() { |
| 123 | @Override |
| 124 | public int compare(Object[] o1, Object[] o2) { |
| 125 | return ((String) o1[0]).compareTo((String) o2[0]); |
| 126 | } |
| 127 | }); |
| 128 | return testcases; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Print a complete stack trace. This differs from Throwable.printStackTrace() |