Test generation
This commit is contained in:
parent
ad44ed15c7
commit
97daf2f3a1
|
@ -637,9 +637,9 @@ Get the distance between two points.
|
|||
|
||||
#### Distance Types
|
||||
|
||||
- `miles`
|
||||
- `radians`
|
||||
- `kilometers`
|
||||
- `miles`
|
||||
- `radians`
|
||||
- `kilometers`
|
||||
|
||||
#### geoPoint.lat
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
- app.model(Model)
|
||||
- app.models()
|
||||
-
|
||||
- Model.validatesPresenceOf(properties...)
|
||||
- Model.validatesLengthOf(property, options)
|
||||
- Model.validatesInclusionOf(property, options)
|
||||
- Model.validatesExclusionOf(property, options)
|
||||
- Model.validatesNumericalityOf(property, options)
|
||||
- Model.validatesUniquenessOf(property, options)
|
||||
- myModel.isValid()
|
||||
- Model.attachTo(dataSource)
|
||||
|
||||
##### Model.create([data], [callback])
|
||||
##### model.save([options], [callback])
|
||||
##### model.updateAttributes(data, [callback])
|
||||
##### model.upsert(data, callback)
|
||||
##### model.destroy([callback])
|
||||
##### Model.destroyAll(callback)
|
||||
##### Model.find(id, callback)
|
||||
##### Model.count([query], callback)
|
||||
#### Static Methods
|
||||
#### Instance Methods
|
||||
#### Remote Methods
|
||||
##### asteroid.remoteMethod(Model, fn, [options]);
|
||||
#### Hooks
|
||||
#### Remote Hooks
|
||||
#### Context
|
||||
##### ctx.me
|
||||
##### Rest
|
||||
###### ctx.req
|
||||
###### ctx.res
|
||||
#### Relationships
|
||||
##### Model.hasMany(Model)
|
||||
##### Model.hasAndBelongsToMany()
|
||||
#### Model.availableHooks()
|
||||
#### Shared Methods
|
||||
#### Model.availableMethods()
|
||||
### Data Source
|
||||
#### dataSource.createModel(name, options, settings)
|
||||
#### dataSource.discover(options, fn)
|
||||
#### dataSource.discoverSync(options)
|
||||
#### dataSource.discoverModels(options, fn)
|
||||
#### dataSource.discoverModelsSync(options)
|
||||
#### dataSource.enable(operation)
|
||||
#### dataSource.disable(operation)
|
||||
#### dataSource.operations()
|
||||
#### Connectors
|
||||
### GeoPoint
|
||||
#### geoPoint.distanceTo(geoPoint, options)
|
||||
#### GeoPoint.distanceBetween(a, b, options)
|
||||
#### Distance Types
|
||||
#### geoPoint.lat
|
||||
#### geoPoint.long
|
||||
### Asteroid Types
|
||||
### REST Router
|
||||
### SocketIO Middleware **Not Available**
|
|
@ -0,0 +1,110 @@
|
|||
/**
|
||||
* Generate asteroid unit tests from documentation...
|
||||
*/
|
||||
|
||||
fs = require('fs')
|
||||
|
||||
readme = fs.readFileSync('./README.md').toString();
|
||||
|
||||
var alias = {
|
||||
myModel: 'Model',
|
||||
model: 'Model',
|
||||
ctx: 'Model',
|
||||
dataSource: 'DataSource',
|
||||
geoPoint: 'GeoPoint'
|
||||
};
|
||||
|
||||
function getName(line) {
|
||||
var name = line
|
||||
.split('.')[0]
|
||||
.replace(/#+\s/, '');
|
||||
|
||||
return alias[name] || name;
|
||||
}
|
||||
|
||||
function Doc(line, lineNum, docIndex) {
|
||||
this.name = getName(line);
|
||||
this.line = line;
|
||||
this.lineNum = lineNum;
|
||||
this.docIndex = docIndex;
|
||||
}
|
||||
|
||||
Doc.prototype.nextDoc = function () {
|
||||
return docs[this.docIndex + 1];
|
||||
}
|
||||
|
||||
Doc.prototype.contents = function () {
|
||||
var nextDoc = this.nextDoc();
|
||||
var endIndex = lines.length - 1;
|
||||
var contents = [];
|
||||
|
||||
if(nextDoc) {
|
||||
endIndex = nextDoc.lineNum;
|
||||
}
|
||||
|
||||
for(var i = this.lineNum; i < endIndex; i++) {
|
||||
contents.push(lines[i]);
|
||||
}
|
||||
|
||||
return contents;
|
||||
}
|
||||
|
||||
Doc.prototype.example = function () {
|
||||
var content = this.contents();
|
||||
var result = [];
|
||||
|
||||
content.forEach(function (line) {
|
||||
if(line.substr(0, 4) === ' ') {
|
||||
result.push(line.substr(4, line.length))
|
||||
}
|
||||
});
|
||||
|
||||
return result.join('\n');
|
||||
}
|
||||
|
||||
lines = readme.split('\n')
|
||||
docs = [];
|
||||
|
||||
lines.forEach(function (line, i) {
|
||||
if(!(line[0] === '#' && ~line.indexOf('.'))) return;
|
||||
|
||||
var doc = new Doc(line, i, docs.length);
|
||||
|
||||
docs.push(doc);
|
||||
});
|
||||
|
||||
var _ = require('underscore');
|
||||
var sh = require('shelljs');
|
||||
|
||||
var byName = _.groupBy(docs, function (doc) {
|
||||
return doc.name;
|
||||
});
|
||||
|
||||
sh.rm('-rf', 'g-tests');
|
||||
sh.mkdir('g-tests');
|
||||
|
||||
Object.keys(byName).forEach(function (group) {
|
||||
var testFile =
|
||||
"var asteroid = require('../');" +
|
||||
"\n" +
|
||||
"describe('app', function(){"
|
||||
testFile
|
||||
|
||||
describe('app', function(){
|
||||
var app;
|
||||
|
||||
beforeEach(function () {
|
||||
app = asteroid();
|
||||
});
|
||||
|
||||
describe('asteroid.createModel(name, properties, settings)', function(){
|
||||
var User = asteroid.createModel('user', {
|
||||
first: String,
|
||||
last: String,
|
||||
age: Number
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
})
|
|
@ -0,0 +1 @@
|
|||
../shelljs/bin/shjs
|
|
@ -7,7 +7,7 @@ module.exports = ModelConfiguration;
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
|
||||
var AsteroidModule = require('asteroid-module')
|
||||
, Model = require('./model')
|
||||
, debug = require('debug')('model-configuration')
|
||||
|
@ -76,4 +76,4 @@ ModelConfiguration.options = {
|
|||
'name': {type: 'string'},
|
||||
'properties': {type: 'array'},
|
||||
'maps': {type: 'array'}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"name": "ShellJS",
|
||||
"twitter": [
|
||||
"r2r"
|
||||
]
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
node_modules/
|
|
@ -0,0 +1,5 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- 0.6
|
||||
- 0.8
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
Copyright (c) 2012, Artur Adib <aadib@mozilla.com>
|
||||
All rights reserved.
|
||||
|
||||
You may use this project under the terms of the New BSD license as follows:
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of Artur Adib nor the
|
||||
names of the contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -0,0 +1,513 @@
|
|||
# ShellJS - Unix shell commands for Node.js [![Build Status](https://secure.travis-ci.org/arturadib/shelljs.png)](http://travis-ci.org/arturadib/shelljs)
|
||||
|
||||
ShellJS is a portable **(Windows/Linux/OS X)** implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate your shell script's dependency on Unix while still keeping its familiar and powerful commands. You can also install it globally so you can run it from outside Node projects - say goodbye to those gnarly Bash scripts!
|
||||
|
||||
The project is [unit-tested](http://travis-ci.org/arturadib/shelljs) and battled-tested in projects like:
|
||||
|
||||
+ [PDF.js](http://github.com/mozilla/pdf.js) - Firefox's next-gen PDF reader
|
||||
+ [Firebug](http://getfirebug.com/) - Firefox's infamous debugger
|
||||
+ [JSHint](http://jshint.com) - Most popular JavaScript linter
|
||||
+ [Zepto](http://zeptojs.com) - jQuery-compatible JavaScript library for modern browsers
|
||||
+ [Yeoman](http://yeoman.io/) - Web application stack and development tool
|
||||
+ [Deployd.com](http://deployd.com) - Open source PaaS for quick API backend generation
|
||||
|
||||
and [many more](https://npmjs.org/browse/depended/shelljs).
|
||||
|
||||
## Installing
|
||||
|
||||
Via npm:
|
||||
|
||||
```bash
|
||||
$ npm install [-g] shelljs
|
||||
```
|
||||
|
||||
If the global option `-g` is specified, the binary `shjs` will be installed. This makes it possible to
|
||||
run ShellJS scripts much like any shell script from the command line, i.e. without requiring a `node_modules` folder:
|
||||
|
||||
```bash
|
||||
$ shjs my_script
|
||||
```
|
||||
|
||||
You can also just copy `shell.js` into your project's directory, and `require()` accordingly.
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
### JavaScript
|
||||
|
||||
```javascript
|
||||
require('shelljs/global');
|
||||
|
||||
if (!which('git')) {
|
||||
echo('Sorry, this script requires git');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// Copy files to release dir
|
||||
mkdir('-p', 'out/Release');
|
||||
cp('-R', 'stuff/*', 'out/Release');
|
||||
|
||||
// Replace macros in each .js file
|
||||
cd('lib');
|
||||
ls('*.js').forEach(function(file) {
|
||||
sed('-i', 'BUILD_VERSION', 'v0.1.2', file);
|
||||
sed('-i', /.*REMOVE_THIS_LINE.*\n/, '', file);
|
||||
sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, cat('macro.js'), file);
|
||||
});
|
||||
cd('..');
|
||||
|
||||
// Run external tool synchronously
|
||||
if (exec('git commit -am "Auto-commit"').code !== 0) {
|
||||
echo('Error: Git commit failed');
|
||||
exit(1);
|
||||
}
|
||||
```
|
||||
|
||||
### CoffeeScript
|
||||
|
||||
```coffeescript
|
||||
require 'shelljs/global'
|
||||
|
||||
if not which 'git'
|
||||
echo 'Sorry, this script requires git'
|
||||
exit 1
|
||||
|
||||
# Copy files to release dir
|
||||
mkdir '-p', 'out/Release'
|
||||
cp '-R', 'stuff/*', 'out/Release'
|
||||
|
||||
# Replace macros in each .js file
|
||||
cd 'lib'
|
||||
for file in ls '*.js'
|
||||
sed '-i', 'BUILD_VERSION', 'v0.1.2', file
|
||||
sed '-i', /.*REMOVE_THIS_LINE.*\n/, '', file
|
||||
sed '-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, cat 'macro.js', file
|
||||
cd '..'
|
||||
|
||||
# Run external tool synchronously
|
||||
if (exec 'git commit -am "Auto-commit"').code != 0
|
||||
echo 'Error: Git commit failed'
|
||||
exit 1
|
||||
```
|
||||
|
||||
## Global vs. Local
|
||||
|
||||
The example above uses the convenience script `shelljs/global` to reduce verbosity. If polluting your global namespace is not desirable, simply require `shelljs`.
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var shell = require('shelljs');
|
||||
shell.echo('hello world');
|
||||
```
|
||||
|
||||
## Make tool
|
||||
|
||||
A convenience script `shelljs/make` is also provided to mimic the behavior of a Unix Makefile. In this case all shell objects are global, and command line arguments will cause the script to execute only the corresponding function in the global `target` object. To avoid redundant calls, target functions are executed only once per script.
|
||||
|
||||
Example (CoffeeScript):
|
||||
|
||||
```coffeescript
|
||||
require 'shelljs/make'
|
||||
|
||||
target.all = ->
|
||||
target.bundle()
|
||||
target.docs()
|
||||
|
||||
target.bundle = ->
|
||||
cd __dirname
|
||||
mkdir 'build'
|
||||
cd 'lib'
|
||||
(cat '*.js').to '../build/output.js'
|
||||
|
||||
target.docs = ->
|
||||
cd __dirname
|
||||
mkdir 'docs'
|
||||
cd 'lib'
|
||||
for file in ls '*.js'
|
||||
text = grep '//@', file # extract special comments
|
||||
text.replace '//@', '' # remove comment tags
|
||||
text.to 'docs/my_docs.md'
|
||||
```
|
||||
|
||||
To run the target `all`, call the above script without arguments: `$ node make`. To run the target `docs`: `$ node make docs`, and so on.
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
|
||||
DO NOT MODIFY BEYOND THIS POINT - IT'S AUTOMATICALLY GENERATED
|
||||
|
||||
-->
|
||||
|
||||
|
||||
## Command reference
|
||||
|
||||
|
||||
All commands run synchronously, unless otherwise stated.
|
||||
|
||||
|
||||
### cd('dir')
|
||||
Changes to directory `dir` for the duration of the script
|
||||
|
||||
### pwd()
|
||||
Returns the current directory.
|
||||
|
||||
### ls([options ,] path [,path ...])
|
||||
### ls([options ,] path_array)
|
||||
Available options:
|
||||
|
||||
+ `-R`: recursive
|
||||
+ `-A`: all files (include files beginning with `.`, except for `.` and `..`)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
ls('projs/*.js');
|
||||
ls('-R', '/users/me', '/tmp');
|
||||
ls('-R', ['/users/me', '/tmp']); // same as above
|
||||
```
|
||||
|
||||
Returns array of files in the given path, or in current directory if no path provided.
|
||||
|
||||
### find(path [,path ...])
|
||||
### find(path_array)
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
find('src', 'lib');
|
||||
find(['src', 'lib']); // same as above
|
||||
find('.').filter(function(file) { return file.match(/\.js$/); });
|
||||
```
|
||||
|
||||
Returns array of all files (however deep) in the given paths.
|
||||
|
||||
The main difference from `ls('-R', path)` is that the resulting file names
|
||||
include the base directories, e.g. `lib/resources/file1` instead of just `file1`.
|
||||
|
||||
### cp([options ,] source [,source ...], dest)
|
||||
### cp([options ,] source_array, dest)
|
||||
Available options:
|
||||
|
||||
+ `-f`: force
|
||||
+ `-r, -R`: recursive
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
cp('file1', 'dir1');
|
||||
cp('-Rf', '/tmp/*', '/usr/local/*', '/home/tmp');
|
||||
cp('-Rf', ['/tmp/*', '/usr/local/*'], '/home/tmp'); // same as above
|
||||
```
|
||||
|
||||
Copies files. The wildcard `*` is accepted.
|
||||
|
||||
### rm([options ,] file [, file ...])
|
||||
### rm([options ,] file_array)
|
||||
Available options:
|
||||
|
||||
+ `-f`: force
|
||||
+ `-r, -R`: recursive
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
rm('-rf', '/tmp/*');
|
||||
rm('some_file.txt', 'another_file.txt');
|
||||
rm(['some_file.txt', 'another_file.txt']); // same as above
|
||||
```
|
||||
|
||||
Removes files. The wildcard `*` is accepted.
|
||||
|
||||
### mv(source [, source ...], dest')
|
||||
### mv(source_array, dest')
|
||||
Available options:
|
||||
|
||||
+ `f`: force
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
mv('-f', 'file', 'dir/');
|
||||
mv('file1', 'file2', 'dir/');
|
||||
mv(['file1', 'file2'], 'dir/'); // same as above
|
||||
```
|
||||
|
||||
Moves files. The wildcard `*` is accepted.
|
||||
|
||||
### mkdir([options ,] dir [, dir ...])
|
||||
### mkdir([options ,] dir_array)
|
||||
Available options:
|
||||
|
||||
+ `p`: full path (will create intermediate dirs if necessary)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
mkdir('-p', '/tmp/a/b/c/d', '/tmp/e/f/g');
|
||||
mkdir('-p', ['/tmp/a/b/c/d', '/tmp/e/f/g']); // same as above
|
||||
```
|
||||
|
||||
Creates directories.
|
||||
|
||||
### test(expression)
|
||||
Available expression primaries:
|
||||
|
||||
+ `'-b', 'path'`: true if path is a block device
|
||||
+ `'-c', 'path'`: true if path is a character device
|
||||
+ `'-d', 'path'`: true if path is a directory
|
||||
+ `'-e', 'path'`: true if path exists
|
||||
+ `'-f', 'path'`: true if path is a regular file
|
||||
+ `'-L', 'path'`: true if path is a symboilc link
|
||||
+ `'-p', 'path'`: true if path is a pipe (FIFO)
|
||||
+ `'-S', 'path'`: true if path is a socket
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
if (test('-d', path)) { /* do something with dir */ };
|
||||
if (!test('-f', path)) continue; // skip if it's a regular file
|
||||
```
|
||||
|
||||
Evaluates expression using the available primaries and returns corresponding value.
|
||||
|
||||
### cat(file [, file ...])
|
||||
### cat(file_array)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var str = cat('file*.txt');
|
||||
var str = cat('file1', 'file2');
|
||||
var str = cat(['file1', 'file2']); // same as above
|
||||
```
|
||||
|
||||
Returns a string containing the given file, or a concatenated string
|
||||
containing the files if more than one file is given (a new line character is
|
||||
introduced between each file). Wildcard `*` accepted.
|
||||
|
||||
### 'string'.to(file)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
cat('input.txt').to('output.txt');
|
||||
```
|
||||
|
||||
Analogous to the redirection operator `>` in Unix, but works with JavaScript strings (such as
|
||||
those returned by `cat`, `grep`, etc). _Like Unix redirections, `to()` will overwrite any existing file!_
|
||||
|
||||
### sed([options ,] search_regex, replace_str, file)
|
||||
Available options:
|
||||
|
||||
+ `-i`: Replace contents of 'file' in-place. _Note that no backups will be created!_
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
sed('-i', 'PROGRAM_VERSION', 'v0.1.3', 'source.js');
|
||||
sed(/.*DELETE_THIS_LINE.*\n/, '', 'source.js');
|
||||
```
|
||||
|
||||
Reads an input string from `file` and performs a JavaScript `replace()` on the input
|
||||
using the given search regex and replacement string. Returns the new string after replacement.
|
||||
|
||||
### grep([options ,] regex_filter, file [, file ...])
|
||||
### grep([options ,] regex_filter, file_array)
|
||||
Available options:
|
||||
|
||||
+ `-v`: Inverse the sense of the regex and print the lines not matching the criteria.
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
grep('-v', 'GLOBAL_VARIABLE', '*.js');
|
||||
grep('GLOBAL_VARIABLE', '*.js');
|
||||
```
|
||||
|
||||
Reads input string from given files and returns a string containing all lines of the
|
||||
file that match the given `regex_filter`. Wildcard `*` accepted.
|
||||
|
||||
### which(command)
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var nodeExec = which('node');
|
||||
```
|
||||
|
||||
Searches for `command` in the system's PATH. On Windows looks for `.exe`, `.cmd`, and `.bat` extensions.
|
||||
Returns string containing the absolute path to the command.
|
||||
|
||||
### echo(string [,string ...])
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
echo('hello world');
|
||||
var str = echo('hello world');
|
||||
```
|
||||
|
||||
Prints string to stdout, and returns string with additional utility methods
|
||||
like `.to()`.
|
||||
|
||||
### dirs([options | '+N' | '-N'])
|
||||
|
||||
Available options:
|
||||
|
||||
+ `-c`: Clears the directory stack by deleting all of the elements.
|
||||
|
||||
Arguments:
|
||||
|
||||
+ `+N`: Displays the Nth directory (counting from the left of the list printed by dirs when invoked without options), starting with zero.
|
||||
+ `-N`: Displays the Nth directory (counting from the right of the list printed by dirs when invoked without options), starting with zero.
|
||||
|
||||
Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified.
|
||||
|
||||
See also: pushd, popd
|
||||
|
||||
### pushd([options,] [dir | '-N' | '+N'])
|
||||
|
||||
Available options:
|
||||
|
||||
+ `-n`: Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated.
|
||||
|
||||
Arguments:
|
||||
|
||||
+ `dir`: Makes the current working directory be the top of the stack, and then executes the equivalent of `cd dir`.
|
||||
+ `+N`: Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
|
||||
+ `-N`: Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
// process.cwd() === '/usr'
|
||||
pushd('/etc'); // Returns /etc /usr
|
||||
pushd('+1'); // Returns /usr /etc
|
||||
```
|
||||
|
||||
Save the current directory on the top of the directory stack and then cd to `dir`. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.
|
||||
|
||||
### popd([options,] ['-N' | '+N'])
|
||||
|
||||
Available options:
|
||||
|
||||
+ `-n`: Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated.
|
||||
|
||||
Arguments:
|
||||
|
||||
+ `+N`: Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero.
|
||||
+ `-N`: Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero.
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
echo(process.cwd()); // '/usr'
|
||||
pushd('/etc'); // '/etc /usr'
|
||||
echo(process.cwd()); // '/etc'
|
||||
popd(); // '/usr'
|
||||
echo(process.cwd()); // '/usr'
|
||||
```
|
||||
|
||||
When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.
|
||||
|
||||
### exit(code)
|
||||
Exits the current process with the given exit code.
|
||||
|
||||
### env['VAR_NAME']
|
||||
Object containing environment variables (both getter and setter). Shortcut to process.env.
|
||||
|
||||
### exec(command [, options] [, callback])
|
||||
Available options (all `false` by default):
|
||||
|
||||
+ `async`: Asynchronous execution. Defaults to true if a callback is provided.
|
||||
+ `silent`: Do not echo program output to console.
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
var version = exec('node --version', {silent:true}).output;
|
||||
|
||||
var child = exec('some_long_running_process', {async:true});
|
||||
child.stdout.on('data', function(data) {
|
||||
/* ... do something with data ... */
|
||||
});
|
||||
|
||||
exec('some_long_running_process', function(code, output) {
|
||||
console.log('Exit code:', code);
|
||||
console.log('Program output:', output);
|
||||
});
|
||||
```
|
||||
|
||||
Executes the given `command` _synchronously_, unless otherwise specified.
|
||||
When in synchronous mode returns the object `{ code:..., output:... }`, containing the program's
|
||||
`output` (stdout + stderr) and its exit `code`. Otherwise returns the child process object, and
|
||||
the `callback` gets the arguments `(code, output)`.
|
||||
|
||||
**Note:** For long-lived processes, it's best to run `exec()` asynchronously as
|
||||
the current synchronous implementation uses a lot of CPU. This should be getting
|
||||
fixed soon.
|
||||
|
||||
### chmod(octal_mode || octal_string, file)
|
||||
### chmod(symbolic_mode, file)
|
||||
|
||||
Available options:
|
||||
|
||||
+ `-v`: output a diagnostic for every file processed
|
||||
+ `-c`: like verbose but report only when a change is made
|
||||
+ `-R`: change files and directories recursively
|
||||
|
||||
Examples:
|
||||
|
||||
```javascript
|
||||
chmod(755, '/Users/brandon');
|
||||
chmod('755', '/Users/brandon'); // same as above
|
||||
chmod('u+x', '/Users/brandon');
|
||||
```
|
||||
|
||||
Alters the permissions of a file or directory by either specifying the
|
||||
absolute permissions in octal form or expressing the changes in symbols.
|
||||
This command tries to mimic the POSIX behavior as much as possible.
|
||||
Notable exceptions:
|
||||
|
||||
+ In symbolic modes, 'a-r' and '-r' are identical. No consideration is
|
||||
given to the umask.
|
||||
+ There is no "quiet" option since default behavior is to run silent.
|
||||
|
||||
## Configuration
|
||||
|
||||
|
||||
### config.silent
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
var silentState = config.silent; // save old silent state
|
||||
config.silent = true;
|
||||
/* ... */
|
||||
config.silent = silentState; // restore old silent state
|
||||
```
|
||||
|
||||
Suppresses all command output if `true`, except for `echo()` calls.
|
||||
Default is `false`.
|
||||
|
||||
### config.fatal
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
config.fatal = true;
|
||||
cp('this_file_does_not_exist', '/dev/null'); // dies here
|
||||
/* more commands... */
|
||||
```
|
||||
|
||||
If `true` the script will die on errors. Default is `false`.
|
||||
|
||||
## Non-Unix commands
|
||||
|
||||
|
||||
### tempdir()
|
||||
Searches and returns string containing a writeable, platform-dependent temporary directory.
|
||||
Follows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir).
|
||||
|
||||
### error()
|
||||
Tests if error occurred in the last command. Returns `null` if no error occurred,
|
||||
otherwise returns string explaining the error
|
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env node
|
||||
require('../global');
|
||||
|
||||
if (process.argv.length < 3) {
|
||||
console.log('ShellJS: missing argument (script name)');
|
||||
console.log();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
var args,
|
||||
scriptName = process.argv[2];
|
||||
env['NODE_PATH'] = __dirname + '/../..';
|
||||
|
||||
if (!scriptName.match(/\.js/) && !scriptName.match(/\.coffee/)) {
|
||||
if (test('-f', scriptName + '.js'))
|
||||
scriptName += '.js';
|
||||
if (test('-f', scriptName + '.coffee'))
|
||||
scriptName += '.coffee';
|
||||
}
|
||||
|
||||
if (!test('-f', scriptName)) {
|
||||
console.log('ShellJS: script not found ('+scriptName+')');
|
||||
console.log();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
args = process.argv.slice(3);
|
||||
|
||||
for (var i = 0, l = args.length; i < l; i++) {
|
||||
if (args[i][0] !== "-"){
|
||||
args[i] = '"' + args[i] + '"'; // fixes arguments with multiple words
|
||||
}
|
||||
}
|
||||
|
||||
if (scriptName.match(/\.coffee$/)) {
|
||||
//
|
||||
// CoffeeScript
|
||||
//
|
||||
if (which('coffee')) {
|
||||
exec('coffee ' + scriptName + ' ' + args.join(' '), { async: true });
|
||||
} else {
|
||||
console.log('ShellJS: CoffeeScript interpreter not found');
|
||||
console.log();
|
||||
process.exit(1);
|
||||
}
|
||||
} else {
|
||||
//
|
||||
// JavaScript
|
||||
//
|
||||
exec('node ' + scriptName + ' ' + args.join(' '), { async: true });
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
var shell = require('./shell.js');
|
||||
for (var cmd in shell)
|
||||
global[cmd] = shell[cmd];
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"loopfunc": true,
|
||||
"sub": true
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
require('./global');
|
||||
config.fatal = true;
|
||||
|
||||
global.target = {};
|
||||
|
||||
// This ensures we only execute the script targets after the entire script has
|
||||
// been evaluated
|
||||
var args = process.argv.slice(2);
|
||||
setTimeout(function() {
|
||||
var t;
|
||||
|
||||
if (args.length === 1 && args[0] === '--help') {
|
||||
console.log('Available targets:');
|
||||
for (t in target)
|
||||
console.log(' ' + t);
|
||||
return;
|
||||
}
|
||||
|
||||
// Wrap targets to prevent duplicate execution
|
||||
for (t in target) {
|
||||
(function(t, oldTarget){
|
||||
|
||||
// Wrap it
|
||||
target[t] = function(force) {
|
||||
if (oldTarget.done && !force)
|
||||
return;
|
||||
oldTarget.done = true;
|
||||
return oldTarget.apply(oldTarget, arguments);
|
||||
};
|
||||
|
||||
})(t, target[t]);
|
||||
}
|
||||
|
||||
// Execute desired targets
|
||||
if (args.length > 0) {
|
||||
args.forEach(function(arg) {
|
||||
if (arg in target)
|
||||
target[arg]();
|
||||
else {
|
||||
console.log('no such target: ' + arg);
|
||||
exit(1);
|
||||
}
|
||||
});
|
||||
} else if ('all' in target) {
|
||||
target.all();
|
||||
}
|
||||
|
||||
}, 0);
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env node
|
||||
require('../global');
|
||||
|
||||
echo('Appending docs to README.md');
|
||||
|
||||
cd(__dirname + '/..');
|
||||
|
||||
// Extract docs from shell.js
|
||||
var docs = grep('//@', 'shell.js');
|
||||
// Remove '//@'
|
||||
docs = docs.replace(/\/\/\@ ?/g, '');
|
||||
// Append docs to README
|
||||
sed('-i', /## Command reference(.|\n)*/, '## Command reference\n\n' + docs, 'README.md');
|
||||
|
||||
echo('All done.');
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env node
|
||||
require('../global');
|
||||
|
||||
var path = require('path');
|
||||
|
||||
var failed = false;
|
||||
|
||||
//
|
||||
// Lint
|
||||
//
|
||||
JSHINT_BIN = './node_modules/jshint/bin/jshint';
|
||||
cd(__dirname + '/..');
|
||||
|
||||
if (!test('-f', JSHINT_BIN)) {
|
||||
echo('JSHint not found. Run `npm install` in the root dir first.');
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (exec(JSHINT_BIN + ' --config jshint.json *.js test/*.js').code !== 0) {
|
||||
failed = true;
|
||||
echo('*** JSHINT FAILED! (return code != 0)');
|
||||
echo();
|
||||
} else {
|
||||
echo('All JSHint tests passed');
|
||||
echo();
|
||||
}
|
||||
|
||||
//
|
||||
// Unit tests
|
||||
//
|
||||
cd(__dirname + '/../test');
|
||||
ls('*.js').forEach(function(file) {
|
||||
echo('Running test:', file);
|
||||
if (exec('node ' + file).code !== 123) { // 123 avoids false positives (e.g. premature exit)
|
||||
failed = true;
|
||||
echo('*** TEST FAILED! (missing exit code "123")');
|
||||
echo();
|
||||
}
|
||||
});
|
||||
|
||||
if (failed) {
|
||||
echo();
|
||||
echo('*******************************************************');
|
||||
echo('WARNING: Some tests did not pass!');
|
||||
echo('*******************************************************');
|
||||
exit(1);
|
||||
} else {
|
||||
echo();
|
||||
echo('All tests passed.');
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,2 @@
|
|||
tmp/
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
// save current dir
|
||||
var cur = shell.pwd();
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.cat();
|
||||
assert.ok(shell.error());
|
||||
|
||||
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
|
||||
shell.cat('/adsfasdf'); // file does not exist
|
||||
assert.ok(shell.error());
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
// simple
|
||||
var result = shell.cat('resources/file1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'test1');
|
||||
|
||||
// multiple files
|
||||
var result = shell.cat('resources/file2', 'resources/file1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'test2\ntest1');
|
||||
|
||||
// multiple files, array syntax
|
||||
var result = shell.cat(['resources/file2', 'resources/file1']);
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'test2\ntest1');
|
||||
|
||||
var result = shell.cat('resources/file*.txt');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.ok(result.search('test1') > -1); // file order might be random
|
||||
assert.ok(result.search('test2') > -1);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,64 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
// save current dir
|
||||
var cur = shell.pwd();
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.cd();
|
||||
assert.ok(shell.error());
|
||||
|
||||
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
|
||||
shell.cd('/adsfasdf'); // dir does not exist
|
||||
assert.ok(shell.error());
|
||||
|
||||
assert.equal(fs.existsSync('resources/file1'), true); // sanity check
|
||||
shell.cd('resources/file1'); // file, not dir
|
||||
assert.ok(shell.error());
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
shell.cd(cur);
|
||||
shell.cd('tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(path.basename(process.cwd()), 'tmp');
|
||||
|
||||
shell.cd(cur);
|
||||
shell.cd('/');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), path.resolve('/'));
|
||||
|
||||
// cd + other commands
|
||||
|
||||
shell.cd(cur);
|
||||
shell.rm('-f', 'tmp/*');
|
||||
assert.equal(fs.existsSync('tmp/file1'), false);
|
||||
shell.cd('resources');
|
||||
assert.equal(shell.error(), null);
|
||||
shell.cp('file1', '../tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
shell.cd('../tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('file1'), true);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,81 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.chmod('blah'); // missing args
|
||||
assert.ok(shell.error());
|
||||
shell.chmod('893', 'resources/chmod'); // invalid permissions - mode must be in octal
|
||||
assert.ok(shell.error());
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
// Test files - the bitmasking is to ignore the upper bits.
|
||||
shell.chmod('755', 'resources/chmod/file1');
|
||||
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('755', 8));
|
||||
shell.chmod('644', 'resources/chmod/file1');
|
||||
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8));
|
||||
|
||||
shell.chmod('o+x', 'resources/chmod/file1');
|
||||
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('007', 8), parseInt('005', 8));
|
||||
shell.chmod('644', 'resources/chmod/file1');
|
||||
|
||||
shell.chmod('+x', 'resources/chmod/file1');
|
||||
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('755', 8));
|
||||
shell.chmod('644', 'resources/chmod/file1');
|
||||
|
||||
// Test setuid
|
||||
shell.chmod('u+s', 'resources/chmod/file1');
|
||||
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('4000', 8), parseInt('4000', 8));
|
||||
shell.chmod('u-s', 'resources/chmod/file1');
|
||||
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8));
|
||||
|
||||
// according to POSIX standards at http://linux.die.net/man/1/chmod,
|
||||
// setuid is never cleared from a directory unless explicitly asked for.
|
||||
shell.chmod('u+s', 'resources/chmod/c');
|
||||
shell.chmod('755', 'resources/chmod/c');
|
||||
assert.equal(fs.statSync('resources/chmod/c').mode & parseInt('4000', 8), parseInt('4000', 8));
|
||||
shell.chmod('u-s', 'resources/chmod/c');
|
||||
|
||||
// Test setgid
|
||||
shell.chmod('g+s', 'resources/chmod/file1');
|
||||
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('2000', 8), parseInt('2000', 8));
|
||||
shell.chmod('g-s', 'resources/chmod/file1');
|
||||
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8));
|
||||
|
||||
// Test sticky bit
|
||||
shell.chmod('+t', 'resources/chmod/file1');
|
||||
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('1000', 8), parseInt('1000', 8));
|
||||
shell.chmod('-t', 'resources/chmod/file1');
|
||||
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8));
|
||||
assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('1000', 8), 0);
|
||||
|
||||
// Test directories
|
||||
shell.chmod('a-w', 'resources/chmod/b/a/b');
|
||||
assert.equal(fs.statSync('resources/chmod/b/a/b').mode & parseInt('777', 8), parseInt('555', 8));
|
||||
shell.chmod('755', 'resources/chmod/b/a/b');
|
||||
|
||||
// Test recursion
|
||||
shell.chmod('-R', 'a+w', 'resources/chmod/b');
|
||||
assert.equal(fs.statSync('resources/chmod/b/a/b').mode & parseInt('777', 8), parseInt('777', 8));
|
||||
shell.chmod('-R', '755', 'resources/chmod/b');
|
||||
assert.equal(fs.statSync('resources/chmod/b/a/b').mode & parseInt('777', 8), parseInt('755', 8));
|
||||
|
||||
// Test symbolic links w/ recursion - WARNING: *nix only
|
||||
fs.symlinkSync('resources/chmod/b/a', 'resources/chmod/a/b/c/link', 'dir');
|
||||
shell.chmod('-R', 'u-w', 'resources/chmod/a/b');
|
||||
assert.equal(fs.statSync('resources/chmod/a/b/c').mode & parseInt('700', 8), parseInt('500', 8));
|
||||
assert.equal(fs.statSync('resources/chmod/b/a').mode & parseInt('700', 8), parseInt('700', 8));
|
||||
shell.chmod('-R', 'u+w', 'resources/chmod/a/b');
|
||||
fs.unlinkSync('resources/chmod/a/b/c/link');
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,50 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
child = require('child_process');
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
//
|
||||
// config.silent
|
||||
//
|
||||
|
||||
assert.equal(shell.config.silent, false); // default
|
||||
|
||||
shell.config.silent = true;
|
||||
assert.equal(shell.config.silent, true);
|
||||
|
||||
shell.config.silent = false;
|
||||
assert.equal(shell.config.silent, false);
|
||||
|
||||
//
|
||||
// config.fatal
|
||||
//
|
||||
|
||||
assert.equal(shell.config.fatal, false); // default
|
||||
|
||||
//
|
||||
// config.fatal = false
|
||||
//
|
||||
shell.mkdir('-p', 'tmp');
|
||||
var file = 'tmp/tempscript'+Math.random()+'.js',
|
||||
script = 'require(\'../../global.js\'); config.silent=true; config.fatal=false; cp("this_file_doesnt_exist", "."); echo("got here");';
|
||||
script.to(file);
|
||||
child.exec('node '+file, function(err, stdout, stderr) {
|
||||
assert.ok(stdout.match('got here'));
|
||||
|
||||
//
|
||||
// config.fatal = true
|
||||
//
|
||||
shell.mkdir('-p', 'tmp');
|
||||
var file = 'tmp/tempscript'+Math.random()+'.js',
|
||||
script = 'require(\'../../global.js\'); config.silent=true; config.fatal=true; cp("this_file_doesnt_exist", "."); echo("got here");';
|
||||
script.to(file);
|
||||
child.exec('node '+file, function(err, stdout, stderr) {
|
||||
assert.ok(!stdout.match('got here'));
|
||||
|
||||
shell.exit(123);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,143 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.cp();
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.cp('file1');
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.cp('-f');
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.rm('-rf', 'tmp/*');
|
||||
shell.cp('-@', 'resources/file1', 'tmp/file1'); // option not supported, files OK
|
||||
assert.ok(shell.error());
|
||||
assert.equal(fs.existsSync('tmp/file1'), false);
|
||||
|
||||
shell.cp('-Z', 'asdfasdf', 'tmp/file2'); // option not supported, files NOT OK
|
||||
assert.ok(shell.error());
|
||||
assert.equal(fs.existsSync('tmp/file2'), false);
|
||||
|
||||
shell.cp('asdfasdf', 'tmp'); // source does not exist
|
||||
assert.ok(shell.error());
|
||||
assert.equal(numLines(shell.error()), 1);
|
||||
assert.equal(fs.existsSync('tmp/asdfasdf'), false);
|
||||
|
||||
shell.cp('asdfasdf1', 'asdfasdf2', 'tmp'); // sources do not exist
|
||||
assert.ok(shell.error());
|
||||
assert.equal(numLines(shell.error()), 2);
|
||||
assert.equal(fs.existsSync('tmp/asdfasdf1'), false);
|
||||
assert.equal(fs.existsSync('tmp/asdfasdf2'), false);
|
||||
|
||||
shell.cp('asdfasdf1', 'asdfasdf2', 'resources/file1'); // too many sources (dest is file)
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.cp('resources/file1', 'resources/file2'); // dest already exists
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.cp('resources/file1', 'resources/file2', 'tmp/a_file'); // too many sources
|
||||
assert.ok(shell.error());
|
||||
assert.equal(fs.existsSync('tmp/a_file'), false);
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
// simple - to dir
|
||||
shell.cp('resources/file1', 'tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/file1'), true);
|
||||
|
||||
// simple - to file
|
||||
shell.cp('resources/file2', 'tmp/file2');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/file2'), true);
|
||||
|
||||
// simple - file list
|
||||
shell.rm('-rf', 'tmp/*');
|
||||
shell.cp('resources/file1', 'resources/file2', 'tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/file1'), true);
|
||||
assert.equal(fs.existsSync('tmp/file2'), true);
|
||||
|
||||
// simple - file list, array syntax
|
||||
shell.rm('-rf', 'tmp/*');
|
||||
shell.cp(['resources/file1', 'resources/file2'], 'tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/file1'), true);
|
||||
assert.equal(fs.existsSync('tmp/file2'), true);
|
||||
|
||||
shell.cp('resources/file2', 'tmp/file3');
|
||||
assert.equal(fs.existsSync('tmp/file3'), true);
|
||||
shell.cp('-f', 'resources/file2', 'tmp/file3'); // file exists, but -f specified
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/file3'), true);
|
||||
|
||||
// wildcard
|
||||
shell.rm('tmp/file1', 'tmp/file2');
|
||||
shell.cp('resources/file*', 'tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/file1'), true);
|
||||
assert.equal(fs.existsSync('tmp/file2'), true);
|
||||
|
||||
//recursive, nothing exists
|
||||
shell.rm('-rf', 'tmp/*');
|
||||
shell.cp('-R', 'resources/cp', 'tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(shell.ls('-R', 'resources/cp') + '', shell.ls('-R', 'tmp/cp') + '');
|
||||
|
||||
//recursive, nothing exists, source ends in '/' (see Github issue #15)
|
||||
shell.rm('-rf', 'tmp/*');
|
||||
shell.cp('-R', 'resources/cp/', 'tmp/');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(shell.ls('-R', 'resources/cp') + '', shell.ls('-R', 'tmp') + '');
|
||||
|
||||
//recursive, everything exists, no force flag
|
||||
shell.rm('-rf', 'tmp/*');
|
||||
shell.cp('-R', 'resources/cp', 'tmp');
|
||||
shell.cp('-R', 'resources/cp', 'tmp');
|
||||
assert.equal(shell.error(), null); // crash test only
|
||||
|
||||
//recursive, everything exists, with force flag
|
||||
shell.rm('-rf', 'tmp/*');
|
||||
shell.cp('-R', 'resources/cp', 'tmp');
|
||||
'changing things around'.to('tmp/cp/dir_a/z');
|
||||
assert.notEqual(shell.cat('resources/cp/dir_a/z'), shell.cat('tmp/cp/dir_a/z')); // before cp
|
||||
shell.cp('-Rf', 'resources/cp', 'tmp');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(shell.cat('resources/cp/dir_a/z'), shell.cat('tmp/cp/dir_a/z')); // after cp
|
||||
|
||||
//recursive, creates dest dir since it's only one level deep (see Github issue #44)
|
||||
shell.rm('-rf', 'tmp/*');
|
||||
shell.cp('-r', 'resources/issue44/*', 'tmp/dir2');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(shell.ls('-R', 'resources/issue44') + '', shell.ls('-R', 'tmp/dir2') + '');
|
||||
assert.equal(shell.cat('resources/issue44/main.js'), shell.cat('tmp/dir2/main.js'));
|
||||
|
||||
//recursive, does *not* create dest dir since it's too deep (see Github issue #44)
|
||||
shell.rm('-rf', 'tmp/*');
|
||||
shell.cp('-r', 'resources/issue44/*', 'tmp/dir2/dir3');
|
||||
assert.ok(shell.error());
|
||||
assert.equal(fs.existsSync('tmp/dir2'), false);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,37 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
var root = path.resolve();
|
||||
|
||||
shell.pushd('resources/pushd');
|
||||
shell.pushd('a');
|
||||
|
||||
var trail = [
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
];
|
||||
|
||||
assert.deepEqual(shell.dirs(), trail);
|
||||
|
||||
// Single items
|
||||
assert.equal(shell.dirs('+0'), trail[0]);
|
||||
assert.equal(shell.dirs('+1'), trail[1]);
|
||||
assert.equal(shell.dirs('+2'), trail[2]);
|
||||
assert.equal(shell.dirs('-0'), trail[2]);
|
||||
assert.equal(shell.dirs('-1'), trail[1]);
|
||||
assert.equal(shell.dirs('-2'), trail[0]);
|
||||
|
||||
// Clearing items
|
||||
assert.deepEqual(shell.dirs('-c'), []);
|
||||
assert(!shell.error());
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,50 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
child = require('child_process');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
|
||||
// From here on we use child.exec() to intercept the stdout
|
||||
|
||||
|
||||
// simple test with defaults
|
||||
shell.mkdir('-p', 'tmp');
|
||||
var file = 'tmp/tempscript'+Math.random()+'.js',
|
||||
script = 'require(\'../../global.js\'); echo("-asdf", "111");'; // test '-' bug (see issue #20)
|
||||
script.to(file);
|
||||
child.exec('node '+file, function(err, stdout, stderr) {
|
||||
assert.ok(stdout === '-asdf 111\n' || stdout === '-asdf 111\nundefined\n'); // 'undefined' for v0.4
|
||||
|
||||
// simple test with silent(true)
|
||||
shell.mkdir('-p', 'tmp');
|
||||
var file = 'tmp/tempscript'+Math.random()+'.js',
|
||||
script = 'require(\'../../global.js\'); config.silent=true; echo(555);';
|
||||
script.to(file);
|
||||
child.exec('node '+file, function(err, stdout, stderr) {
|
||||
assert.ok(stdout === '555\n' || stdout === '555\nundefined\n'); // 'undefined' for v0.4
|
||||
|
||||
theEnd();
|
||||
});
|
||||
});
|
||||
|
||||
function theEnd() {
|
||||
shell.exit(123);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert');
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
assert.equal(shell.env['PATH'], process.env['PATH']);
|
||||
|
||||
shell.env['SHELLJS_TEST'] = 'hello world';
|
||||
assert.equal(shell.env['SHELLJS_TEST'], process.env['SHELLJS_TEST']);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,109 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
util = require('util'),
|
||||
child = require('child_process');
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.exec();
|
||||
assert.ok(shell.error());
|
||||
|
||||
var result = shell.exec('asdfasdf'); // could not find command
|
||||
assert.ok(result.code > 0);
|
||||
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
//
|
||||
// sync
|
||||
//
|
||||
|
||||
// check if stdout goes to output
|
||||
var result = shell.exec('node -e \"console.log(1234);\"');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.code, 0);
|
||||
assert.ok(result.output === '1234\n' || result.output === '1234\nundefined\n'); // 'undefined' for v0.4
|
||||
|
||||
// check if stderr goes to output
|
||||
var result = shell.exec('node -e \"console.error(1234);\"');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.code, 0);
|
||||
assert.ok(result.output === '1234\n' || result.output === '1234\nundefined\n'); // 'undefined' for v0.4
|
||||
|
||||
// check if stdout + stderr go to output
|
||||
var result = shell.exec('node -e \"console.error(1234); console.log(666);\"');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.code, 0);
|
||||
assert.ok(result.output === '1234\n666\n' || result.output === '1234\n666\nundefined\n'); // 'undefined' for v0.4
|
||||
|
||||
// check exit code
|
||||
var result = shell.exec('node -e \"process.exit(12);\"');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.code, 12);
|
||||
|
||||
// interaction with cd
|
||||
shell.cd('resources/external');
|
||||
var result = shell.exec('node node_script.js');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.code, 0);
|
||||
assert.equal(result.output, 'node_script_1234\n');
|
||||
shell.cd('../..');
|
||||
|
||||
// check quotes escaping
|
||||
var result = shell.exec( util.format('node -e "console.log(%s);"', "\\\"\\'+\\'_\\'+\\'\\\"") );
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.code, 0);
|
||||
assert.equal(result.output, "'+'_'+'\n");
|
||||
|
||||
//
|
||||
// async
|
||||
//
|
||||
|
||||
// no callback
|
||||
var c = shell.exec('node -e \"console.log(1234)\"', {async:true});
|
||||
assert.equal(shell.error(), null);
|
||||
assert.ok('stdout' in c, 'async exec returns child process object');
|
||||
|
||||
//
|
||||
// callback as 2nd argument
|
||||
//
|
||||
shell.exec('node -e \"console.log(5678);\"', function(code, output) {
|
||||
assert.equal(code, 0);
|
||||
assert.ok(output === '5678\n' || output === '5678\nundefined\n'); // 'undefined' for v0.4
|
||||
|
||||
//
|
||||
// callback as 3rd argument
|
||||
//
|
||||
shell.exec('node -e \"console.log(5566);\"', {async:true}, function(code, output) {
|
||||
assert.equal(code, 0);
|
||||
assert.ok(output === '5566\n' || output === '5566\nundefined\n'); // 'undefined' for v0.4
|
||||
|
||||
//
|
||||
// callback as 3rd argument (slient:true)
|
||||
//
|
||||
shell.exec('node -e \"console.log(5678);\"', {silent:true}, function(code, output) {
|
||||
assert.equal(code, 0);
|
||||
assert.ok(output === '5678\n' || output === '5678\nundefined\n'); // 'undefined' for v0.4
|
||||
|
||||
shell.exit(123);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
assert.equal(shell.error(), null);
|
|
@ -0,0 +1,56 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
var result = shell.find(); // no paths given
|
||||
assert.ok(shell.error());
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
// current path
|
||||
shell.cd('resources/find');
|
||||
var result = shell.find('.');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('.hidden') > -1, true);
|
||||
assert.equal(result.indexOf('dir1/dir11/a_dir11') > -1, true);
|
||||
assert.equal(result.length, 11);
|
||||
shell.cd('../..');
|
||||
|
||||
// simple path
|
||||
var result = shell.find('resources/find');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('resources/find/.hidden') > -1, true);
|
||||
assert.equal(result.indexOf('resources/find/dir1/dir11/a_dir11') > -1, true);
|
||||
assert.equal(result.length, 11);
|
||||
|
||||
// multiple paths - comma
|
||||
var result = shell.find('resources/find/dir1', 'resources/find/dir2');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('resources/find/dir1/dir11/a_dir11') > -1, true);
|
||||
assert.equal(result.indexOf('resources/find/dir2/a_dir1') > -1, true);
|
||||
assert.equal(result.length, 6);
|
||||
|
||||
// multiple paths - array
|
||||
var result = shell.find(['resources/find/dir1', 'resources/find/dir2']);
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('resources/find/dir1/dir11/a_dir11') > -1, true);
|
||||
assert.equal(result.indexOf('resources/find/dir2/a_dir1') > -1, true);
|
||||
assert.equal(result.length, 6);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,59 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.grep();
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.grep(/asdf/g); // too few args
|
||||
assert.ok(shell.error());
|
||||
|
||||
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
|
||||
shell.grep(/asdf/g, '/asdfasdf'); // no such file
|
||||
assert.ok(shell.error());
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
var result = shell.grep('line', 'resources/a.txt');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.split('\n').length - 1, 4);
|
||||
|
||||
var result = shell.grep('-v', 'line', 'resources/a.txt');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.split('\n').length - 1, 8);
|
||||
|
||||
var result = shell.grep('line one', 'resources/a.txt');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'This is line one\n');
|
||||
|
||||
// multiple files
|
||||
var result = shell.grep(/test/, 'resources/file1.txt', 'resources/file2.txt');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'test1\ntest2\n');
|
||||
|
||||
// multiple files, array syntax
|
||||
var result = shell.grep(/test/, ['resources/file1.txt', 'resources/file2.txt']);
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'test1\ntest2\n');
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,202 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
|
||||
var result = shell.ls('/asdfasdf'); // no such file or dir
|
||||
assert.ok(shell.error());
|
||||
assert.equal(result.length, 0);
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
var result = shell.ls();
|
||||
assert.equal(shell.error(), null);
|
||||
|
||||
var result = shell.ls('/');
|
||||
assert.equal(shell.error(), null);
|
||||
|
||||
// no args
|
||||
shell.cd('resources/ls');
|
||||
var result = shell.ls();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('file1') > -1, true);
|
||||
assert.equal(result.indexOf('file2') > -1, true);
|
||||
assert.equal(result.indexOf('file1.js') > -1, true);
|
||||
assert.equal(result.indexOf('file2.js') > -1, true);
|
||||
assert.equal(result.indexOf('filename(with)[chars$]^that.must+be-escaped') > -1, true);
|
||||
assert.equal(result.indexOf('a_dir') > -1, true);
|
||||
assert.equal(result.length, 6);
|
||||
shell.cd('../..');
|
||||
|
||||
// simple arg
|
||||
var result = shell.ls('resources/ls');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('file1') > -1, true);
|
||||
assert.equal(result.indexOf('file2') > -1, true);
|
||||
assert.equal(result.indexOf('file1.js') > -1, true);
|
||||
assert.equal(result.indexOf('file2.js') > -1, true);
|
||||
assert.equal(result.indexOf('filename(with)[chars$]^that.must+be-escaped') > -1, true);
|
||||
assert.equal(result.indexOf('a_dir') > -1, true);
|
||||
assert.equal(result.length, 6);
|
||||
|
||||
// no args, 'all' option
|
||||
shell.cd('resources/ls');
|
||||
var result = shell.ls('-A');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('file1') > -1, true);
|
||||
assert.equal(result.indexOf('file2') > -1, true);
|
||||
assert.equal(result.indexOf('file1.js') > -1, true);
|
||||
assert.equal(result.indexOf('file2.js') > -1, true);
|
||||
assert.equal(result.indexOf('filename(with)[chars$]^that.must+be-escaped') > -1, true);
|
||||
assert.equal(result.indexOf('a_dir') > -1, true);
|
||||
assert.equal(result.indexOf('.hidden_file') > -1, true);
|
||||
assert.equal(result.indexOf('.hidden_dir') > -1, true);
|
||||
assert.equal(result.length, 8);
|
||||
shell.cd('../..');
|
||||
|
||||
// no args, 'all' option
|
||||
shell.cd('resources/ls');
|
||||
var result = shell.ls('-a'); // (deprecated) backwards compatibility test
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('file1') > -1, true);
|
||||
assert.equal(result.indexOf('file2') > -1, true);
|
||||
assert.equal(result.indexOf('file1.js') > -1, true);
|
||||
assert.equal(result.indexOf('file2.js') > -1, true);
|
||||
assert.equal(result.indexOf('filename(with)[chars$]^that.must+be-escaped') > -1, true);
|
||||
assert.equal(result.indexOf('a_dir') > -1, true);
|
||||
assert.equal(result.indexOf('.hidden_file') > -1, true);
|
||||
assert.equal(result.indexOf('.hidden_dir') > -1, true);
|
||||
assert.equal(result.length, 8);
|
||||
shell.cd('../..');
|
||||
|
||||
// wildcard, simple
|
||||
var result = shell.ls('resources/ls/*');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('resources/ls/file1') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/file2') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/file2.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/filename(with)[chars$]^that.must+be-escaped') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/a_dir') > -1, true);
|
||||
assert.equal(result.length, 6);
|
||||
|
||||
// wildcard, hidden only
|
||||
var result = shell.ls('resources/ls/.*');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('resources/ls/.hidden_file') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/.hidden_dir') > -1, true);
|
||||
assert.equal(result.length, 2);
|
||||
|
||||
// wildcard, mid-file
|
||||
var result = shell.ls('resources/ls/f*le*');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.length, 5);
|
||||
assert.equal(result.indexOf('resources/ls/file1') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/file2') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/file2.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/filename(with)[chars$]^that.must+be-escaped') > -1, true);
|
||||
|
||||
// wildcard, mid-file with dot (should escape dot for regex)
|
||||
var result = shell.ls('resources/ls/f*le*.js');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.length, 2);
|
||||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/file2.js') > -1, true);
|
||||
|
||||
// wildcard, should not do partial matches
|
||||
var result = shell.ls('resources/ls/*.j'); // shouldn't get .js
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.length, 0);
|
||||
|
||||
// wildcard, all files with extension
|
||||
var result = shell.ls('resources/ls/*.*');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.length, 3);
|
||||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/file2.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/filename(with)[chars$]^that.must+be-escaped') > -1, true);
|
||||
|
||||
// wildcard, with additional path
|
||||
var result = shell.ls('resources/ls/f*le*.js', 'resources/ls/a_dir');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.length, 4);
|
||||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/file2.js') > -1, true);
|
||||
assert.equal(result.indexOf('b_dir') > -1, true); // no wildcard == no path prefix
|
||||
assert.equal(result.indexOf('nada') > -1, true); // no wildcard == no path prefix
|
||||
|
||||
// wildcard for both paths
|
||||
var result = shell.ls('resources/ls/f*le*.js', 'resources/ls/a_dir/*');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.length, 4);
|
||||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/file2.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/a_dir/b_dir') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/a_dir/nada') > -1, true);
|
||||
|
||||
// wildcard for both paths, array
|
||||
var result = shell.ls(['resources/ls/f*le*.js', 'resources/ls/a_dir/*']);
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.length, 4);
|
||||
assert.equal(result.indexOf('resources/ls/file1.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/file2.js') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/a_dir/b_dir') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/a_dir/nada') > -1, true);
|
||||
|
||||
// recursive, no path
|
||||
shell.cd('resources/ls');
|
||||
var result = shell.ls('-R');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('a_dir') > -1, true);
|
||||
assert.equal(result.indexOf('a_dir/b_dir') > -1, true);
|
||||
assert.equal(result.indexOf('a_dir/b_dir/z') > -1, true);
|
||||
assert.equal(result.length, 9);
|
||||
shell.cd('../..');
|
||||
|
||||
// recusive, path given
|
||||
var result = shell.ls('-R', 'resources/ls');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('a_dir') > -1, true);
|
||||
assert.equal(result.indexOf('a_dir/b_dir') > -1, true);
|
||||
assert.equal(result.indexOf('a_dir/b_dir/z') > -1, true);
|
||||
assert.equal(result.length, 9);
|
||||
|
||||
// recusive, path given - 'all' flag
|
||||
var result = shell.ls('-RA', 'resources/ls');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('a_dir') > -1, true);
|
||||
assert.equal(result.indexOf('a_dir/b_dir') > -1, true);
|
||||
assert.equal(result.indexOf('a_dir/b_dir/z') > -1, true);
|
||||
assert.equal(result.indexOf('a_dir/.hidden_dir/nada') > -1, true);
|
||||
assert.equal(result.length, 14);
|
||||
|
||||
// recursive, wildcard
|
||||
var result = shell.ls('-R', 'resources/ls/*');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result.indexOf('resources/ls/a_dir') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/a_dir/b_dir') > -1, true);
|
||||
assert.equal(result.indexOf('resources/ls/a_dir/b_dir/z') > -1, true);
|
||||
assert.equal(result.length, 9);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,20 @@
|
|||
var shell = require('..'),
|
||||
child = require('child_process'),
|
||||
assert = require('assert');
|
||||
|
||||
shell.mkdir('-p', 'tmp');
|
||||
var file = 'tmp/tempscript'+Math.random()+'.js',
|
||||
script = 'require(\'../../make.js\');' +
|
||||
'target.all=function(){' +
|
||||
' echo("first"); '+
|
||||
' cp("this_file_doesnt_exist", ".");' +
|
||||
' echo("second");' +
|
||||
'}';
|
||||
|
||||
script.to(file);
|
||||
child.exec('node '+file, function(err, stdout, stderr) {
|
||||
assert.ok(stdout.match('first'));
|
||||
assert.ok(!stdout.match('second')); // Make should die on errors, so this should never get echoed
|
||||
|
||||
shell.exit(123);
|
||||
});
|
|
@ -0,0 +1,79 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.mkdir();
|
||||
assert.ok(shell.error());
|
||||
|
||||
var mtime = fs.statSync('tmp').mtime.toString();
|
||||
shell.mkdir('tmp'); // dir already exists
|
||||
assert.ok(shell.error());
|
||||
assert.equal(fs.statSync('tmp').mtime.toString(), mtime); // didn't mess with dir
|
||||
|
||||
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
|
||||
shell.mkdir('/asdfasdf/asdfasdf'); // root path does not exist
|
||||
assert.ok(shell.error());
|
||||
assert.equal(fs.existsSync('/asdfasdf'), false);
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
assert.equal(fs.existsSync('tmp/t1'), false);
|
||||
shell.mkdir('tmp/t1'); // simple dir
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/t1'), true);
|
||||
|
||||
assert.equal(fs.existsSync('tmp/t2'), false);
|
||||
assert.equal(fs.existsSync('tmp/t3'), false);
|
||||
shell.mkdir('tmp/t2', 'tmp/t3'); // multiple dirs
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/t2'), true);
|
||||
assert.equal(fs.existsSync('tmp/t3'), true);
|
||||
|
||||
assert.equal(fs.existsSync('tmp/t1'), true);
|
||||
assert.equal(fs.existsSync('tmp/t4'), false);
|
||||
shell.mkdir('tmp/t1', 'tmp/t4'); // one dir exists, one doesn't
|
||||
assert.equal(numLines(shell.error()), 1);
|
||||
assert.equal(fs.existsSync('tmp/t1'), true);
|
||||
assert.equal(fs.existsSync('tmp/t4'), true);
|
||||
|
||||
assert.equal(fs.existsSync('tmp/a'), false);
|
||||
shell.mkdir('-p', 'tmp/a/b/c');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/a/b/c'), true);
|
||||
shell.rm('-Rf', 'tmp/a'); // revert
|
||||
|
||||
// multiple dirs
|
||||
shell.mkdir('-p', 'tmp/zzza', 'tmp/zzzb', 'tmp/zzzc');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/zzza'), true);
|
||||
assert.equal(fs.existsSync('tmp/zzzb'), true);
|
||||
assert.equal(fs.existsSync('tmp/zzzc'), true);
|
||||
|
||||
// multiple dirs, array syntax
|
||||
shell.mkdir('-p', ['tmp/yyya', 'tmp/yyyb', 'tmp/yyyc']);
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/yyya'), true);
|
||||
assert.equal(fs.existsSync('tmp/yyyb'), true);
|
||||
assert.equal(fs.existsSync('tmp/yyyc'), true);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,130 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
// Prepare tmp/
|
||||
shell.cp('resources/*', 'tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.mv();
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.mv('file1');
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.mv('-f');
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.mv('-Z', 'tmp/file1', 'tmp/file1'); // option not supported
|
||||
assert.ok(shell.error());
|
||||
assert.equal(fs.existsSync('tmp/file1'), true);
|
||||
|
||||
shell.mv('asdfasdf', 'tmp'); // source does not exist
|
||||
assert.ok(shell.error());
|
||||
assert.equal(numLines(shell.error()), 1);
|
||||
assert.equal(fs.existsSync('tmp/asdfasdf'), false);
|
||||
|
||||
shell.mv('asdfasdf1', 'asdfasdf2', 'tmp'); // sources do not exist
|
||||
assert.ok(shell.error());
|
||||
assert.equal(numLines(shell.error()), 2);
|
||||
assert.equal(fs.existsSync('tmp/asdfasdf1'), false);
|
||||
assert.equal(fs.existsSync('tmp/asdfasdf2'), false);
|
||||
|
||||
shell.mv('asdfasdf1', 'asdfasdf2', 'tmp/file1'); // too many sources (dest is file)
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.mv('tmp/file1', 'tmp/file2'); // dest already exists
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.mv('tmp/file1', 'tmp/file2', 'tmp/a_file'); // too many sources (exist, but dest is file)
|
||||
assert.ok(shell.error());
|
||||
assert.equal(fs.existsSync('tmp/a_file'), false);
|
||||
|
||||
shell.mv('tmp/file*', 'tmp/file1'); // can't use wildcard when dest is file
|
||||
assert.ok(shell.error());
|
||||
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);
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
shell.cd('tmp');
|
||||
|
||||
// handles self OK
|
||||
shell.mkdir('tmp2');
|
||||
shell.mv('*', 'tmp2'); // has to handle self (tmp2 --> tmp2) without throwing error
|
||||
assert.ok(shell.error()); // there's an error, but not fatal
|
||||
assert.equal(fs.existsSync('tmp2/file1'), true); // moved OK
|
||||
shell.mv('tmp2/*', '.'); // revert
|
||||
assert.equal(fs.existsSync('file1'), true); // moved OK
|
||||
|
||||
shell.mv('file1', 'file3'); // one source
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('file1'), false);
|
||||
assert.equal(fs.existsSync('file3'), true);
|
||||
shell.mv('file3', 'file1'); // revert
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('file1'), true);
|
||||
|
||||
// two sources
|
||||
shell.rm('-rf', 't');
|
||||
shell.mkdir('-p', 't');
|
||||
shell.mv('file1', 'file2', 't');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('file1'), false);
|
||||
assert.equal(fs.existsSync('file2'), false);
|
||||
assert.equal(fs.existsSync('t/file1'), true);
|
||||
assert.equal(fs.existsSync('t/file2'), true);
|
||||
shell.mv('t/*', '.'); // revert
|
||||
assert.equal(fs.existsSync('file1'), true);
|
||||
assert.equal(fs.existsSync('file2'), true);
|
||||
|
||||
// two sources, array style
|
||||
shell.rm('-rf', 't');
|
||||
shell.mkdir('-p', 't');
|
||||
shell.mv(['file1', 'file2'], 't'); // two sources
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('file1'), false);
|
||||
assert.equal(fs.existsSync('file2'), false);
|
||||
assert.equal(fs.existsSync('t/file1'), true);
|
||||
assert.equal(fs.existsSync('t/file2'), true);
|
||||
shell.mv('t/*', '.'); // revert
|
||||
assert.equal(fs.existsSync('file1'), true);
|
||||
assert.equal(fs.existsSync('file2'), true);
|
||||
|
||||
shell.mv('file*.js', 't'); // wildcard
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('file1.js'), false);
|
||||
assert.equal(fs.existsSync('file2.js'), false);
|
||||
assert.equal(fs.existsSync('t/file1.js'), true);
|
||||
assert.equal(fs.existsSync('t/file2.js'), true);
|
||||
shell.mv('t/*', '.'); // revert
|
||||
assert.equal(fs.existsSync('file1.js'), true);
|
||||
assert.equal(fs.existsSync('file2.js'), true);
|
||||
|
||||
shell.mv('-f', 'file1', 'file2'); // dest exists, but -f given
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('file1'), false);
|
||||
assert.equal(fs.existsSync('file2'), true);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,118 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
var root = path.resolve(), trail;
|
||||
|
||||
function reset() {
|
||||
shell.dirs('-c');
|
||||
shell.cd(root);
|
||||
}
|
||||
|
||||
// Valid
|
||||
shell.pushd('resources/pushd');
|
||||
trail = shell.popd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [ root ]);
|
||||
|
||||
shell.pushd('resources/pushd');
|
||||
shell.pushd('a');
|
||||
trail = shell.popd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
shell.pushd('b');
|
||||
trail = shell.popd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
shell.pushd('b');
|
||||
shell.pushd('c');
|
||||
trail = shell.popd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
trail = shell.popd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
trail = shell.popd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(trail.length, 1);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [ root ]);
|
||||
|
||||
// Valid by index
|
||||
shell.pushd('resources/pushd');
|
||||
trail = shell.popd('+0');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [ root ]);
|
||||
|
||||
shell.pushd('resources/pushd');
|
||||
trail = shell.popd('+1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [ path.resolve(root, 'resources/pushd') ]);
|
||||
|
||||
reset(); shell.pushd('resources/pushd');
|
||||
trail = shell.popd('-0');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [ path.resolve(root, 'resources/pushd') ]);
|
||||
|
||||
reset(); shell.pushd('resources/pushd');
|
||||
trail = shell.popd('-1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [ root ]);
|
||||
|
||||
|
||||
reset(); shell.pushd('resources/pushd');
|
||||
trail = shell.popd('-n');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [ path.resolve(root, 'resources/pushd') ]);
|
||||
|
||||
// Invalid
|
||||
trail = shell.popd();
|
||||
assert.ok(shell.error('popd: directory stack empty\n'));
|
||||
|
||||
// Test that the root dir is not stored
|
||||
shell.cd('resources/pushd');
|
||||
shell.pushd('b');
|
||||
trail = shell.popd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(trail[0], path.resolve(root, 'resources/pushd'));
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
shell.popd();
|
||||
assert.ok(shell.error(), null);
|
||||
|
||||
shell.cd(root);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,228 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
var root = path.resolve(), trail;
|
||||
|
||||
function reset() {
|
||||
shell.dirs('-c');
|
||||
shell.cd(root);
|
||||
}
|
||||
|
||||
// Push valid directories
|
||||
trail = shell.pushd('resources/pushd');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
trail = shell.pushd('a');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
trail = shell.pushd('../b');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
trail = shell.pushd('c');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd/b/c'),
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
// Push stuff around with positive indices
|
||||
trail = shell.pushd('+0');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd/b/c'),
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
trail = shell.pushd('+1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root,
|
||||
path.resolve(root, 'resources/pushd/b/c')
|
||||
]);
|
||||
|
||||
trail = shell.pushd('+2');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root,
|
||||
path.resolve(root, 'resources/pushd/b/c'),
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd/a')
|
||||
]);
|
||||
|
||||
trail = shell.pushd('+3');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root,
|
||||
path.resolve(root, 'resources/pushd/b/c')
|
||||
]);
|
||||
|
||||
trail = shell.pushd('+4');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd/b/c'),
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
// Push stuff around with negative indices
|
||||
trail = shell.pushd('-0');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
root,
|
||||
path.resolve(root, 'resources/pushd/b/c'),
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd')
|
||||
]);
|
||||
|
||||
trail = shell.pushd('-1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root,
|
||||
path.resolve(root, 'resources/pushd/b/c'),
|
||||
path.resolve(root, 'resources/pushd/b')
|
||||
]);
|
||||
|
||||
trail = shell.pushd('-2');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
root,
|
||||
path.resolve(root, 'resources/pushd/b/c'),
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd')
|
||||
]);
|
||||
|
||||
trail = shell.pushd('-3');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd/b/c'),
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
trail = shell.pushd('-4');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
path.resolve(root, 'resources/pushd/b/c'),
|
||||
path.resolve(root, 'resources/pushd/b'),
|
||||
path.resolve(root, 'resources/pushd/a'),
|
||||
path.resolve(root, 'resources/pushd'),
|
||||
root
|
||||
]);
|
||||
|
||||
// Push without changing directory or resolving paths
|
||||
reset(); trail = shell.pushd('-n', 'resources/pushd');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
root,
|
||||
'resources/pushd'
|
||||
]);
|
||||
|
||||
trail = shell.pushd('-n', 'resources/pushd/a');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
assert.deepEqual(trail, [
|
||||
root,
|
||||
'resources/pushd/a',
|
||||
'resources/pushd'
|
||||
]);
|
||||
|
||||
// Push invalid directory
|
||||
shell.pushd('does/not/exist');
|
||||
assert.equal(shell.error(), 'pushd: no such file or directory: ' + path.resolve('.', 'does/not/exist') + '\n');
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
// Push without arguments should swap top two directories when stack length is 2
|
||||
reset(); trail = shell.pushd('resources/pushd');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(trail.length, 2);
|
||||
assert.equal(path.relative(root, trail[0]), 'resources/pushd');
|
||||
assert.equal(trail[1], root);
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
trail = shell.pushd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(trail.length, 2);
|
||||
assert.equal(trail[0], root);
|
||||
assert.equal(path.relative(root, trail[1]), 'resources/pushd');
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
// Push without arguments should swap top two directories when stack length is > 2
|
||||
trail = shell.pushd('resources/pushd/a');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(trail.length, 3);
|
||||
assert.equal(path.relative(root, trail[0]), 'resources/pushd/a');
|
||||
assert.equal(trail[1], root);
|
||||
assert.equal(path.relative(root, trail[2]), 'resources/pushd');
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
trail = shell.pushd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(trail.length, 3);
|
||||
assert.equal(trail[0], root);
|
||||
assert.equal(path.relative(root, trail[1]), 'resources/pushd/a');
|
||||
assert.equal(path.relative(root, trail[2]), 'resources/pushd');
|
||||
assert.equal(process.cwd(), trail[0]);
|
||||
|
||||
// Push without arguments invalid when stack is empty
|
||||
reset(); shell.pushd();
|
||||
assert.equal(shell.error(), 'pushd: no other directory\n');
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,28 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path');
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
var _pwd = shell.pwd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(_pwd, path.resolve('.'));
|
||||
|
||||
shell.cd('tmp');
|
||||
var _pwd = shell.pwd();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(path.basename(_pwd), 'tmp');
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,11 @@
|
|||
This is line one
|
||||
This is line two
|
||||
|
||||
This is line four
|
||||
.
|
||||
.
|
||||
More content here
|
||||
.
|
||||
.
|
||||
|
||||
This is line eleven
|
|
@ -0,0 +1,2 @@
|
|||
this is test file 1
|
||||
default state should be 0644 (rw-r--r--)
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1,2 @@
|
|||
console.log('node_script_1234');
|
||||
|
|
@ -0,0 +1 @@
|
|||
test1
|
|
@ -0,0 +1 @@
|
|||
test
|
|
@ -0,0 +1 @@
|
|||
test1
|
|
@ -0,0 +1 @@
|
|||
test2
|
|
@ -0,0 +1 @@
|
|||
test
|
|
@ -0,0 +1 @@
|
|||
test2
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
123
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
nada
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
test
|
|
@ -0,0 +1 @@
|
|||
test
|
|
@ -0,0 +1 @@
|
|||
test
|
|
@ -0,0 +1 @@
|
|||
test
|
1
node_modules/shelljs/test/resources/ls/filename(with)[chars$]^that.must+be-escaped
generated
vendored
Normal file
1
node_modules/shelljs/test/resources/ls/filename(with)[chars$]^that.must+be-escaped
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
asdf
|
|
@ -0,0 +1 @@
|
|||
meh
|
|
@ -0,0 +1 @@
|
|||
meh
|
|
@ -0,0 +1,183 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.rm();
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.rm('asdfasdf'); // file does not exist
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.rm('-f'); // no file
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.rm('-@', 'resources/file1'); // invalid option
|
||||
assert.ok(shell.error());
|
||||
assert.equal(fs.existsSync('resources/file1'), true);
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
// file does not exist, but -f specified
|
||||
shell.rm('-f', 'asdfasdf');
|
||||
assert.equal(shell.error(), null);
|
||||
|
||||
// simple rm
|
||||
shell.cp('-f', 'resources/file1', 'tmp/file1');
|
||||
assert.equal(fs.existsSync('tmp/file1'), true);
|
||||
shell.rm('tmp/file1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/file1'), false);
|
||||
|
||||
// recursive dir removal - small-caps '-r'
|
||||
shell.mkdir('-p', 'tmp/a/b/c');
|
||||
assert.equal(fs.existsSync('tmp/a/b/c'), true);
|
||||
shell.rm('-rf', 'tmp/a');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/a'), false);
|
||||
|
||||
// recursive dir removal - capital '-R'
|
||||
shell.mkdir('-p', 'tmp/a/b/c');
|
||||
assert.equal(fs.existsSync('tmp/a/b/c'), true);
|
||||
shell.rm('-Rf', 'tmp/a');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/a'), false);
|
||||
|
||||
// recursive dir removal - absolute path
|
||||
shell.mkdir('-p', 'tmp/a/b/c');
|
||||
assert.equal(fs.existsSync('tmp/a/b/c'), true);
|
||||
shell.rm('-Rf', path.resolve('./tmp/a'));
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync('tmp/a'), false);
|
||||
|
||||
// wildcard
|
||||
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);
|
||||
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
|
||||
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);
|
||||
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
|
||||
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);
|
||||
shell.rm('-rf', 'tmp/*', 'tmp/.*');
|
||||
assert.equal(shell.error(), null);
|
||||
var contents = fs.readdirSync('tmp');
|
||||
assert.equal(contents.length, 0);
|
||||
|
||||
// recursive dir removal - array-syntax
|
||||
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);
|
||||
shell.rm('-rf', ['tmp/*', 'tmp/.*']);
|
||||
assert.equal(shell.error(), null);
|
||||
var contents = fs.readdirSync('tmp');
|
||||
assert.equal(contents.length, 0);
|
||||
|
||||
// removal of a read-only file (unforced)
|
||||
shell.mkdir('-p', 'tmp/readonly');
|
||||
'asdf'.to('tmp/readonly/file1');
|
||||
fs.chmodSync('tmp/readonly/file1', '0444'); // -r--r--r--
|
||||
shell.rm('tmp/readonly/file1');
|
||||
assert.equal(fs.existsSync('tmp/readonly/file1'), true); // bash's rm always asks before removing read-only files
|
||||
// here we just assume "no"
|
||||
|
||||
// removal of a read-only file (forced)
|
||||
shell.mkdir('-p', 'tmp/readonly');
|
||||
'asdf'.to('tmp/readonly/file2');
|
||||
fs.chmodSync('tmp/readonly/file2', '0444'); // -r--r--r--
|
||||
shell.rm('-f', 'tmp/readonly/file2');
|
||||
assert.equal(fs.existsSync('tmp/readonly/file2'), false);
|
||||
|
||||
// removal of a tree containing read-only files (unforced)
|
||||
shell.mkdir('-p', 'tmp/tree2');
|
||||
'asdf'.to('tmp/tree2/file1');
|
||||
'asdf'.to('tmp/tree2/file2');
|
||||
fs.chmodSync('tmp/tree2/file1', '0444'); // -r--r--r--
|
||||
shell.rm('-r', 'tmp/tree2');
|
||||
assert.equal(fs.existsSync('tmp/tree2/file1'), true);
|
||||
assert.equal(fs.existsSync('tmp/tree2/file2'), false);
|
||||
|
||||
// removal of a tree containing read-only files (forced)
|
||||
shell.mkdir('-p', 'tmp/tree');
|
||||
'asdf'.to('tmp/tree/file1');
|
||||
'asdf'.to('tmp/tree/file2');
|
||||
fs.chmodSync('tmp/tree/file1', '0444'); // -r--r--r--
|
||||
shell.rm('-rf', 'tmp/tree');
|
||||
assert.equal(fs.existsSync('tmp/tree'), false);
|
||||
|
||||
// removal of a sub-tree containing read-only and hidden files - rm('dir/*')
|
||||
shell.mkdir('-p', 'tmp/tree3');
|
||||
shell.mkdir('-p', 'tmp/tree3/subtree');
|
||||
shell.mkdir('-p', 'tmp/tree3/.hidden');
|
||||
'asdf'.to('tmp/tree3/subtree/file');
|
||||
'asdf'.to('tmp/tree3/.hidden/file');
|
||||
'asdf'.to('tmp/tree3/file');
|
||||
fs.chmodSync('tmp/tree3/file', '0444'); // -r--r--r--
|
||||
fs.chmodSync('tmp/tree3/subtree/file', '0444'); // -r--r--r--
|
||||
fs.chmodSync('tmp/tree3/.hidden/file', '0444'); // -r--r--r--
|
||||
shell.rm('-rf', 'tmp/tree3/*', 'tmp/tree3/.*'); // erase dir contents
|
||||
assert.equal(shell.ls('tmp/tree3').length, 0);
|
||||
|
||||
// removal of a sub-tree containing read-only and hidden files - rm('dir')
|
||||
shell.mkdir('-p', 'tmp/tree4');
|
||||
shell.mkdir('-p', 'tmp/tree4/subtree');
|
||||
shell.mkdir('-p', 'tmp/tree4/.hidden');
|
||||
'asdf'.to('tmp/tree4/subtree/file');
|
||||
'asdf'.to('tmp/tree4/.hidden/file');
|
||||
'asdf'.to('tmp/tree4/file');
|
||||
fs.chmodSync('tmp/tree4/file', '0444'); // -r--r--r--
|
||||
fs.chmodSync('tmp/tree4/subtree/file', '0444'); // -r--r--r--
|
||||
fs.chmodSync('tmp/tree4/.hidden/file', '0444'); // -r--r--r--
|
||||
shell.rm('-rf', 'tmp/tree4'); // erase dir contents
|
||||
assert.equal(fs.existsSync('tmp/tree4'), false);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,58 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.sed();
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.sed(/asdf/g); // too few args
|
||||
assert.ok(shell.error());
|
||||
|
||||
shell.sed(/asdf/g, 'nada'); // too few args
|
||||
assert.ok(shell.error());
|
||||
|
||||
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
|
||||
shell.sed(/asdf/g, 'nada', '/asdfasdf'); // no such file
|
||||
assert.ok(shell.error());
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
shell.cp('-f', 'resources/file1', 'tmp/file1');
|
||||
var result = shell.sed('test1', 'hello', 'tmp/file1'); // search string
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'hello');
|
||||
|
||||
var result = shell.sed(/test1/, 'hello', 'tmp/file1'); // search regex
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'hello');
|
||||
|
||||
var result = shell.sed(/test1/, 1234, 'tmp/file1'); // numeric replacement
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, '1234');
|
||||
|
||||
var result = shell.sed('-i', /test1/, 'hello', 'tmp/file1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'hello');
|
||||
assert.equal(shell.cat('tmp/file1'), 'hello');
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,27 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
var tmp = shell.tempdir();
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync(tmp), true);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,91 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
var result = shell.test(); // no expression given
|
||||
assert.ok(shell.error());
|
||||
|
||||
var result = shell.test('asdf'); // bad expression
|
||||
assert.ok(shell.error());
|
||||
|
||||
var result = shell.test('f', 'resources/file1'); // bad expression
|
||||
assert.ok(shell.error());
|
||||
|
||||
var result = shell.test('-f'); // no file
|
||||
assert.ok(shell.error());
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
//exists
|
||||
var result = shell.test('-e', 'resources/file1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, true);//true
|
||||
|
||||
var result = shell.test('-e', 'resources/404');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, false);
|
||||
|
||||
//directory
|
||||
var result = shell.test('-d', 'resources');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, true);//true
|
||||
|
||||
var result = shell.test('-f', 'resources');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, false);
|
||||
|
||||
var result = shell.test('-L', 'resources');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, false);
|
||||
|
||||
//file
|
||||
var result = shell.test('-d', 'resources/file1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, false);
|
||||
|
||||
var result = shell.test('-f', 'resources/file1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, true);//true
|
||||
|
||||
var result = shell.test('-L', 'resources/file1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, false);
|
||||
|
||||
//link
|
||||
var result = shell.test('-d', 'resources/link');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, false);
|
||||
|
||||
var result = shell.test('-f', 'resources/link');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, true);//true
|
||||
|
||||
var result = shell.test('-L', 'resources/link');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, true);//true
|
||||
|
||||
var result = shell.test('-L', 'resources/badlink');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, true);//true
|
||||
|
||||
var result = shell.test('-L', 'resources/404');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, false);//false
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,39 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
'hello world'.to();
|
||||
assert.ok(shell.error());
|
||||
|
||||
assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check
|
||||
'hello world'.to('/asdfasdf/file');
|
||||
assert.ok(shell.error());
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
'hello world'.to('tmp/to1');
|
||||
var result = shell.cat('tmp/to1');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, 'hello world');
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,38 @@
|
|||
var shell = require('..');
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
// Node shims for < v0.7
|
||||
fs.existsSync = fs.existsSync || path.existsSync;
|
||||
|
||||
shell.config.silent = true;
|
||||
|
||||
function numLines(str) {
|
||||
return typeof str === 'string' ? str.match(/\n/g).length : 0;
|
||||
}
|
||||
|
||||
shell.rm('-rf', 'tmp');
|
||||
shell.mkdir('tmp');
|
||||
|
||||
//
|
||||
// Invalids
|
||||
//
|
||||
|
||||
shell.which();
|
||||
assert.ok(shell.error());
|
||||
|
||||
var result = shell.which('asdfasdfasdfasdfasdf'); // what are the odds...
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(result, null);
|
||||
|
||||
//
|
||||
// Valids
|
||||
//
|
||||
|
||||
var result = shell.which('node');
|
||||
assert.equal(shell.error(), null);
|
||||
assert.equal(fs.existsSync(result), true);
|
||||
|
||||
shell.exit(123);
|
|
@ -0,0 +1,4 @@
|
|||
test/
|
||||
Rakefile
|
||||
docs/
|
||||
raw/
|
|
@ -0,0 +1,5 @@
|
|||
language: node_js
|
||||
node_js:
|
||||
- 0.8
|
||||
notifications:
|
||||
email: false
|
|
@ -0,0 +1 @@
|
|||
underscorejs.org
|
|
@ -0,0 +1,9 @@
|
|||
## How to contribute to Underscore.js
|
||||
|
||||
* Before you open a ticket or send a pull request, [search](https://github.com/documentcloud/underscore/issues) for previous discussions about the same feature or issue. Add to the earlier ticket if you find one.
|
||||
|
||||
* Before sending a pull request for a feature, be sure to have [tests](http://underscorejs.org/test/).
|
||||
|
||||
* Use the same coding style as the rest of the [codebase](https://github.com/documentcloud/underscore/blob/master/underscore.js).
|
||||
|
||||
* In your pull request, do not add documentation or re-build the minified `underscore-min.js` file. We'll do those things before cutting a new release.
|
|
@ -0,0 +1,22 @@
|
|||
Copyright (c) 2009-2013 Jeremy Ashkenas, DocumentCloud
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,19 @@
|
|||
__
|
||||
/\ \ __
|
||||
__ __ ___ \_\ \ __ _ __ ____ ___ ___ _ __ __ /\_\ ____
|
||||
/\ \/\ \ /' _ `\ /'_ \ /'__`\/\ __\/ ,__\ / ___\ / __`\/\ __\/'__`\ \/\ \ /',__\
|
||||
\ \ \_\ \/\ \/\ \/\ \ \ \/\ __/\ \ \//\__, `\/\ \__//\ \ \ \ \ \//\ __/ __ \ \ \/\__, `\
|
||||
\ \____/\ \_\ \_\ \___,_\ \____\\ \_\\/\____/\ \____\ \____/\ \_\\ \____\/\_\ _\ \ \/\____/
|
||||
\/___/ \/_/\/_/\/__,_ /\/____/ \/_/ \/___/ \/____/\/___/ \/_/ \/____/\/_//\ \_\ \/___/
|
||||
\ \____/
|
||||
\/___/
|
||||
|
||||
Underscore.js is a utility-belt library for JavaScript that provides
|
||||
support for the usual functional suspects (each, map, reduce, filter...)
|
||||
without extending any core JavaScript objects.
|
||||
|
||||
For Docs, License, Tests, and pre-packed downloads, see:
|
||||
http://underscorejs.org
|
||||
|
||||
Many thanks to our contributors:
|
||||
https://github.com/documentcloud/underscore/contributors
|
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1 @@
|
|||
module.exports = require('./underscore');
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"name": "underscore",
|
||||
"description": "JavaScript's functional programming helper library.",
|
||||
"homepage": "http://underscorejs.org",
|
||||
"keywords": [
|
||||
"util",
|
||||
"functional",
|
||||
"server",
|
||||
"client",
|
||||
"browser"
|
||||
],
|
||||
"author": {
|
||||
"name": "Jeremy Ashkenas",
|
||||
"email": "jeremy@documentcloud.org"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/documentcloud/underscore.git"
|
||||
},
|
||||
"main": "underscore.js",
|
||||
"version": "1.4.4",
|
||||
"devDependencies": {
|
||||
"phantomjs": "0.2.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "phantomjs test/vendor/runner.js test/index.html?noglobals=true"
|
||||
},
|
||||
"readme": " __\n /\\ \\ __\n __ __ ___ \\_\\ \\ __ _ __ ____ ___ ___ _ __ __ /\\_\\ ____\n /\\ \\/\\ \\ /' _ `\\ /'_ \\ /'__`\\/\\ __\\/ ,__\\ / ___\\ / __`\\/\\ __\\/'__`\\ \\/\\ \\ /',__\\\n \\ \\ \\_\\ \\/\\ \\/\\ \\/\\ \\ \\ \\/\\ __/\\ \\ \\//\\__, `\\/\\ \\__//\\ \\ \\ \\ \\ \\//\\ __/ __ \\ \\ \\/\\__, `\\\n \\ \\____/\\ \\_\\ \\_\\ \\___,_\\ \\____\\\\ \\_\\\\/\\____/\\ \\____\\ \\____/\\ \\_\\\\ \\____\\/\\_\\ _\\ \\ \\/\\____/\n \\/___/ \\/_/\\/_/\\/__,_ /\\/____/ \\/_/ \\/___/ \\/____/\\/___/ \\/_/ \\/____/\\/_//\\ \\_\\ \\/___/\n \\ \\____/\n \\/___/\n\nUnderscore.js is a utility-belt library for JavaScript that provides\nsupport for the usual functional suspects (each, map, reduce, filter...)\nwithout extending any core JavaScript objects.\n\nFor Docs, License, Tests, and pre-packed downloads, see:\nhttp://underscorejs.org\n\nMany thanks to our contributors:\nhttps://github.com/documentcloud/underscore/contributors\n",
|
||||
"readmeFilename": "README.md",
|
||||
"_id": "underscore@1.4.4",
|
||||
"_from": "underscore@"
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue