This commit is contained in:
Artur Adib 2012-03-02 11:30:42 -05:00
Родитель 534c05dc25
Коммит 65c8ce2efc
3 изменённых файлов: 55 добавлений и 47 удалений

8
scripts/run-tests.js Executable file
Просмотреть файл

@ -0,0 +1,8 @@
#!/usr/bin/env node
require('../global');
cd(__dirname + '/../test');
for (file in ls('*.js')) {
echo('Running test:', file);
exec('node '+file);
}

Просмотреть файл

@ -1,8 +1,8 @@
require('../maker');
var shell = require('..');
var assert = require('assert');
silent();
shell.silent();
shell.rm('-rf', 'tmp');
shell.mkdir('tmp')
@ -11,9 +11,9 @@ shell.mkdir('tmp')
// Valids
//
assert.equal(env['PATH'], process.env['PATH']);
assert.equal(shell.env['PATH'], process.env['PATH']);
env['MAKERJS_TEST'] = 'hello world';
assert.equal(env['MAKERJS_TEST'], process.env['MAKERJS_TEST']);
shell.env['MAKERJS_TEST'] = 'hello world';
assert.equal(shell.env['MAKERJS_TEST'], process.env['MAKERJS_TEST']);
exit(123);
shell.exit(123);

Просмотреть файл

@ -1,4 +1,4 @@
require('../maker');
var shell = require('..');
var assert = require('assert'),
path = require('path'),
@ -7,7 +7,7 @@ var assert = require('assert'),
// Node shims for < v0.7
fs.existsSync = fs.existsSync || path.existsSync;
silent();
shell.silent();
shell.rm('-rf', 'tmp');
shell.mkdir('tmp')
@ -16,92 +16,92 @@ shell.mkdir('tmp')
// Invalids
//
rm();
assert.ok(error());
shell.rm();
assert.ok(shell.error());
rm('asdfasdf'); // file does not exist
assert.ok(error());
shell.rm('asdfasdf'); // file does not exist
assert.ok(shell.error());
rm('-f'); // no file
assert.ok(error());
shell.rm('-f'); // no file
assert.ok(shell.error());
rm('-@ resources/file1'); // invalid option
assert.ok(error());
shell.rm('-@', 'resources/file1'); // invalid option
assert.ok(shell.error());
assert.equal(fs.existsSync('resources/file1'), true);
//
// Valids
//
rm('-f asdfasdf'); // file does not exist, but -f specified
assert.equal(error(), null);
shell.rm('-f', 'asdfasdf'); // file does not exist, but -f specified
assert.equal(shell.error(), null);
cp('-f resources/file1 tmp/file1');
shell.cp('-f', 'resources/file1', 'tmp/file1');
assert.equal(fs.existsSync('tmp/file1'), true);
rm('tmp/file1'); // simple rm
assert.equal(error(), null);
shell.rm('tmp/file1'); // simple rm
assert.equal(shell.error(), null);
assert.equal(fs.existsSync('tmp/file1'), false);
mkdir('-p tmp/a/b/c');
shell.mkdir('-p', 'tmp/a/b/c');
assert.equal(fs.existsSync('tmp/a/b/c'), true);
rm('-rf tmp/a'); // recursive dir removal
assert.equal(error(), null);
shell.rm('-rf', 'tmp/a'); // recursive dir removal
assert.equal(shell.error(), null);
assert.equal(fs.existsSync('tmp/a'), false);
cp('-f resources/file* tmp');
assert.equal(error(), null);
shell.cp('-f', 'resources/file*', 'tmp');
assert.equal(shell.error(), null);
assert.equal(fs.existsSync('tmp/file1'), true);
assert.equal(fs.existsSync('tmp/file2'), true);
assert.equal(fs.existsSync('tmp/file1.js'), true);
assert.equal(fs.existsSync('tmp/file2.js'), true);
rm('tmp/file*');
assert.equal(error(), null);
shell.rm('tmp/file*');
assert.equal(shell.error(), null);
assert.equal(fs.existsSync('tmp/file1'), false);
assert.equal(fs.existsSync('tmp/file2'), false);
assert.equal(fs.existsSync('tmp/file1.js'), false);
assert.equal(fs.existsSync('tmp/file2.js'), false);
// recursive dir removal
mkdir('-p tmp/a/b/c');
mkdir('-p tmp/b');
mkdir('-p tmp/c');
mkdir('-p tmp/.hidden');
shell.mkdir('-p', 'tmp/a/b/c');
shell.mkdir('-p', 'tmp/b');
shell.mkdir('-p', 'tmp/c');
shell.mkdir('-p', 'tmp/.hidden');
assert.equal(fs.existsSync('tmp/a/b/c'), true);
assert.equal(fs.existsSync('tmp/b'), true);
assert.equal(fs.existsSync('tmp/c'), true);
assert.equal(fs.existsSync('tmp/.hidden'), true);
rm('-rf tmp/*');
assert.equal(error(), null);
shell.rm('-rf', 'tmp/*');
assert.equal(shell.error(), null);
var contents = fs.readdirSync('tmp');
assert.equal(contents.length, 1);
assert.equal(contents[0], '.hidden'); // shouldn't remove hiddden if no .* given
// recursive dir removal
mkdir('-p tmp/a/b/c');
mkdir('-p tmp/b');
mkdir('-p tmp/c');
mkdir('-p tmp/.hidden');
shell.mkdir('-p', 'tmp/a/b/c');
shell.mkdir('-p', 'tmp/b');
shell.mkdir('-p', 'tmp/c');
shell.mkdir('-p', 'tmp/.hidden');
assert.equal(fs.existsSync('tmp/a/b/c'), true);
assert.equal(fs.existsSync('tmp/b'), true);
assert.equal(fs.existsSync('tmp/c'), true);
assert.equal(fs.existsSync('tmp/.hidden'), true);
rm('-rf tmp/* tmp/.*');
assert.equal(error(), null);
shell.rm('-rf', 'tmp/*', 'tmp/.*');
assert.equal(shell.error(), null);
var contents = fs.readdirSync('tmp');
assert.equal(contents.length, 0);
// recursive dir removal - comma-syntax
mkdir('-p tmp/a/b/c');
mkdir('-p tmp/b');
mkdir('-p tmp/c');
mkdir('-p tmp/.hidden');
shell.mkdir('-p', 'tmp/a/b/c');
shell.mkdir('-p', 'tmp/b');
shell.mkdir('-p', 'tmp/c');
shell.mkdir('-p', 'tmp/.hidden');
assert.equal(fs.existsSync('tmp/a/b/c'), true);
assert.equal(fs.existsSync('tmp/b'), true);
assert.equal(fs.existsSync('tmp/c'), true);
assert.equal(fs.existsSync('tmp/.hidden'), true);
rm('-rf', 'tmp/*', 'tmp/.*');
assert.equal(error(), null);
shell.rm('-rf', 'tmp/*', 'tmp/.*');
assert.equal(shell.error(), null);
var contents = fs.readdirSync('tmp');
assert.equal(contents.length, 0);
exit(123);
shell.exit(123);