Skip to content
This repository
Browse code

Add shell smoke tests for node.js cli

First steps for #209
  • Loading branch information...
commit e91a12e5515bdb878434e0bd8524a96b824f0905 1 parent a668045
Liam Newman authored April 13, 2013
4  js/bin/js-beautify.js
... ...
@@ -1,4 +1,4 @@
1 1
 #!/usr/bin/env node
2  
-var cli = require('../lib/cli'); cli.interpret();
3  
-
4 2
 
  3
+var cli = require('../lib/cli');
  4
+cli.interpret();
4  js/lib/cli.js
@@ -113,7 +113,7 @@ var interpret = exports.interpret = function (argv, slice) {
113 113
     var parsed = nopt(knownOpts, shortHands, argv, slice);
114 114
 
115 115
     if (parsed.version) {
116  
-        console.log(require(__dirname + '/../../package.json').version);
  116
+        console.log(require('../../package.json').version);
117 117
         process.exit(0);
118 118
     }
119 119
     else if (parsed.help) {
@@ -157,7 +157,7 @@ if (require.main === module) {
157 157
 function usage(err) {
158 158
     var scriptName = getScriptName();
159 159
     var msg = [
160  
-        scriptName + '@' + require(__dirname + '/../../package.json').version,
  160
+        scriptName + '@' + require('../../package.json').version,
161 161
         '',
162 162
         'CLI Options:',
163 163
         '  -f, --file       Input file(s) (Pass \'-\' for stdin)',
75  js/test/shell-smoke-test.sh
... ...
@@ -0,0 +1,75 @@
  1
+#!/bin/bash
  2
+
  3
+REL_SCRIPT_DIR="`dirname \"$0\"`"
  4
+SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`"
  5
+
  6
+test_cli_common()
  7
+{
  8
+  echo ----------------------------------------
  9
+  echo Testing common cli behavior...
  10
+  CLI_SCRIPT=${1:?missing_param}
  11
+  echo Script: $CLI_SCRIPT
  12
+
  13
+  # should find the minimal help output
  14
+  $SCRIPT_DIR/../bin/$CLI_SCRIPT.js 2>&1 | grep -q "Must define at least one file\." || {
  15
+      echo "[$CLI_SCRIPT.js] Output should be help message."
  16
+      exit 1
  17
+  }
  18
+
  19
+  $SCRIPT_DIR/../bin/$CLI_SCRIPT.js 2> /dev/null && {
  20
+      echo "[$CLI_SCRIPT.js (with no parameters)] Return code should be error."
  21
+      exit 1
  22
+  }
  23
+
  24
+  $SCRIPT_DIR/../bin/$CLI_SCRIPT.js -invalidParameter 2> /dev/null && {
  25
+      echo "[$CLI_SCRIPT.js -invalidParameter] Return code should be error."
  26
+      exit 1
  27
+  }
  28
+
  29
+  $SCRIPT_DIR/../bin/$CLI_SCRIPT.js -h > /dev/null || {
  30
+      echo "[$CLI_SCRIPT.js -h] Return code should be success."
  31
+      exit 1
  32
+  }
  33
+
  34
+  $SCRIPT_DIR/../bin/$CLI_SCRIPT.js -v > /dev/null || {
  35
+      echo "[$CLI_SCRIPT.js -v] Return code should be success."
  36
+      exit 1
  37
+  }
  38
+
  39
+}
  40
+
  41
+test_cli_js_beautify()
  42
+{
  43
+  echo ----------------------------------------
  44
+  echo Testing js-beautify cli behavior...
  45
+  $SCRIPT_DIR/../bin/js-beautify.js $SCRIPT_DIR/../bin/js-beautify.js > /dev/null || {
  46
+      echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected succeed."
  47
+      exit 1
  48
+  }
  49
+
  50
+  $SCRIPT_DIR/../bin/js-beautify.js $SCRIPT_DIR/../bin/css-beautify.js > /dev/null || {
  51
+      echo "js-beautify output for $SCRIPT_DIR/../bin/css-beautify.js was expected succeed."
  52
+      exit 1
  53
+  }
  54
+
  55
+  $SCRIPT_DIR/../bin/js-beautify.js $SCRIPT_DIR/../bin/js-beautify.js | diff $SCRIPT_DIR/../bin/js-beautify.js - || {
  56
+      echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected to be unchanged."
  57
+      exit 1
  58
+  }
  59
+
  60
+  $SCRIPT_DIR/../bin/js-beautify.js $SCRIPT_DIR/../bin/css-beautify.js | diff -q $SCRIPT_DIR/../bin/css-beautify.js - && {
  61
+      echo "js-beautify output for $SCRIPT_DIR/../bin/css-beautify.js was expected to be different."
  62
+      exit 1
  63
+  }
  64
+
  65
+}
  66
+
  67
+test_cli_common css-beautify
  68
+test_cli_common html-beautify
  69
+test_cli_common js-beautify
  70
+
  71
+test_cli_js_beautify
  72
+
  73
+echo ----------------------------------------
  74
+echo $0 - PASSED.
  75
+echo ----------------------------------------
2  package.json
@@ -15,7 +15,7 @@
15 15
 
16 16
   },
17 17
   "scripts": {
18  
-    "test": "node ./js/test/node-beautify-tests.js",
  18
+    "test": "./js/test/shell-smoke-test.sh && node ./js/test/node-beautify-tests.js",
19 19
     "update-codemirror": "npm install codemirror && rm -rf ./web/third-party/codemirror && cp -r ./node_modules/codemirror ./web/third-party && git add -Av ./web/third-party/codemirror"
20 20
   },
21 21
   "bugs": "https://github.com/einars/js-beautify/issues",

0 notes on commit e91a12e

Please sign in to comment.
Something went wrong with that request. Please try again.