Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ahm... Do you know about test? #1

Closed
yamadapc opened this issue Apr 11, 2016 · 1 comment
Closed

Ahm... Do you know about test? #1

yamadapc opened this issue Apr 11, 2016 · 1 comment

Comments

@yamadapc
Copy link

Sorry if this isn't relevant. This repository showed up on my GitHub newsletter.

Do you know the shell's if statement is actually just syntactic sugar for the test coreutils utility?

http://www.gnu.org/software/coreutils/manual/html_node/test-invocation.html#test-invocation

So on pretty much any shell, you can run:

$ test -e asdf && echo "asdf exists"
$ test -d adsf && echo "adsf exists and is a directory"

And more... You can test for a file's length, it's permissions, it's type, if it's executable, if it's a socket, if it's newer than another file... You can make assertions over strings etc.

This specific case of test can be rewritten as:

$ if [ -e asdf ]; then echo "asdf exists"; fi
$ if [ -d adsf ]; then echo "asdf exists and is a directory"; fi

This is also how loops work in the shell, as far as I recall. Heh... A loop that spawns a Node.js runtime on every iteration would be pretty bad.


I just think it's a little weird for this kind of stuff to exist and even require another module to work...

This would be a pretty good example of going to far with modules, don't you think?

test from coreutils is an example of a useful, fast implementation of something that does 1 thing in the UNIX way... Which sort of means constructing a verb that's modular enough to be composed, but useful enough... A verb.

It seems like if this utility's approach was going to write coreutils, instead of test, there'd be:

  • path-exists
  • path-exists-and-is-directory
  • path-exists-and-is-directory-and-is-newer-than
  • path-exists-and-has-filename-equal-to
@sindresorhus
Copy link
Owner

I'm aware of test and how it works. I use it all the time. This was made for cross-platform compatibility (Windows). I'm not trying to replace Unix tools.

See: sindresorhus/path-exists#3

I'm sorry for locking this issue, but I don't have the energy to argue about the merits of small modules today. You're probably never going to agree with me anyways. I'll leave you with sindresorhus/ama#10 (comment) and sindresorhus/ama#367 (comment).

Repository owner locked and limited conversation to collaborators Apr 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants