/
file_task.js
104 lines (93 loc) · 3.41 KB
/
file_task.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var assert = require('assert')
, fs = require('fs')
, exec = require('child_process').exec
, h = require('./helpers');
process.chdir('./tests');
var cleanUpAndNext = function () {
exec('rm -fr ./foo', function (err, stdout, stderr) {
if (err) { throw err }
if (stderr || stdout) {
console.log (stderr || stdout);
}
h.next();
});
};
var tests = new (function () {
this.testConcatTwoFiles = function () {
h.exec('../bin/cli.js fileTest:foo/concat.txt', function (out) {
var data;
assert.equal('fileTest:foo/src1.txt task\ndefault task\nfileTest:foo/src2.txt task\n' +
'fileTest:foo/concat.txt task', out);
// Check to see the two files got concat'd
data = fs.readFileSync(process.cwd() + '/foo/concat.txt');
assert.equal('src1src2', data.toString());
cleanUpAndNext();
});
};
this.testNoPrereqChange = function () {
h.exec('../bin/cli.js fileTest:foo/from-src1.txt', function (out) {
assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task', out);
h.exec('../bin/cli.js fileTest:foo/from-src1.txt', function (out) {
// Second time should be a no-op
assert.equal('', out);
cleanUpAndNext();
});
});
};
this.testNoPrereqChangeAlwaysMake = function () {
h.exec('../bin/cli.js fileTest:foo/from-src1.txt', function (out) {
assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task',
out);
h.exec('../bin/cli.js -B fileTest:foo/from-src1.txt', function (out) {
assert.equal('fileTest:foo/src1.txt task\nfileTest:foo/from-src1.txt task',
out);
cleanUpAndNext();
});
});
};
this.testPreexistingFile = function () {
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;
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();
/*
h.exec('../bin/cli.js fileTest:touch-prereq', function () {
h.exec('../bin/cli.js fileTest:foo/from-prereq.txt', function (out) {
// Third time should update the target file
assert.equal('fileTest:foo/from-prereq.txt task', out);
cleanUpAndNext();
});
});
*/
});
});
});
};
this.testPreexistingFileAlwaysMake = function () {
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;
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();
});
});
});
};
})();
h.run(tests, function () {
process.chdir('../');
});