Added full windows support with tests.
authorGoalSmashers <jakub@goalsmashers.com>
Sun, 5 Aug 2012 13:28:17 +0000 (15:28 +0200)
committerGoalSmashers <jakub@goalsmashers.com>
Sun, 5 Aug 2012 13:28:17 +0000 (15:28 +0200)
bin/cleancss
test.bat [new file with mode: 0644]
test/batch-test.js
test/binary-test.js

index fef360f..682f68b 100755 (executable)
@@ -20,12 +20,12 @@ if (argv.e) cleanOptions.removeEmpty = true;
 if (argv.v) {
   var packageConfig = fs.readFileSync(path.join(path.dirname(fs.realpathSync(process.argv[1])), '../package.json'));
   util.puts(JSON.parse(packageConfig).version);
-  process.exit(0);
+  return 0;
 }
 
 if (argv.h || argv.help || (!fromStdin && argv._.length == 0)) {
   util.print('usage: cleancss [-e] -o <output-file> <input-file>\n');
-  process.exit(0);
+  return 0;
 }
 
 if (options.source) {
diff --git a/test.bat b/test.bat
new file mode 100644 (file)
index 0000000..0d30683
--- /dev/null
+++ b/test.bat
@@ -0,0 +1 @@
+node .\node_modules\vows\bin\vows test\batch-test.js test\binary-test.js test\custom-test.js test\unit-test.js
\ No newline at end of file
index f8dc5ee..525ad06 100644 (file)
@@ -4,6 +4,8 @@ var vows = require('vows'),
   assert = require('assert'),
   cleanCSS = require('../index');
 
+var lineBreak = process.platform == 'win32' ? /\r\n/g : /\n/g;
+
 var batchContexts = function() {
   var context = {};
   fs.readdirSync(path.join(__dirname, 'data')).forEach(function(filename) {
@@ -13,8 +15,8 @@ var batchContexts = function() {
     context[testName] = {
       topic: function() {
         return {
-          plain: fs.readFileSync(path.join(__dirname, 'data', testName + '.css')).toString('utf-8'),
-          minimized: fs.readFileSync(path.join(__dirname, 'data', testName + '-min.css')).toString('utf-8').replace(/\n/g, '')
+          plain: fs.readFileSync(path.join(__dirname, 'data', testName + '.css'), 'utf-8').replace(lineBreak, ''),
+          minimized: fs.readFileSync(path.join(__dirname, 'data', testName + '-min.css'), 'utf-8').replace(lineBreak, '')
         };
       }
     }
index 3653009..64b0ca0 100644 (file)
@@ -3,15 +3,24 @@ var vows = require('vows'),
   exec = require('child_process').exec,
   fs = require('fs');
 
+var isWindows = process.platform == 'win32',
+  lineBreak = isWindows ? /\r\n/g : /\n/g;
+
 var binaryContext = function(options, context) {
   context.topic = function() {
     // We add __DIRECT__=1 to switch binary into 'non-piped' mode
-    exec("__DIRECT__=1 ./bin/cleancss " + options, this.callback);
+    if (isWindows)
+      exec("set __DIRECT__=1 & node .\\bin\\cleancss " + options, this.callback);
+    else
+      exec("__DIRECT__=1 ./bin/cleancss " + options, this.callback);
   };
   return context;
 };
 
 var pipedContext = function(css, options, context) {
+  if (isWindows)
+    return {};
+
   context.topic = function() {
     exec("echo \"" + css + "\" | ./bin/cleancss " + options, this.callback);
   };
@@ -25,7 +34,7 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({
     }
   }),
   'help': binaryContext('-h', {
-    'should output help': function(error, stdout) {
+    'should output help': function(error, stdout, stderr) {
       assert.equal(/usage:/.test(stdout), true);
     }
   }),
@@ -52,7 +61,7 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({
   }),
   'from source': binaryContext('./test/data/reset.css', {
     'should minimize': function(error, stdout) {
-      var minimized = fs.readFileSync('./test/data/reset-min.css', 'utf-8').replace(/\n/g, '');
+      var minimized = fs.readFileSync('./test/data/reset-min.css', 'utf-8').replace(lineBreak, '');
       assert.equal(stdout, minimized);
     }
   }),
@@ -61,8 +70,8 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({
       assert.equal(stdout, '');
     },
     'should minimize': function(stdout) {
-      var minimized = fs.readFileSync('./test/data/reset-min.css', 'utf-8').replace(/\n/g, '');
-      var target = fs.readFileSync('./reset-min.css', 'utf-8').replace(/\n/g, '');
+      var minimized = fs.readFileSync('./test/data/reset-min.css', 'utf-8').replace(lineBreak, '');
+      var target = fs.readFileSync('./reset-min.css', 'utf-8').replace(lineBreak, '');
       assert.equal(minimized, target);
     },
     teardown: function() {