Skip to content

Commit

Permalink
Change tests to use submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
chbrown committed Sep 18, 2013
1 parent 6395205 commit c99bbbc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ language: node_js
node_js:
- "0.11"
- "0.10"
before_install:
- git submodule update --init --recursive
69 changes: 28 additions & 41 deletions test/mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var child_process = require('child_process');
var tap = require('tap');

var helpers = require('../lib/helpers');
var mustache_repository = path.join(__dirname, 'mustache');


function runSpec(spec, t, callback) {
Expand Down Expand Up @@ -43,47 +42,35 @@ function runSpec(spec, t, callback) {
}, callback);
}

function run(err) {
tap.test('mustache specs', function(t) {
t.notOk(err, 'run initialization should not raise an error');
fs.readdir(path.join(mustache_repository, 'specs'), function(err, filenames) {
t.notOk(err, 'fs.readdir should not raise an error');
helpers.eachSeries(filenames, function(filename, callback) {
// skip non-json files
if (filename.match(/^[^~]+json$/)) {
var filepath = path.join(mustache_repository, 'specs', filename);
fs.readFile(filepath, {encoding: 'utf8'}, function(err, data) {
t.notOk(err, 'fs.readFile("' + filepath + '") should not raise an error');
var spec = JSON.parse(data);
runSpec(spec, t, callback);
});
}
else {
callback();
}
}, function(err) {
t.notOk(err, 'file read loop should not raise an error');
t.end();
});
tap.test('mustache specs', function(t) {
// ./mustache-spec is a submodule cloned from https://github.com/mustache/spec.git
var specs_directory = path.join(__dirname, 'mustache-spec', 'specs');
fs.readdir(specs_directory, function(err, filenames) {
t.notOk(err, 'fs.readdir should not raise an error');
helpers.eachSeries(filenames, function(filename, callback) {
// skip non-json files
if (filename.match(/^[^~]+json$/)) {
var filepath = path.join(specs_directory, filename);
fs.readFile(filepath, {encoding: 'utf8'}, function(err, data) {
t.notOk(err, 'fs.readFile("' + filepath + '") should not raise an error');
var spec = JSON.parse(data);
runSpec(spec, t, callback);
});
}
else {
callback();
}
}, function(err) {
t.notOk(err, 'file read loop should not raise an error');
t.end();
});
});
}
});

fs.exists(mustache_repository, function(exists) {
if (exists) {
run();
}
else {
console.error('Cloning mustache spec github repository');
child_process.exec('git clone git://github.com/mustache/spec.git ' + mustache_repository, {
cwd: __dirname,
env: process.env
}, function(err, stdout, stderr) {
if (err) {
console.error('STDOUT:' + stdout);
console.error('STDERR:' + stderr);
}
run(err);
});
}
tap.test('mustache repository', function(t) {
var mustache_repository = path.join(__dirname, 'mustache-spec');
fs.exists(mustache_repository, function(exists) {
t.ok(exists, 'mustache repository should exist: ' + mustache_repository);
t.end();
});
});

0 comments on commit c99bbbc

Please sign in to comment.