Permalink
Browse files

Replaced 'nix-specific shell commands with file utils

  • Loading branch information...
1 parent 37b86e0 commit 472985a8417bfeb601811a0da0e123e0df3ed388 @mde mde committed Sep 18, 2013
Showing with 56 additions and 45 deletions.
  1. +4 −7 test/Jakefile.rule
  2. +26 −30 test/file_task.js
  3. +26 −8 test/rule.js
View
@@ -1,6 +1,7 @@
var exec = require('child_process').exec
, fs = require('fs')
, util = require('util')
+ , utils = require('utilities');
task('default', ['tmp']);
@@ -241,11 +242,7 @@ namespace('sourceFunction', function () {
});
////////////////////////////////////////////////////////////
-task('clean', function() {
- exec('rm -fr ./foo ./tmp*', function (err, stdout, stderr) {
- if (err) { throw err }
- if (stderr || stdout) {
- console.log (stderr || stdout);
- }
- });
+task('clean', function () {
+ utils.file.rmRf('./foo');
+ utils.file.rmRf('./tmp');
});
View
@@ -2,16 +2,14 @@ var assert = require('assert')
, fs = require('fs')
, path = require('path')
, exec = require('child_process').exec
- , h = require('./helpers');
+ , h = require('./helpers')
+ , utils = require('utilities');
var cleanUpAndNext = function (callback) {
- exec('rm -fr ./foo', function (err, stdout, stderr) {
- if (err) { throw err; }
- if (stderr || stdout) {
- console.log (stderr || stdout);
- }
- callback();
+ utils.file.rmRf('./foo', {
+ silent: true
});
+ callback();
};
var tests = {
@@ -50,7 +48,7 @@ var tests = {
, 'file-task where prereq file is modified': function (next) {
setTimeout(function () {
- exec('touch ./foo/src1.txt', function (err, data) {
+ fs.writeFile('./foo/src1.txt', '', function (err, data) {
if (err) {
throw err;
}
@@ -59,7 +57,7 @@ var tests = {
cleanUpAndNext(next);
});
});
- }, 1000); // Wait to do the touch to ensure mod-time is different
+ }, 1000); // Wait to do the mod to ensure mod-time is different
}
, 'test where a file-task prereq does not change with --always-make': function (next) {
@@ -76,35 +74,33 @@ var tests = {
, 'test a preexisting file': function (next) {
var prereqData = 'howdy';
- h.exec('mkdir -p foo', function (out) {
- fs.writeFileSync('foo/prereq.txt', prereqData);
+ utils.file.mkdirP('foo');
+ fs.writeFileSync('foo/prereq.txt', prereqData);
+ h.exec('../bin/cli.js fileTest:foo/from-prereq.txt', function (out) {
+ var data;
+ assert.equal('fileTest:foo/from-prereq.txt task', out);
+ data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt');
+ assert.equal(prereqData, data.toString());
h.exec('../bin/cli.js fileTest:foo/from-prereq.txt', function (out) {
- var data;
- assert.equal('fileTest:foo/from-prereq.txt task', out);
- data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt');
- assert.equal(prereqData, data.toString());
- h.exec('../bin/cli.js fileTest:foo/from-prereq.txt', function (out) {
- // Second time should be a no-op
- assert.equal('', out);
- cleanUpAndNext(next);
- });
+ // Second time should be a no-op
+ assert.equal('', out);
+ cleanUpAndNext(next);
});
});
}
, 'test a preexisting file with --always-make flag': function (next) {
var prereqData = 'howdy';
- h.exec('mkdir -p foo', function (out) {
- fs.writeFileSync('foo/prereq.txt', prereqData);
- h.exec('../bin/cli.js fileTest:foo/from-prereq.txt', function (out) {
- var data;
+ utils.file.mkdirP('foo');
+ fs.writeFileSync('foo/prereq.txt', prereqData);
+ h.exec('../bin/cli.js fileTest:foo/from-prereq.txt', function (out) {
+ var data;
+ assert.equal('fileTest:foo/from-prereq.txt task', out);
+ data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt');
+ assert.equal(prereqData, data.toString());
+ h.exec('../bin/cli.js -B fileTest:foo/from-prereq.txt', function (out) {
assert.equal('fileTest:foo/from-prereq.txt task', out);
- data = fs.readFileSync(process.cwd() + '/foo/from-prereq.txt');
- assert.equal(prereqData, data.toString());
- h.exec('../bin/cli.js -B fileTest:foo/from-prereq.txt', function (out) {
- assert.equal('fileTest:foo/from-prereq.txt task', out);
- cleanUpAndNext(next);
- });
+ cleanUpAndNext(next);
});
});
}
View
@@ -4,16 +4,33 @@ var assert = require('assert')
, exec = require('child_process').exec
, h = require('./helpers')
, Matcher = require('../lib/rule').Matcher
- , utils = require('../lib/utils');
+ , utils = require('utilities');
var cleanUpAndNext = function (callback) {
- exec('rm -fr ./foo ./tmp*', function (err, stdout, stderr) {
- if (err) { throw err; }
- if (stderr || stdout) {
- console.log (stderr || stdout);
- }
- callback();
+ // Gotta add globbing to file utils rmRf
+ var tmpFiles = [
+ 'tmp'
+ , 'tmp_ns'
+ , 'tmp_cr'
+ , 'tmp_p'
+ , 'tmp_pf'
+ , 'tmpbin'
+ , 'tmpsrc'
+ , 'tmp_dep1.c'
+ , 'tmp_dep1.o'
+ , 'tmp_dep1.oo'
+ , 'tmp_dep2.c'
+ , 'tmp_dep2.o'
+ , 'tmp_dep2.oo'
+ , 'foo'
+ , 'foo.html'
+ ];
+ tmpFiles.forEach(function (f) {
+ utils.file.rmRf(f, {
+ silent: true
+ });
});
+ callback();
};
var tests = {
@@ -166,7 +183,7 @@ var tests = {
tests['test rule with source file modified (' + key + ')'] = function (next) {
setTimeout(function () {
- exec('touch foo.txt', function (err, data) {
+ fs.writeFile('foo.txt', '', function (err, data) {
if (err) {
throw err;
}
@@ -187,6 +204,7 @@ var tests = {
tests['test rule with existing objective file and no source ' +
' (should be normal file-task) (' + key + ')'] = function (next) {
// Remove just the source file
+ fs.writeFileSync('foo.html', '');
utils.file.rmRf('foo.txt', {silent: true});
h.exec('../bin/cli.js -f Jakefile.rule ' + key + ':test', function (out) {
// Should treat existing objective file as plain file-task,

0 comments on commit 472985a

Please sign in to comment.