Skip to content

Commit

Permalink
Add initial python shell test
Browse files Browse the repository at this point in the history
More of #209
  • Loading branch information
bitwiseman committed Apr 15, 2013
1 parent 9355d6a commit 99ac772
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/jsbeautifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,7 @@ def main():
return usage()

if not file:
print("Must define at least one file.")
return usage()
else:
if outfile == 'stdout':
Expand Down
80 changes: 80 additions & 0 deletions python/jsbeautifier/tests/shell-smoke-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

REL_SCRIPT_DIR="`dirname \"$0\"`"
SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`"

test_cli_common()
{
echo ----------------------------------------
echo Testing common cli behavior...
CLI_SCRIPT_NAME=${1:?missing_param}
CLI_SCRIPT=$SCRIPT_DIR/../../$CLI_SCRIPT_NAME
echo Script: $CLI_SCRIPT

# should find the minimal help output
$CLI_SCRIPT 2>&1 | grep -q "Must define at least one file\." || {
echo "[$CLI_SCRIPT_NAME] Output should be help message."
exit 1
}

# Not working yet for python
# $CLI_SCRIPT 2> /dev/null && {
# echo "[$CLI_SCRIPT_NAME (with no parameters)] Return code should be error."
# exit 1
# }

# Not working yet for python
# $CLI_SCRIPT -invalidParameter 2> /dev/null && {
# echo "[$CLI_SCRIPT_NAME -invalidParameter] Return code should be error."
# exit 1
# }

$CLI_SCRIPT -h > /dev/null || {
echo "[$CLI_SCRIPT_NAME -h] Return code should be success."
exit 1
}

$CLI_SCRIPT -v > /dev/null || {
echo "[$CLI_SCRIPT_NAME -v] Return code should be success."
exit 1
}

}

test_cli_js_beautify()
{
echo ----------------------------------------
echo Testing js-beautify cli behavior...
CLI_SCRIPT=$SCRIPT_DIR/../../js-beautify

$CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js > /dev/null || {
echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected succeed."
exit 1
}

$CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/css-beautify.js > /dev/null || {
echo "js-beautify output for $SCRIPT_DIR/../bin/css-beautify.js was expected succeed."
exit 1
}

$CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js | diff $SCRIPT_DIR/../../../js/bin/js-beautify.js - || {
echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected to be unchanged."
exit 1
}

$CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/css-beautify.js | diff -q $SCRIPT_DIR/../../../js/bin/css-beautify.js - && {
echo "js-beautify output for $SCRIPT_DIR/../bin/css-beautify.js was expected to be different."
exit 1
}

}

#test_cli_common css-beautify
#test_cli_common html-beautify
test_cli_common js-beautify

test_cli_js_beautify

echo ----------------------------------------
echo $0 - PASSED.
echo ----------------------------------------

0 comments on commit 99ac772

Please sign in to comment.