/usr/share/doc/node-clean-css/test/binary-test.js is in node-clean-css 1.0.12-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | var vows = require('vows'),
assert = require('assert'),
exec = require('child_process').exec,
fs = require('fs');
var isWindows = process.platform == 'win32';
var lineBreak = isWindows ? /\r\n/g : /\n/g;
var binaryContext = function(options, context) {
if (isWindows)
return {};
context.topic = function() {
// We add __DIRECT__=1 to force binary into 'non-piped' mode
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);
};
return context;
};
exports.commandsSuite = vows.describe('binary commands').addBatch({
'no options': binaryContext('', {
'should output help': function(stdout) {
assert.equal(/Usage:/.test(stdout), true);
}
}),
'help': binaryContext('-h', {
'should output help': function(error, stdout) {
assert.equal(/Usage:/.test(stdout), true);
},
'should output one file example': function(error, stdout) {
assert.equal(stdout.indexOf('cleancss -o one-min.css one.css') > -1, true);
},
'should output multiple files example': function(error, stdout) {
assert.equal(stdout.indexOf('cat one.css two.css three.css | cleancss -o merged-and-minified.css') > -1, true);
},
'should output gzipping multiple files example': function(error, stdout) {
assert.equal(stdout.indexOf('cat one.css two.css three.css | cleancss | gzip -9 -c > merged-minified-and-gzipped.css.gz') > -1, true);
}
}),
'version': binaryContext('-v', {
'should output help': function(error, stdout) {
var version = JSON.parse(fs.readFileSync('./package.json')).version;
assert.equal(stdout, version + '\n');
}
}),
'stdin': pipedContext('a{color: #f00}', '', {
'should output data': function(error, stdout) {
assert.equal(stdout, 'a{color:red}');
}
}),
'no empty by default': pipedContext('a{}', '', {
'should preserve content': function(error, stdout) {
assert.equal(stdout, 'a{}');
}
}),
'strip all but first comment': pipedContext('/*!1st*//*! 2nd */a{}', '--s1', {
'should keep the 2nd comment': function(error, stdout) {
assert.equal(stdout, '/*!1st*/a{}');
}
}),
'strip all comments': pipedContext('/*!1st*//*! 2nd */a{}', '--s0', {
'should keep the 2nd comment': function(error, stdout) {
assert.equal(stdout, 'a{}');
}
}),
'empty': pipedContext('a{}', '-e', {
'should preserve content': function(error, stdout) {
assert.equal(stdout, '');
}
}),
'no relative to path': binaryContext('./test/data/partials-absolute/base.css', {
'should not be able to resolve it fully': function(error, stdout) {
assert.equal(stdout, '.sub{padding:0}.base{margin:0}');
}
}),
'relative to path': binaryContext('-r ./test/data ./test/data/partials-absolute/base.css', {
'should be able to resolve it': function(error, stdout) {
assert.equal(stdout, '.base2{border-width:0}.sub{padding:0}.base{margin:0}');
}
}),
'from source': binaryContext('./test/data/reset.css', {
'should minimize': function(error, stdout) {
var minimized = fs.readFileSync('./test/data/reset-min.css', 'utf-8').replace(lineBreak, '');
assert.equal(stdout, minimized);
}
}),
'to file': binaryContext('-o ./reset-min.css ./test/data/reset.css', {
'should give no output': function(error, stdout) {
assert.equal(stdout, '');
},
'should minimize': function() {
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() {
if (isWindows)
exec('del /q /f ./reset-min.css');
else
exec('rm ./reset-min.css');
}
}),
'disable @import': binaryContext('-s ./test/data/imports.css', {
'should disable the import processing': function(error, stdout) {
assert.equal(stdout, "@import url(./partials/one.css);@import url(./partials/two.css);.imports{color:#000}");
}
})
});
|