diff --git a/Makefile b/Makefile index 0a3bd679..ba19336a 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,8 @@ SHELL := /bin/bash -user=postgres -password=1234 -host=localhost -port=5432 -database=postgres -verbose=false +connectionString=pg://postgres:5432@localhost/postgres -params := -u $(user) --password $(password) -p $(port) -d $(database) -h $(host) --verbose $(verbose) +params := $(connectionString) node-command := xargs -n 1 -I file node file $(params) @@ -29,12 +24,12 @@ test-connection: @node script/test-connection.js $(params) test-connection-binary: - @node script/test-connection.js $(params) --binary true + @node script/test-connection.js $(params) binary test-native: build/default/binding.node @echo "***Testing native bindings***" @find test/native -name "*-tests.js" | $(node-command) - @find test/integration -name "*-tests.js" | $(node-command) --native true + @find test/integration -name "*-tests.js" | $(node-command) native test-integration: test-connection @echo "***Testing Pure Javascript***" @@ -42,4 +37,4 @@ test-integration: test-connection test-binary: test-connection-binary @echo "***Testing Pure Javascript (binary)***" - @find test/integration -name "*-tests.js" | $(node-command) --binary true + @find test/integration -name "*-tests.js" | $(node-command) binary diff --git a/lib/utils.js b/lib/utils.js index e52df7b2..0b98e996 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -96,5 +96,6 @@ module.exports = { //only exported here to make testing of this method possible //since it contains quite a bit of logic and testing for //each connection scenario in an integration test is impractical - buildLibpqConnectionString: getLibpgConString + buildLibpqConnectionString: getLibpgConString, + parseConnectionString: parseConnectionString } diff --git a/test/cli.js b/test/cli.js index 04f58321..c35df8ef 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,56 +1,16 @@ -var config = { - port: 5432, - host: 'localhost', - user: 'postgres', - database: 'postgres', - password: '', - test: 'unit' -}; +var config = require(__dirname + '/../lib/utils').parseConnectionString(process.argv[2]) -var args = process.argv; -for(var i = 0; i < args.length; i++) { - switch(args[i].toLowerCase()) { - case '-u': - case '--user': - config.user = args[++i]; +for(var i = 0; i < process.argv.length; i++) { + switch(process.argv[i].toLowerCase()) { + case 'native': + config.native = true; break; - case '--password': - config.password = args[++i]; + case 'binary': + config.binary = true; break; - case '--verbose': - config.verbose = (args[++i] == "true"); - break; - case '-d': - case '--database': - config.database = args[++i]; - break; - case '-p': - case '--port': - config.port = args[++i]; - break; - case '-h': - case '--host': - config.host = args[++i]; - break; - case '--down': - config.down = true; - break; - case '-t': - case '--test': - config.test = args[++i]; - case '--native': - config.native = (args[++i] == "true"); - case '--binary': - config.binary = (args[++i] == "true"); default: break; } } -var log = function(keys) { - keys.forEach(function(key) { - console.log(key + ": '" + config[key] + "'"); - }); -} - module.exports = config; diff --git a/test/test-helper.js b/test/test-helper.js index 55a0a5c5..6917ea8c 100644 --- a/test/test-helper.js +++ b/test/test-helper.js @@ -6,7 +6,6 @@ var sys = require('util'); var BufferList = require(__dirname+'/buffer-list') var Connection = require(__dirname + '/../lib/connection'); -var args = require(__dirname + '/cli'); Client = require(__dirname + '/../lib').Client; @@ -143,47 +142,21 @@ assert.isNull = function(item, message) { test = function(name, action) { test.testCount ++; - if(args.verbose) { - console.log(name); - } var result = action(); if(result === false) { - test.ignored.push(name); - if(!args.verbose) { - process.stdout.write('?'); - } + process.stdout.write('?'); }else{ - if(!args.verbose) { - process.stdout.write('.'); - } + process.stdout.write('.'); } }; //print out the filename process.stdout.write(require('path').basename(process.argv[1])); -//print a new line since we'll be printing test names -if(args.verbose) { - console.log(); -} -test.testCount = test.testCount || 0; -test.ignored = test.ignored || []; -test.errors = test.errors || []; +var args = require(__dirname + '/cli'); +if(args.binary) process.stdout.write(' (binary)'); +if(args.native) process.stdout.write(' (native)'); -process.on('exit', function() { - console.log(''); - if(test.ignored.length || test.errors.length) { - test.ignored.forEach(function(name) { - console.log("Ignored: " + name); - }); - test.errors.forEach(function(error) { - console.log("Error: " + error.name); - }); - console.log(''); - } - test.errors.forEach(function(error) { - throw error.e; - }); -}); +process.on('exit', console.log) process.on('uncaughtException', function(err) { console.error("\n %s", err.stack || err.toString()) @@ -221,10 +194,11 @@ var Sink = function(expected, timeout, callback) { } } + module.exports = { - args: args, Sink: Sink, pg: require(__dirname + '/../lib/'), + args: args, config: args, sys: sys, Client: Client