Tests.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. var Fs = require("fs");
  16. var nThen = require("nthen");
  17. var Tests = module.exports;
  18. var Fs_stat = function (file, callback) {
  19. Fs.stat(file, function (err, ret) {
  20. if (err === 'ENOENT') {
  21. console.log("Magical ENOENT on a file which definitely does exist, good job Linus");
  22. setTimeout(function () {
  23. Fs_stat(file, callback);
  24. }, 1000);
  25. } else {
  26. callback(err, ret);
  27. }
  28. });
  29. };
  30. var getTests = function (file, tests, callback) {
  31. if (/\/(.git|build_.*|node_build|contrib)\//.test(file)) { callback(); return; }
  32. Fs_stat(file, function (err, stat) {
  33. if (err) { throw err; }
  34. if (stat.isDirectory()) {
  35. nThen(function (waitFor) {
  36. Fs.readdir(file, waitFor(function (err, list) {
  37. if (err) { throw err; }
  38. list.forEach(function (subFile) {
  39. getTests(file + '/' + subFile, tests, waitFor());
  40. });
  41. }));
  42. }).nThen(function (waitFor) {
  43. callback();
  44. });
  45. return;
  46. } else if (/_test\.c$/.test(file) && tests.indexOf(file) === -1) {
  47. tests.push(file);
  48. }
  49. callback();
  50. });
  51. };
  52. var get = Tests.get = function (callback) {
  53. var tests = [];
  54. getTests('.', tests, function () {
  55. callback(tests);
  56. });
  57. };