708 Commits

Author SHA1 Message Date
Brandon Freitag
dcead1be86 Add "encoding" option to exec (#763)
* Add 'encoding' option to shell.exec

* Add 'encoding' option to docs

* Add exec encoding option tests

* Clarify use of encoding with fs.readFileSync

* Add check for stderr buffer
2017-09-13 16:18:28 -07:00
Brandon Freitag
c7d65ac590 fix(ls): ls not following links to directories by default (#764)
* Fix ls not following links to directories by default
2017-08-23 19:06:25 -07:00
Nate Fischer
2ee83ebf74 refactor(test): update AVA and refactor tests (#760)
This updates tests for `AVA` 19.0.0+.

`AVA` 0.18.0 has a breaking change which changes the current working directory
for tests. As a result, we need to change 'resources' -> 'test/resources' (and
 similar path changes).

`AVA` 0.19.0 has a breaking change that all tests must run at least one assert.
This breaking change was already resolved by #746, so no change was necessary in
this PR.

This updates to `AVA` 0.21.0, since there are no other breaking changes.
2017-08-11 11:03:13 -07:00
Nate Fischer
38b57c8942 chore: add skipOnWin and skipOnUnix test helpers (#746)
This adds `skipOnWin` and `skipOnUnix` to help us manage our platform-dependent
tests. These methods give a nice warning message when we skip tests. We may also
consider adding warnings when running platform-dependent tests.

Part of the motivation for this is if we ever update to AVA v0.19. This version
requires at least one assertion per test case. While this could be disabled with
an AVA setting, we instead benefit from warnings for any case when we
unintentionally skip assertions.

This adds chalk as a dev dependency to enable colored messages.
2017-06-18 11:51:01 -07:00
Nate Fischer
5823ab18bb test(exec): add tests for coverage (#744)
* test(exec): add tests for coverage

No logic change.

This adds one test to cover some missing lines, and adds some `istanbul ignore`
directives.

I see 100% line coverage for `src/exec.js` when running:

```sh
$ nyc --reporter=text --reporter=lcov ava --serial test/exec.js`
```

Fixes #742

* Fix lint
2017-06-17 19:09:01 -07:00
Nate Fischer
291241811f test(head): improve coverage (#743)
This adds a test for `head()` on the right-hand side of a pipe. This also
removes the try-catch surrounding `fs.openSync()`, because it was unreachable
code. `fs.existsSync()` guarantees that the file exists, and `fs.openSync()`
only throws if the file does not exist, according to official documentation.

Fixes #671
2017-06-17 18:31:24 -07:00
Vojtech Jasny
c16fb7dac9 Remove PDF.js mention from README.md (#738)
Fixes #737.
2017-06-16 15:55:25 -07:00
Brandon Freitag
522a46dcf4 Deprecate common.getUserHome, advise using os.homedir instead (#725)
* Deprecate common.getUserHome, advise using os.homedir instead

* Remove common.getUserHome
2017-06-06 21:10:27 -07:00
Brandon Freitag
e8ec60bc2f Echo test mocks (#708)
* Add stdout/stderr test mocks

* Mock stdout/stderr during echo tests

* Fix lint issues

* Use 'use strict'

* Re-implement mocks as a prototype

* Implement mocks as a single-instance

* Remove redundant test

* Create mocked stdout/stderr.write methods once
2017-06-06 21:10:27 -07:00
Nate Fischer
c1d8fecc56 Fix broken test 2017-06-06 21:10:27 -07:00
Nate Fischer
18034486a5 Echo stdout (#677)
* Add newline to output of echo (#557)

* Add newline to output of echo

* Add test

* Throw an error if the options string does not start with '-' (#615)

* Throw an error if the options string does not start with '-'

* Add test

* Change message grammar

* Add -n option to echo

* Fix null argument issue

* Add -n tests

* Add documentation

* Add -en escaped character test

* Add function to parse options for echo

* Use parseOptions to parse echo options

* Simplify control flow

* parseOptions throws now

* Allow null to be echoed

* Prevent echo stderr on unrecognized option

* Add test to check stderr of returned value

* Use consistent variable name

* Change test message, leave TODO about console output
2017-06-06 21:10:27 -07:00
Brandon Freitag
97a8c1969a fix(grep, sed, sort, uniq): Split only on newline characters (#690)
* Split on newlines only

* Only split lines if need be

* Clarify code by making use of Array.prototype.reduce
2017-06-06 21:10:27 -07:00
Nate Fischer
f74e783890 chore: remove v0.12 and iojs support (#648)
Fixes #647
2017-06-06 21:10:27 -07:00
Brandon Freitag
5d05d27108 Safely exit by throwing an error (#649) 2017-06-06 21:10:27 -07:00
Brandon Freitag
5acb353bc5 Add newline to output of echo (#557)
* Add newline to output of echo

* Add test
2017-06-06 21:10:27 -07:00
Nate Fischer
0ad6252f2e docs(changelog): updated by Nate Fischer [ci skip] 2017-06-06 21:02:26 -07:00
Nate Fischer
38645675f1 0.7.8 v0.7.8 2017-06-06 21:01:21 -07:00
Nate Fischer
a66e338b5f docs(changelog): updated by Nate Fischer [ci skip] 2017-06-06 20:58:14 -07:00
Brandon Freitag
bbd8178cba Add node 8 to CI (#730) 2017-06-03 22:26:10 -07:00
Nate Fischer
15558cf67a fix(mkdir): improve error handling around files (#721)
* fix(mkdir): improve error handling around files

In particular, this fixes:

 - if we try to overwrite a file with a mkdir
 - if we try to create a subdirectory of a file
 - adds `continue: true` in spots where we missed it

Fixes #720

* Fixing tests on Windows
2017-05-16 00:30:11 -07:00
Nate Fischer
a2e13b62dc Properly handle directories as arguments (#713)
* fix(cat): do not cat directories

Fixes #707

* fix(head): do not let head() read directories

Also fixes a typo

* fix(sort): do not sort directories

Also fixes a typo

* fix(tail): do not let tail() read directories

Also fixes a typo

* fix(uniq): do not let uniq() read directories

We also had a test which called sort() instead of uniq(), so we never
actually tested the missing-file case. This fixes that as well.

This also throws an error for using a directory as output.

* fix(pipe): fix breakages with piped commands
2017-05-08 22:57:58 -07:00
Brandon Freitag
951ff22671 Add common.buffer (#710)
* Add common.buffer

* Fix comment
2017-05-02 23:04:56 -07:00
Brandon Freitag
92d3f3982e Fix common.expand error (#709)
* When glob.sync errors, return original array element

* Add test for cp with empty string
2017-05-02 19:54:56 -07:00
Kumar Uttpal
bbe521b57d Fix #631 throw error when overwriting recently created file (#702)
* cp: add error to not overwrite recently created files #631

* cp: add tests for errors not overwrite recently created files #631

* mv: show error when overwriting recently created file #631

* mv: add tests for error on recently created files #631

* mv: test remove unnecessary steps #631
2017-04-15 02:01:58 -07:00
Nate Fischer
d8ac4d3f02 refactor: remove unnecessary common.js imports (#703)
No change in logic.

This removes unnecessary imports of `common.js` in favor of the `shell`
package.
2017-04-15 00:51:29 -07:00
Brandon Freitag
7feabda0d6 Remove contents of symlink to dir with rm -rf (#688)
* rm -rf on a symlink to a dir deletes contents

* Fix comment typo

* Clarify comments

* Pass symlink directly to rmdirSync

* Skip rm -rf symlink test on windows
2017-04-15 00:49:10 -07:00
Brandon Freitag
e12da9d888 Refactor: Use process.platform across codebase (#689)
* Use process.platform across codebase

* Use process.platform in tests
2017-04-14 23:04:21 -07:00
Christian Zommerfelds
80d590ec05 Small clarification of verbose flag (#691)
* small clarification of verbose flag

* nfischer's documentation suggestion

* verbose flag documentation in source file
2017-03-30 20:30:30 -07:00
Nate Fischer
b9201eba0f docs(changelog): updated by Nate Fischer [ci skip] 2017-03-08 22:38:36 -08:00
Nate Fischer
95638cc773 0.7.7 v0.7.7 2017-03-08 22:37:03 -08:00
Nate Fischer
54c1befe94 refactor(parseOptions): better handle errors (#674)
* refactor(parseOptions): better handle errors

For the case where `parseOptions()` is passed a string that does not
start with a hyphen, we should reject this string instead of returning
the same value. This has no change on any other test cases, and should
not affect any commands since we are careful about what input we pass to
`parseOptions()`

This also adjust how we were handling error cases in the function. We
were previously using two different calls to `common.error()`, one for
if `errorOptions` is passed, and one without. This hurts readability,
because it reads like "if we have errorOptions, then this is an error,
and if we don't then it's also an error," instead of the more
appropriate, "we reached an error case and should use errorOptions if
it's available, otherwise we should signal an error without using it."

We do not need to use `errorOptions` for the added call to `error()`,
since this is an error which indicates misuse, and should not be
recoverable.

This adds a test case as well, for a line which was not previously
covered in our tests.

Partial fix for #671

* Refactor parseOptions()

This validates input at the top of `parseOptions()` for type
correctness. This changes `typeof x === 'object'` to `x instanceOf
Object` to improve robustness. Now we can safely use `errorOptions`
knowing that if it has a truthy value, it will be an object, otherwise
we should use defaults instead.

The new tests ensure that we have 100% unit test coverage for this
function.

* Use exceptions, not common.error()s, for internal misuse

* Add common.isObject() helper function

The `isObject()` helper is used throughout common.js to reliably test if
variables are JavaScript objects.
2017-03-08 19:30:56 -08:00
Brandon Freitag
7949759463 Add support for removing fifos (#687)
* Add support for removing fifos in rm

* Add test for removing fifo

* Add mkfifo util for testing

* Use ES5 syntax in utils
2017-03-08 07:33:41 -08:00
Brandon Freitag
5b5a28d2de Fix cp overwriting identical files (#679)
* Implement fix for cp with identical files

* Implement tests for cp with identical files

* Change error message

* Use common.error immediately if the file is identical

* Add test for copying to exact same path
2017-03-07 22:18:43 -08:00
Nate Fischer
b6b2cd84ef fix: convert error output to be consistent cross-platform (#684)
* fix: convert error output to be consistent cross-platform

The error output produced by `shell.error()` or `result.stderr` should
not be inconsistent between platforms. This ensures that path separators
are always printed by ShellJS as `/` instead of as `\` on Windows. This
should allow scripts using ShellJS to be more consistent cross-platform.

We were not previously relying on error output to always be consistent--
only checking its truthiness. Since this was not part of our tested API,
it should be reasonable to change this and release in a patch.

Fixes #681

* Fix broken pushd test case

* Fix TODO in a test case
2017-03-06 00:54:26 -08:00
Nate Fischer
fb09c6aab8 chore: add codecov script to appveyor CI (#686)
Invoke codecov on appveyor builds too, so that we can get coverage for
Windows-specific lines of code.

Partial fix for #671
2017-03-05 10:25:44 -08:00
Nate Fischer
7a94b1bbba Refactor tests to improve readability (#685)
No change in production logic.
2017-03-05 10:24:09 -08:00
Nate Fischer
35016ce1e7 test: add misc. tests to improve coverage (#673)
No change in production logic.

This adds missing tests to improve test coverage. This does not change
ShellJS behavior at all--all test cases are testing already-working
functionality.

One test case has been renamed for clarity.

For the "omit directory if missing recursive flag" case, we were
actually already testing that in another case, but we were testing
multiple things in that test case. It's better to test this one error
condition explicitly in its own case.

When adding real tests for `parseOptions()`, we need to explicitly clear
`common.state.error` because we're testing an internal function, not a
wrapped command.

Partial fix for #671
2017-03-05 02:28:47 -08:00
Nate Fischer
346fca4cb6 test: don't count hard-to-test lines for coverage (#672)
No change in logic.

Add `/* istanbul ignore next */` lines for hard-to-test lines so that
they don't count against us during code coverage.

I've also adjusted comments that I found confusing, and changed some
formatting.

Partial fix for #671
2017-03-04 17:54:43 -08:00
Nate Fischer
eb5230a53c chore: add codecov (#682)
* chore: add codecov

Add codecov to ShellJS

Partial fix for #671

* Add codecov badge to README
2017-03-04 17:53:37 -08:00
Nate Fischer
5318fdc43a docs: miscellaneous README changes (#661)
- Add @freitagbr to the bottom of the README
 - Remove docs about shjs (it's not well supported)
 - Remove docs about coffeescript (we don't do anything special for
   coffeescript anyway)
 - Modify the section about shelljs/global, since we strongly recommend
   avoiding this now
 - Rewrite the code example to use `require('shelljs')` instead of
   shelljs/global
 - Mention ESLint next to JSHint
 - Reformat sections with long lines to be 80 columns
2017-03-04 01:07:23 -08:00
Nate Fischer
3cd4470be3 refactor: reduce repeated code in which() (#659)
Use path.delimiter instead of explicit conditional. Try to reuse
repeated code blocks.

Fixes #656
2017-03-04 00:14:20 -08:00
Fran Dios
172d0f1543 Modified glob pattern. Fixes #666 (#676) 2017-02-28 17:32:02 -08:00
Nate Fischer
2d0428b1c9 Switch commands.json -> commands.js (#668)
WebPack has issues with importing JSON directly and using JavaScript
methods on it. For this reason, using the `.forEach()` method on the
imported JSON array caused a method-not-found error.

Instead, we can make this a real JavaScript array by keeping it in a
JavaScript file and exporting it as a field.

It should be noted that exporting it as `exports = [...]` does not work,
because Node won't actually interpret it as a JavaScript array (with
the required methods). So instead we can export it as
`exports.list = [...]` and access the `list` field to get the real
JavaScript array of command names.

Fixes #667
2017-02-28 01:34:51 -08:00
Fran Dios
df06ac4a8a ls -L (follow symlinks) (#665)
* feat: -L (follow symlinks) option for ls

* test: ls -L option

* docs: Add ls -L option to readme

* fix: ls -L ternary operator

* Revert "test: ls -L option"

This reverts commit dbb057ac087b23aa2c1358018d3c832dd546c5f2.

* test: ls -L option

* test: Remove duplicate test
2017-02-27 20:53:32 -08:00
Nate Fischer
006b8c2460 docs: clean up RELEASE.md (#662)
Miscellaneous changes.
2017-02-27 13:23:30 -08:00
George Kalpakas
434ed592de docs(chmod): document options argument (#663) 2017-02-20 15:45:46 -08:00
Faheel Ahmad
fdcc789882 Fix typo (#660)
battled-tested -> battle-tested
2017-02-11 00:17:46 -08:00
Stanislav Termosa
8dd2488ec5 feature: add -a option for which command (#655)
* feature: add -a option for which command

* chore(test): test which -a with unexisting name

* chore(test): check which -a has same result as regular one

* chord(test): fix errors mentioned by eslint
2017-02-10 10:32:22 -08:00
Brandon Freitag
055156f7f5 Fix find ENOENT (#654)
* Add find: nonexistant path test

* Catch statSync errors, return shell error
2017-02-02 15:21:58 -08:00
Nate Fischer
84ffb386eb chore(lint): Enforce a trailing comma for multi-line (#646) 2017-01-16 12:45:14 -08:00