From: GoalSmashers Date: Sun, 5 Aug 2012 13:28:17 +0000 (+0200) Subject: Added full windows support with tests. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=d385669d1d7e7898eafd201f1b2b7d26473b5997;p=clean-css.git Added full windows support with tests. --- diff --git a/bin/cleancss b/bin/cleancss index fef360f7..682f68bd 100755 --- a/bin/cleancss +++ b/bin/cleancss @@ -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 \n'); - process.exit(0); + return 0; } if (options.source) { diff --git a/test.bat b/test.bat new file mode 100644 index 00000000..0d306839 --- /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 diff --git a/test/batch-test.js b/test/batch-test.js index f8dc5eeb..525ad068 100644 --- a/test/batch-test.js +++ b/test/batch-test.js @@ -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, '') }; } } diff --git a/test/binary-test.js b/test/binary-test.js index 36530098..64b0ca06 100644 --- a/test/binary-test.js +++ b/test/binary-test.js @@ -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() {