Skip to content

Commit dd84db3

Browse files
committed
reduce complexity of test runner
1 parent 527eb0d commit dd84db3

File tree

4 files changed

+23
-93
lines changed

4 files changed

+23
-93
lines changed

Makefile

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
SHELL := /bin/bash
22

3-
user=postgres
4-
password=1234
5-
host=localhost
6-
port=5432
7-
database=postgres
8-
verbose=false
3+
connectionString=pg://postgres:5432@localhost/postgres
94

10-
params := -u $(user) --password $(password) -p $(port) -d $(database) -h $(host) --verbose $(verbose)
5+
params := $(connectionString)
116

127
node-command := xargs -n 1 -I file node file $(params)
138

@@ -29,17 +24,17 @@ test-connection:
2924
@node script/test-connection.js $(params)
3025

3126
test-connection-binary:
32-
@node script/test-connection.js $(params) --binary true
27+
@node script/test-connection.js $(params) binary
3328

3429
test-native: build/default/binding.node
3530
@echo "***Testing native bindings***"
3631
@find test/native -name "*-tests.js" | $(node-command)
37-
@find test/integration -name "*-tests.js" | $(node-command) --native true
32+
@find test/integration -name "*-tests.js" | $(node-command) native
3833

3934
test-integration: test-connection
4035
@echo "***Testing Pure Javascript***"
4136
@find test/integration -name "*-tests.js" | $(node-command)
4237

4338
test-binary: test-connection-binary
4439
@echo "***Testing Pure Javascript (binary)***"
45-
@find test/integration -name "*-tests.js" | $(node-command) --binary true
40+
@find test/integration -name "*-tests.js" | $(node-command) binary

lib/utils.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@ module.exports = {
9696
//only exported here to make testing of this method possible
9797
//since it contains quite a bit of logic and testing for
9898
//each connection scenario in an integration test is impractical
99-
buildLibpqConnectionString: getLibpgConString
99+
buildLibpqConnectionString: getLibpgConString,
100+
parseConnectionString: parseConnectionString
100101
}

test/cli.js

+7-47
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,16 @@
1-
var config = {
2-
port: 5432,
3-
host: 'localhost',
4-
user: 'postgres',
5-
database: 'postgres',
6-
password: '',
7-
test: 'unit'
8-
};
1+
var config = require(__dirname + '/../lib/utils').parseConnectionString(process.argv[2])
92

10-
var args = process.argv;
11-
for(var i = 0; i < args.length; i++) {
12-
switch(args[i].toLowerCase()) {
13-
case '-u':
14-
case '--user':
15-
config.user = args[++i];
3+
for(var i = 0; i < process.argv.length; i++) {
4+
switch(process.argv[i].toLowerCase()) {
5+
case 'native':
6+
config.native = true;
167
break;
17-
case '--password':
18-
config.password = args[++i];
8+
case 'binary':
9+
config.binary = true;
1910
break;
20-
case '--verbose':
21-
config.verbose = (args[++i] == "true");
22-
break;
23-
case '-d':
24-
case '--database':
25-
config.database = args[++i];
26-
break;
27-
case '-p':
28-
case '--port':
29-
config.port = args[++i];
30-
break;
31-
case '-h':
32-
case '--host':
33-
config.host = args[++i];
34-
break;
35-
case '--down':
36-
config.down = true;
37-
break;
38-
case '-t':
39-
case '--test':
40-
config.test = args[++i];
41-
case '--native':
42-
config.native = (args[++i] == "true");
43-
case '--binary':
44-
config.binary = (args[++i] == "true");
4511
default:
4612
break;
4713
}
4814
}
4915

50-
var log = function(keys) {
51-
keys.forEach(function(key) {
52-
console.log(key + ": '" + config[key] + "'");
53-
});
54-
}
55-
5616
module.exports = config;

test/test-helper.js

+9-35
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var sys = require('util');
66
var BufferList = require(__dirname+'/buffer-list')
77

88
var Connection = require(__dirname + '/../lib/connection');
9-
var args = require(__dirname + '/cli');
109

1110
Client = require(__dirname + '/../lib').Client;
1211

@@ -143,47 +142,21 @@ assert.isNull = function(item, message) {
143142

144143
test = function(name, action) {
145144
test.testCount ++;
146-
if(args.verbose) {
147-
console.log(name);
148-
}
149145
var result = action();
150146
if(result === false) {
151-
test.ignored.push(name);
152-
if(!args.verbose) {
153-
process.stdout.write('?');
154-
}
147+
process.stdout.write('?');
155148
}else{
156-
if(!args.verbose) {
157-
process.stdout.write('.');
158-
}
149+
process.stdout.write('.');
159150
}
160151
};
161152

162153
//print out the filename
163154
process.stdout.write(require('path').basename(process.argv[1]));
164-
//print a new line since we'll be printing test names
165-
if(args.verbose) {
166-
console.log();
167-
}
168-
test.testCount = test.testCount || 0;
169-
test.ignored = test.ignored || [];
170-
test.errors = test.errors || [];
171-
172-
process.on('exit', function() {
173-
console.log('');
174-
if(test.ignored.length || test.errors.length) {
175-
test.ignored.forEach(function(name) {
176-
console.log("Ignored: " + name);
177-
});
178-
test.errors.forEach(function(error) {
179-
console.log("Error: " + error.name);
180-
});
181-
console.log('');
182-
}
183-
test.errors.forEach(function(error) {
184-
throw error.e;
185-
});
186-
});
155+
var args = require(__dirname + '/cli');
156+
if(args.binary) process.stdout.write(' (binary)');
157+
if(args.native) process.stdout.write(' (native)');
158+
159+
process.on('exit', console.log)
187160

188161
process.on('uncaughtException', function(err) {
189162
console.error("\n %s", err.stack || err.toString())
@@ -221,10 +194,11 @@ var Sink = function(expected, timeout, callback) {
221194
}
222195
}
223196

197+
224198
module.exports = {
225-
args: args,
226199
Sink: Sink,
227200
pg: require(__dirname + '/../lib/'),
201+
args: args,
228202
config: args,
229203
sys: sys,
230204
Client: Client

0 commit comments

Comments
 (0)