Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dmajda
Created August 5, 2016 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dmajda/9f9f9196b05d71344f4ab5a893f12d92 to your computer and use it in GitHub Desktop.
Save dmajda/9f9f9196b05d71344f4ab5a893f12d92 to your computer and use it in GitHub Desktop.
sanity-check.sh
#!/bin/sh
# A script I used as a sanity check that PEG.js works with a particular version
# of Node.js.
#
# Example usage:
#
# nvm use 6.3.1 && PEGJS_DIR=../pegjs ./sanity-check.sh
#
set -e
if [ -z ${PEGJS_DIR+x} ]; then
echo 'Set PEGJS_DIR to point to a PEG.js checkout before running this script.'
exit 1
fi
rm -rf package.json node_modules arithmetics.js
# This prevents warnings during "npm install" that would otherwise clutter the
# output.
cat > package.json <<EOT
{
"private": true
}
EOT
npm install $PEGJS_DIR
node_modules/.bin/pegjs -o arithmetics.js node_modules/pegjs/examples/arithmetics.pegjs
node <<EOT
var parser = require("./arithmetics");
var result = parser.parse("5 + 6");
console.log(result === 11 ? "OK" : "FAIL");
EOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment