Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cloudkick/whiskey
Browse files Browse the repository at this point in the history
Conflicts:
	lib/constants.js
  • Loading branch information
Kami committed Jun 14, 2011
2 parents 298f493 + 6f6ca1f commit fd85704
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 42 deletions.
10 changes: 10 additions & 0 deletions CHANGES.md
@@ -1,6 +1,16 @@
Changes
=======

* in development - v0.4.0:
* Fix a bug in assert.response
* Fix a bug with exiting prematurely in the option parser on Mac OS X
* Default Whiskey communication socket path now contains a random component
* `--print-stdout` and `--print-stderr` options have been replaced with the
`--quiet` option
* The tests now run in sequential mode by default
* Fix a bug in scope leak reporting
* Fix a bug with assert.eql

* 31.05.2011 - v0.3.4:
* When reporting the test results print a whole path to the test file
instead of just a file name
Expand Down
22 changes: 22 additions & 0 deletions assets/Makefile.magic
@@ -0,0 +1,22 @@
TEST_FILES={{ test_files }}

test:
whiskey --tests "${TEST_FILES}"

test-fast:
whiskey --tests "${TEST_FILES}" --failfast

tap:
whiskey --tests "${TEST_FILES}" --test-reporter tap

coverage:
whiskey --tests "${TEST_FILES}" --coverage --coverage-reporter html \
--coverage-dir coverage_html

cov:
make coverage

leaks:
whiskey --tests "${TEST_FILES}" --scope-leaks

.PHONY: test tap coverage cov leaks
2 changes: 2 additions & 0 deletions bin/whiskey
Expand Up @@ -22,6 +22,7 @@ require.paths.unshift(path.join(__dirname, '../'));
var cwd = process.cwd();
var argv = process.argv;
var whiskey = require('index');
var run = require('lib/run');
var argvLen = argv.length;

if (argvLen >= 3) {
Expand All @@ -34,5 +35,6 @@ whiskey.run(cwd, argv);

process.on('uncaughtException', function(err) {
console.log(err.message);
run.exitCode = 1;
process.exit(1);
});
65 changes: 65 additions & 0 deletions example/test-custom-assert-methods.js
@@ -0,0 +1,65 @@
var http = require('http');

var async = require('async');

exports['test_assert.response'] = function(test, assert) {
var server = http.createServer(function (req, res) {
if (req.method === 'GET') {
res.writeHead(200, {'Content-Type': 'text/plain'});
}
else {
res.writeHead(404, {'Content-Type': 'text/plain'});
}

res.end('hello world');
});

async.series([
function testGet(callback) {
var req = {
'url': '/test',
'method': 'get'
};

assert.response(server, req, function(res) {
assert.equal(res.statusCode, 200);
assert.equal(res.body, 'hello world');
callback();
});
},

function testPost(callback) {
var req = {
'url': '/test',
'method': 'post'
};

assert.response(server, req, function(res) {
assert.equal(res.statusCode, 404);
assert.equal(res.body, 'hello world');
callback();
});
}
],

function(err) {
assert.ifError(err);
test.finish();
});
};

exports['test_other_custom_asserts_functions'] = function(test, assert) {
assert.equal(assert.eql, assert.deepEqual);
assert.isNull(null);
assert.isNotNull(1);
assert.isNotNull(false);
assert.isNotNull(0);
assert.isNotNull(-1);
assert.isDefined(1);
assert.type('a', 'string');
assert.type(function() {}, 'function');
assert.includes([1,2,3], 2);
assert.length([1,2,3], 3);

test.finish();
};
4 changes: 2 additions & 2 deletions example/test-stdout-and-stderr-is-captured-on-timeout.js
Expand Up @@ -7,7 +7,7 @@ var sprintf = require('sprintf').sprintf;

var cwd = process.cwd();

exec(sprintf('%s/bin/whiskey --tests %s/example/test-print-stdout-stderr-timeout.js --timeout 1000 --print-stdout --print-stderr', cwd, cwd),
exec(sprintf('%s/bin/whiskey --tests %s/example/test-print-stdout-stderr-timeout.js --timeout 1000', cwd, cwd),
function(err, stdout, stderr) {
try {
assert.match(stdout, /this is stdout 1/);
Expand All @@ -20,4 +20,4 @@ exec(sprintf('%s/bin/whiskey --tests %s/example/test-print-stdout-stderr-timeout
}

process.exit(0);
});
});
2 changes: 1 addition & 1 deletion example/test-succeeded-tests-are-reported-on-timeout.js
Expand Up @@ -7,7 +7,7 @@ var sprintf = require('sprintf').sprintf;

var cwd = process.cwd();

exec(sprintf('%s/bin/whiskey --tests %s/example/test-timeout.js --timeout 1000 --print-stdout --print-stderr', cwd, cwd),
exec(sprintf('%s/bin/whiskey --tests %s/example/test-timeout.js --timeout 1000', cwd, cwd),
function(err, stdout, stderr) {
try {
assert.match(stdout, /test_success_1/);
Expand Down
46 changes: 31 additions & 15 deletions lib/assert.js
Expand Up @@ -24,6 +24,9 @@
*/

var util = require('util');
var url = require('url');
var http = require('http');
var https = require('https');

var port = parseInt((Math.random() * (65500 - 2000) + 2000), 10);

Expand Down Expand Up @@ -59,7 +62,7 @@ var assert = {};
/*
* Alias deepEqual as eql for complex equality
*/
assert.eql = assert.deepEqual;
assert.eql = origAssert.deepEqual;

/**
* Assert that `val` is null.
Expand Down Expand Up @@ -205,7 +208,18 @@ var assert = {};
}
}

var request = client.request(method, req.url, headers);
var urlParsed = url.parse(req.url);
var reqOptions = {
'host': '127.0.0.1',
'port': server.__port,
'path': urlParsed.pathname,
'method': method,
'headers': headers
};

var reqMethod = (urlParsed.protocol === 'http:' || !urlParsed.hasOwnProperty('protocol')) ? http.request : https.request;
var request = http.request(reqOptions);

if (req.trailers) {
request.addTrailers(req.trailers);
}
Expand Down Expand Up @@ -245,9 +259,9 @@ var assert = {};
assert.equal(
response.statusCode,
status,
msg + colorize('Invalid response status code.\n'
+ ' Expected: [green]{' + status + '}\n'
+ ' Got: [red]{' + response.statusCode + '}')
msg + 'Invalid response status code.\n'
+ ' Expected: [{' + status + '}\n'
+ ' Got: {' + response.sttusCode + '}'
);
}

Expand All @@ -261,22 +275,24 @@ var assert = {};
assert.equal(
actual,
expected,
msg + colorize('Invalid response header [bold]{' + name + '}.\n'
+ ' Expected: [green]{' + expected + '}\n'
+ ' Got: [red]{' + actual + '}')
msg + 'Invalid response header [bold]{' + name + '}.\n'
+ ' Expected: {' + expected + '}\n'
+ ' Got: {' + actual + '}'
);
}
}
});

if (streamer) {
streamer(request);
return;
}

request.end();
callback(response);
});
});

if (streamer) {
streamer(request);
}
else {
request.end();
}
});
};

function merge(obj1, obj2, ignore) {
Expand Down
11 changes: 5 additions & 6 deletions lib/constants.js
Expand Up @@ -22,7 +22,7 @@ var sprintf = require('sprintf').sprintf;
*/
var DEFAULT_TEST_TIMEOUT = 15 * 1000;

var DEFAULT_CONCURRENCY = 100;
var DEFAULT_CONCURRENCY = 1;

/**
* Default reporters.
Expand All @@ -34,7 +34,7 @@ var DEFAULT_SCOPE_LEAKS_REPORTER = 'cli';
/**
* Program version.
*/
var VERSION = '0.3.4-dev';
var VERSION = '0.4.0-dev';

/**
* Path where the instrumented files are saved.
Expand Down Expand Up @@ -84,17 +84,16 @@ var OPTIONS = [
['', '--socket-path STRING', sprintf('A path to the unix socket used for communication. ' +
'Defaults to %s', DEFAULT_SOCKET_PATH)],

['', '--concurrency [NUMBER]', sprintf('Maximum number of tests in a file which will run in ' +
['', '--concurrency [NUMBER]', sprintf('Maximum number of tests in a file which will run in ' +
'parallel. Defaults to %s', DEFAULT_CONCURRENCY)],
['', '--sequential', 'Run test in a file in sequential mode. This is the same as using --concurrency 1'],

['', '--custom-assert-module STRING', 'Absolute path to a module with custom assert methods'],

['', '--no-styles', 'Don\'t use colors and styles'],

['', '--print-stdout', 'Print data which was sent to stdout'],
['', '--print-stderr', 'Print data which was sent to stderr'],
['', '--real-time', 'Print data which is sent to stdout / stderr as soon ' +
['', '--quiet', 'Don\'t print stdout and stderr'],
['', '--real-time', 'Print data which is sent to stdout / stderr as soon ' +
'as it comes in'],

['', '--test-reporter STRING', 'Rest reporter type (cli or tap)'],
Expand Down
4 changes: 3 additions & 1 deletion lib/parser.js
Expand Up @@ -20,10 +20,12 @@ var sys = require('sys');
var optparse = require('./extern/optparse/lib/optparse');

var constants = require('./constants');
var run = require('./run');

var halt = function(parser) {
parser.halt(parser);
process.exit(0);
parser._halted = true;
run.exitCode = 1;
};

var getParser = function() {
Expand Down
27 changes: 20 additions & 7 deletions lib/reporters/scope-leaks/cli.js
Expand Up @@ -24,14 +24,13 @@ var ScopeLeaksReporter = require('./base').ScopeLeaksReporter;

function CliReporter(tests, options) {
ScopeLeaksReporter.call(this, tests, options);
console.log(this._options)
}

util.inherits(CliReporter, ScopeLeaksReporter);

CliReporter.prototype.handleTestsComplete = function() {
this._reportLeakedVariables();
}
};

CliReporter.prototype._reportLeakedVariables = function() {
var testFilePath, testFile, tests, test, leakedVariables, leakedVariablesTest;
Expand All @@ -50,18 +49,32 @@ CliReporter.prototype._reportLeakedVariables = function() {
console.log(testFile);

for (test in tests) {
leakedVariables = ((tests[test] && tests[test].length > 0) ? tests[test] : ['/']);
console.log(sprintf(' %s: %s', test, leakedVariables.join(', ')));
leakedVariables = ((tests[test] && tests[test].length > 0) ? tests[test] : null);

if (leakedVariables && leakedVariables.length > 0) {
console.log(sprintf(' %s: %s', test, leakedVariables.join(', ')));
}
else {
console.log(sprintf(' %s: no leaks detected', test));
}
}
}
else {
leakedVariables = [];
for (test in tests) {
leakedVariablesTest = ((tests[test] && tests[test].length > 0) ? tests[test] : ['/']);
leakedVariables = leakedVariables.concat(leakedVariablesTest);
leakedVariablesTest = ((tests[test] && tests[test].length > 0) ? tests[test] : null);

if (leakedVariablesTest) {
leakedVariables = leakedVariables.concat(leakedVariablesTest);
}
}

console.log(sprintf(' %s: %s', testFile, leakedVariables.join(', ')));
if (leakedVariables && leakedVariables.length > 0) {
console.log(sprintf(' %s: %s', testFile, leakedVariables.join(', ')));
}
else {
console.log(sprintf(' %s: no leaks detected', testFile));
}
}
}
};
Expand Down

0 comments on commit fd85704

Please sign in to comment.