prepack/scripts/test-std-in.sh
Baptiste Manson bad3ec4720 fix #1239 - Command-line based syntax errors now print location
Summary:
Hi all!

I took the path to implement a custom errorHandler, to be more aligned with the rest of the code, but it may be a mistake.

I reached that point.
```bash
echo "(){}" | yarn prepack
yarn prepack v0.27.5
$ node lib/prepack-cli.js
Unexpected token (1:1) found in stdin
Error: A fatal error occurred while prepacking.
+ (full stack trace)
error Command failed with exit code 1.
```

and when srcmapIn is given but not existing:
```bash
 echo "(){}" | yarn prepack -- --srcmapIn notExisting
yarn prepack v0.27.5
$ node lib/prepack-cli.js "--srcmapIn" "notExisting"
No sourcemap found at notExisting.
Unexpected token (1:1) found in stdin
+ (stack trace)
```
Finally when using files with syntax error:
```bash
yarn prepack ../notepad/test.js
yarn prepack v0.27.5
$ node lib/prepack-cli.js "../notepad/test.js"
Unexpected token (1:3) found in input file ../notepad/test.js
+ (stack trace)
```
Closes https://github.com/facebook/prepack/pull/1272

Differential Revision: D6595324

Pulled By: hermanventer

fbshipit-source-id: 6f73a15db5710585ffc9579f4487217a98f921f5
2017-12-18 13:56:26 -08:00

43 lines
1.9 KiB
Bash

# Prepacks a correct stdin input. Checks if the output execution is correct.
cat ./test/std-in/StdIn.js | node ./bin/prepack.js --out StdIn-test.js > /dev/null
node ./StdIn-test.js | grep "Hello world from std-in" > /dev/null
if [[ $? -ne 0 ]]; then
echo "Stdin test failed: cat ./test/std-in/StdIn.js | node ./bin/prepack.js --out StdIn-test.js returned an error"
exit 1
fi
rm ./StdIn-test.js
# Prepacks an empty stdin input. Checks if it exits with signal 0.
echo "" | node ./bin/prepack.js 1>/dev/null 2>&1
if [[ $? -ne 0 ]]; then
echo "Stdin test failed: echo "" | node ./bin/prepack.js --out StdIn-test.js didn't exit with signal 0"
exit 1
fi
# Prepacks an empty stdin input. Checks if the correct error message is printed.
(echo "" | node ./bin/prepack.js 2>&1 1>/dev/null ) | grep "Prepack returned empty code." > /dev/null
# grep returns 0, even though prepack returned 1
if [[ $? -ne 0 ]]; then
echo "Stdin test failed: echo "" | node ./bin/prepack.js --out StdIn-test.js didn't exit with the expected signal 1."
exit 1
fi
# Prepacks a stdin with a syntax error. Checks if it exits with signal 1.
echo "{}()" | node ./bin/prepack.js 1>/dev/null 2>&1
if [[ $? -ne 1 ]]; then
echo "Stdin test failed:echo \"{}()\" | node ./bin/prepack.js --out StdInError-test.js didn't exit with the expected signal 1."
# If the test failed, rerun and show the output
echo "{}()" | node ./bin/prepack.js
exit 1
fi
# Prepacks a stdin with a syntax error. Checks if the correct error message is printed.
(echo "{}()" | node ./bin/prepack.js 2>&1 1>/dev/null ) | grep "In stdin(1:4) FatalError PP1004" > /dev/null
# grep returns 0, even though prepack returned 1
if [[ $? -ne 0 ]]; then
echo "Stdin test failed: echo \"{}()\" | node ./bin/prepack.js didn't return the expected error message."
# If the test failed, rerun and show the output
echo "{}()" | node ./bin/prepack.js
exit 1
fi