* 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
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
* 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
* 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
* 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
* 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
* 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
* 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
* 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.
* 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
* 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
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
- 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
* 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
* 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
Adds tests to make sure that non-normalized paths (i.e. path/to/./dir) are
valid for a few commands, including mkdir() which previously failed when given
the -p flag.
Fixes#634
If an error exists, but has no error code, it defaults to 1 (a common code for
most Unix commands). Tests have been omitted since this is an edge case that is
difficult to reproduce.
Fixes#536
* fix: maxdepth doesn't limit total number of copies
Prevent maxdepth from limiting the total number of copies, only allow it to
limit the maximum depth
Fixes#547
* refactor: make `depth` be its own argument