File test/plank/bin/base.js deleted (index 30ecf53..0000000) |
1 |
|
|
|
2 |
|
var assert = require( 'assert' ) |
|
3 |
|
, path = require( 'path' ) |
|
4 |
|
, cp = require( 'child_process' ) |
|
5 |
|
, copy = require( 'fs-extra' ).copy |
|
6 |
|
, fs = require( 'graceful-fs' ) |
|
7 |
|
, Printer = require( './printer' ); |
|
8 |
|
|
|
9 |
|
assert( typeof copy === 'function' ); |
|
10 |
|
|
|
11 |
|
function Base(program) { |
|
12 |
|
|
|
13 |
|
this.readSuites = function(suite, cb) { |
|
14 |
|
fs.readFile( suite, function(err, data) { |
|
15 |
|
if (err) throw err; |
|
16 |
|
cb( JSON.parse( data.toString() ).tests ); |
|
17 |
|
}); |
|
18 |
|
}; |
|
19 |
|
|
|
20 |
|
this.generate = function( o, cb ) { |
|
21 |
|
|
|
22 |
|
assert( o.hasOwnProperty( 'output' ) ); |
|
23 |
|
assert( o.hasOwnProperty( 'testDir' ) ); |
|
24 |
|
assert( o.hasOwnProperty( 'defFile' ) ); |
|
25 |
|
|
|
26 |
|
makePathIfNone(o.output, function() { |
|
27 |
|
|
|
28 |
|
var include = program.gcc ? 'plank/def/cpp11-gcc.gypi' : 'plank/def/cpp11.gypi' |
|
29 |
|
, args = [ |
|
30 |
|
o.defFile, |
|
31 |
|
'--depth=' + (program.gcc ? './' : '.'), |
|
32 |
|
'--generator-output=' + o.output, |
|
33 |
|
'--include=' + include |
|
34 |
|
]; |
|
35 |
|
|
|
36 |
|
if (program.gcc) { |
|
37 |
|
args.push( '--format=make' ); |
|
38 |
|
} |
|
39 |
|
|
|
40 |
|
console.log( args ); |
|
41 |
|
|
|
42 |
|
cp.spawn( |
|
43 |
|
'gyp', |
|
44 |
|
args, { |
|
45 |
|
stdio: 'inherit', |
|
46 |
|
cwd: o.testDir |
|
47 |
|
}) |
|
48 |
|
.on( 'close', function( code ) { |
|
49 |
|
cb( code, o.output ); |
|
50 |
|
}); |
|
51 |
|
}); |
|
52 |
|
|
|
53 |
|
function makePathIfNone( path, cb ) { |
|
54 |
|
fs.exists(path, function(exists) { |
|
55 |
|
if (exists) |
|
56 |
|
cb(); |
|
57 |
|
else |
|
58 |
|
fs.mkdir( path, [], cb ); |
|
59 |
|
}); |
|
60 |
|
} |
|
61 |
|
}; |
|
62 |
|
|
|
63 |
|
this.traverse = function( o, cb ) { |
|
64 |
|
fs.readdir( o.testDir, function( err, files ) { |
|
65 |
|
files.forEach( function( file ) { |
|
66 |
|
if (path.extname(file) == '.gyp') { |
|
67 |
|
cb( file ); |
|
68 |
|
} |
|
69 |
|
} ); |
|
70 |
|
} ); |
|
71 |
|
}; |
|
72 |
|
|
|
73 |
|
this.build = function( o, cb ) { |
|
74 |
|
|
|
75 |
|
readTargetName( o.defFile, o.testDir, function( targetName ) { |
|
76 |
|
|
|
77 |
|
var child; |
|
78 |
|
if (program.gcc) { |
|
79 |
|
child = cp.spawn( |
|
80 |
|
'make', |
|
81 |
|
[ '-j'], |
|
82 |
|
{ |
|
83 |
|
stdio: 'inherit', |
|
84 |
|
cwd: o.output |
|
85 |
|
}); |
|
86 |
|
} |
|
87 |
|
else { |
|
88 |
|
|
|
89 |
|
var args = [ |
|
90 |
|
"-project", |
|
91 |
|
path.join( o.output, targetName + '.xcodeproj' ) |
|
92 |
|
]; |
|
93 |
|
|
|
94 |
|
console.log( args ); |
|
95 |
|
|
|
96 |
|
child = cp.spawn( |
|
97 |
|
'xcodebuild', |
|
98 |
|
args, { |
|
99 |
|
cwd: o.output, |
|
100 |
|
stdio: 'inherit' |
|
101 |
|
} ); |
|
102 |
|
} |
|
103 |
|
|
|
104 |
|
child.on( 'close', function( code ) { |
|
105 |
|
o['target'] = targetName; |
|
106 |
|
o['exitCode'] = code; |
|
107 |
|
cb( o ); |
|
108 |
|
} ); |
|
109 |
|
} ); |
|
110 |
|
|
|
111 |
|
function readTargetName(defFile, testDir, cb) { |
|
112 |
|
var defPath = path.join( testDir, defFile ); |
|
113 |
|
fs.readFile( defPath, function( err, data ) { |
|
114 |
|
if (err) { |
|
115 |
|
Printer.cursor.red(); |
|
116 |
|
process.stdout.write( defFile + ': ' ); |
|
117 |
|
Printer.cursor.reset(); |
|
118 |
|
console.log( err ); |
|
119 |
|
} |
|
120 |
|
else { |
|
121 |
|
var matches = data.toString().match( /'target_name'\s*:\s*'(.*)'/ ) |
|
122 |
|
if (matches) { |
|
123 |
|
cb( matches[1] ); |
|
124 |
|
} |
|
125 |
|
} |
|
126 |
|
} ); |
|
127 |
|
} |
|
128 |
|
}; |
|
129 |
|
|
|
130 |
|
this.run = function( o, cb ) { |
|
131 |
|
var execPath; |
|
132 |
|
|
|
133 |
|
if (program.gcc) { |
|
134 |
|
o.testDir = path.join( o.testDir, 'out' ); |
|
135 |
|
execPath = path.join( o.output, 'out/Test', o.target ); |
|
136 |
|
} |
|
137 |
|
else |
|
138 |
|
execPath = path.join( o.output, 'Test', o.target ); |
|
139 |
|
|
|
140 |
|
cp.spawn( |
|
141 |
|
execPath, |
|
142 |
|
[ 'http://localhost:3000' ], { |
|
143 |
|
stdio: 'pipe' |
|
144 |
|
}) |
|
145 |
|
.on( 'error', function( error ) { |
|
146 |
|
console.log( error ); |
|
147 |
|
}) |
|
148 |
|
.on( 'close', function( code ) { |
|
149 |
|
cb( code ); |
|
150 |
|
//server.kill(); |
|
151 |
|
}) |
|
152 |
|
.stdout.on( 'data', function( data ) { |
|
153 |
|
Printer.cursor.blue(); |
|
154 |
|
process.stdout.write( o.defFile + ': ' ); |
|
155 |
|
Printer.cursor.reset(); |
|
156 |
|
console.log( data.toString() ); |
|
157 |
|
}); |
|
158 |
|
}; |
|
159 |
|
} |
|
160 |
|
|
|
161 |
|
module.exports = Base; |
|
File test/plank/bin/logic.js deleted (index 553e705..0000000) |
1 |
|
var assert = require( 'assert' ) |
|
2 |
|
, Promise = require( 'promise' ) |
|
3 |
|
, Printer = require( './printer' ) |
|
4 |
|
, fs = require( 'graceful-fs' ) |
|
5 |
|
, summary = ''; |
|
6 |
|
|
|
7 |
|
process.on( 'exit', function() { |
|
8 |
|
console.log( summary ); |
|
9 |
|
}); |
|
10 |
|
|
|
11 |
|
function Logic(base) { |
|
12 |
|
|
|
13 |
|
this.traverse = function(o) { |
|
14 |
|
return new Promise(function(resolve, reject) { |
|
15 |
|
try { |
|
16 |
|
fs.exists( o.testDir, function(exists) { |
|
17 |
|
if (exists) { |
|
18 |
|
resolve( o ); |
|
19 |
|
} |
|
20 |
|
else { |
|
21 |
|
Printer.cursor.red(); |
|
22 |
|
process.stdout.write( 'invalid test definition path: ' + o.testDir ); |
|
23 |
|
Printer.cursor.reset(); |
|
24 |
|
reject(); |
|
25 |
|
} |
|
26 |
|
}); |
|
27 |
|
} |
|
28 |
|
catch(e) |
|
29 |
|
{ |
|
30 |
|
Printer.printError( e ); |
|
31 |
|
summarize( e, o ); |
|
32 |
|
throw(e); |
|
33 |
|
} |
|
34 |
|
}); |
|
35 |
|
|
|
36 |
|
}; |
|
37 |
|
|
|
38 |
|
this.generate = function(o) { |
|
39 |
|
return new Promise(function(resolve, reject) { |
|
40 |
|
Printer.begin( o.defFile, 'generate' ); |
|
41 |
|
try { |
|
42 |
|
base.generate( o, function( exitCode, buildDir){ |
|
43 |
|
//o['buildDir'] = buildDir; |
|
44 |
|
o['testDir'] = o.testDir; |
|
45 |
|
if (!exitCode) { |
|
46 |
|
Printer.finishGreen( o.defFile, 'generate' ); |
|
47 |
|
resolve(o); |
|
48 |
|
} |
|
49 |
|
else { |
|
50 |
|
Printer.finishRed( o.defFile ) ; |
|
51 |
|
reject(o); |
|
52 |
|
} |
|
53 |
|
}); |
|
54 |
|
} |
|
55 |
|
catch( e ) |
|
56 |
|
{ |
|
57 |
|
Printer.printError( e ); |
|
58 |
|
summarize( e, o ); |
|
59 |
|
throw( e ); |
|
60 |
|
} |
|
61 |
|
}); |
|
62 |
|
}; |
|
63 |
|
|
|
64 |
|
this.build = function(o) { |
|
65 |
|
return new Promise( function(resolve, reject) { |
|
66 |
|
Printer.begin( o.defFile, 'build' ); |
|
67 |
|
|
|
68 |
|
try { |
|
69 |
|
base.build( o, function( o ) { |
|
70 |
|
if (!o.exitCode) { |
|
71 |
|
Printer.finishGreen( o.defFile ); |
|
72 |
|
resolve( o ); |
|
73 |
|
} |
|
74 |
|
else { |
|
75 |
|
Printer.finishRed( o.defFile ); |
|
76 |
|
reject(o); |
|
77 |
|
} |
|
78 |
|
}); |
|
79 |
|
} |
|
80 |
|
catch(e) |
|
81 |
|
{ |
|
82 |
|
Printer.printError( e ); |
|
83 |
|
summarize( e, o ); |
|
84 |
|
throw e; |
|
85 |
|
} |
|
86 |
|
}); |
|
87 |
|
}; |
|
88 |
|
|
|
89 |
|
this.run = function(o) { |
|
90 |
|
return new Promise(function(resolve, reject) { |
|
91 |
|
Printer.begin( o.defFile, 'run' ); |
|
92 |
|
try { |
|
93 |
|
base.run( o, function(exitCode) { |
|
94 |
|
o['exitCode'] = exitCode; |
|
95 |
|
if (!exitCode) { |
|
96 |
|
Printer.finishGreen( o.defFile ); |
|
97 |
|
resolve(o); |
|
98 |
|
summarize( " passed", o ); |
|
99 |
|
} |
|
100 |
|
else { |
|
101 |
|
Printer.finishRed( o.defFile ) ; |
|
102 |
|
reject(o); |
|
103 |
|
} |
|
104 |
|
}); |
|
105 |
|
} |
|
106 |
|
catch(e) { |
|
107 |
|
Printer.printError(e); |
|
108 |
|
summarize( e, o ); |
|
109 |
|
throw e; |
|
110 |
|
} |
|
111 |
|
}); |
|
112 |
|
}; |
|
113 |
|
}; |
|
114 |
|
|
|
115 |
|
function summarize(e, o) { |
|
116 |
|
if (typeof e !== 'string') { |
|
117 |
|
e = e.toString(); |
|
118 |
|
} |
|
119 |
|
summary += o.testDir + e + '\n'; |
|
120 |
|
} |
|
121 |
|
|
|
122 |
|
module.exports = Logic; |
|
File test/plank/bin/test.js deleted (index 74d4491..0000000) |
1 |
|
#!/usr/bin/env node |
|
2 |
|
|
|
3 |
|
var assert = require( 'assert' ) |
|
4 |
|
, events = require( 'events' ) |
|
5 |
|
, path = require( 'path' ) |
|
6 |
|
, fs = require( 'graceful-fs' ) |
|
7 |
|
, program = require( 'commander' ) |
|
8 |
|
, Base = require( './base' ) |
|
9 |
|
, Logic = require( './logic' ) |
|
10 |
|
, DateTime = require( 'date-time-string' ); |
|
11 |
|
|
|
12 |
|
assert( typeof Logic !== 'undefined' ); |
|
13 |
|
|
|
14 |
|
program |
|
15 |
|
.version( '0.0.0' ) |
|
16 |
|
.option( '-p, --path [path]', 'test path' ) |
|
17 |
|
.option( '-o, --output [path]', 'build output' ) |
|
18 |
|
.option( '-g, --gcc', 'use gcc compiler' ) |
|
19 |
|
.option( '-s, --suite [path]', 'suite json' ) |
|
20 |
|
.parse( process.argv ); |
|
21 |
|
|
|
22 |
|
|
|
23 |
|
program.path = program.path ? path.join( process.cwd(), program.path ) : process.cwd(); |
|
24 |
|
|
|
25 |
|
(function() { |
|
26 |
|
var base = new Base(program) |
|
27 |
|
, logic = new Logic( base ) |
|
28 |
|
, emitter = new events.EventEmitter; |
|
29 |
|
|
|
30 |
|
emitter.on( 'run', function( o ) { |
|
31 |
|
logic.run( o ) |
|
32 |
|
.then( function() { |
|
33 |
|
log('passed'); |
|
34 |
|
emitter.emit('done'); |
|
35 |
|
}) |
|
36 |
|
.catch( function() { |
|
37 |
|
log('failed (test)'); |
|
38 |
|
emitter.emit('done'); |
|
39 |
|
}); |
|
40 |
|
}); |
|
41 |
|
|
|
42 |
|
emitter.on( 'build', function( o ) { |
|
43 |
|
logic.build( o ) |
|
44 |
|
.then( function( o ) { |
|
45 |
|
emitter.emit( 'run', o ); |
|
46 |
|
}) |
|
47 |
|
.catch( function() { |
|
48 |
|
log('failed (build)'); |
|
49 |
|
}); |
|
50 |
|
}); |
|
51 |
|
|
|
52 |
|
emitter.on( 'generate', function( o ) { |
|
53 |
|
logic.generate( o ) |
|
54 |
|
.then( function( o ) { |
|
55 |
|
emitter.emit( 'build', o ); |
|
56 |
|
}) |
|
57 |
|
.catch( function() { |
|
58 |
|
log('failed (generate)'); |
|
59 |
|
}); |
|
60 |
|
}); |
|
61 |
|
|
|
62 |
|
emitter.on( 'traverse', function( o ) { |
|
63 |
|
logic.traverse( o ).then( function( o ) { |
|
64 |
|
base.traverse( o, function(defFile) { |
|
65 |
|
o['defFile'] = defFile; |
|
66 |
|
emitter.emit( 'generate', o ); |
|
67 |
|
}); |
|
68 |
|
}); |
|
69 |
|
}); |
|
70 |
|
|
|
71 |
|
if (!program.suite) { |
|
72 |
|
program.output = path.join( program.path, program.output ? program.output : 'build' ); |
|
73 |
|
|
|
74 |
|
emitter.emit( 'traverse', { |
|
75 |
|
testDir: program.path, |
|
76 |
|
output: program.output, |
|
77 |
|
} ); |
|
78 |
|
} |
|
79 |
|
else { |
|
80 |
|
base.readSuites( program.suite, function( suites ) { |
|
81 |
|
|
|
82 |
|
var index = 0; |
|
83 |
|
emitter.on( 'done', testNextSuite ); |
|
84 |
|
testNextSuite(); |
|
85 |
|
|
|
86 |
|
function testNextSuite() { |
|
87 |
|
if (index < suites.length) { |
|
88 |
|
var suite = path.join( process.cwd(), suites[index] ); |
|
89 |
|
var output = path.join( suite, program.output ? program.output : 'build' ); |
|
90 |
|
emitter.emit( 'traverse', { |
|
91 |
|
testDir: suite, |
|
92 |
|
output: output |
|
93 |
|
} ); |
|
94 |
|
++index; |
|
95 |
|
} |
|
96 |
|
} |
|
97 |
|
|
|
98 |
|
}); |
|
99 |
|
} |
|
100 |
|
|
|
101 |
|
function log(msg) { |
|
102 |
|
var tmp = DateTime.toDateTimeString() + ": " + msg + '\n'; |
|
103 |
|
console.log( tmp ); |
|
104 |
|
fs.appendFile( 'build.log', tmp, function(err) { |
|
105 |
|
if (err) throw err; |
|
106 |
|
} ); |
|
107 |
|
} |
|
108 |
|
})(); |
|
File test/plank/def/mac-targets.gypi deleted (index ce9c6ee..0000000) |
1 |
|
{ |
|
2 |
|
'targets': [ |
|
3 |
|
{ |
|
4 |
|
'conditions': [ |
|
5 |
|
[ |
|
6 |
|
'OS=="mac"', { |
|
7 |
|
'xcode_settings': { |
|
8 |
|
'OTHER_CPLUSPLUSFLAGS' : ['-std=c++11','-stdlib=libc++'], |
|
9 |
|
'OTHER_LDFLAGS': ['-stdlib=libc++'], |
|
10 |
|
}#xcode-settings |
|
11 |
|
} #mac |
|
12 |
|
], |
|
13 |
|
[ 'OS=="ios"', { |
|
14 |
|
'mac_bundle': 1, |
|
15 |
|
'xcode_settings': { |
|
16 |
|
'SDKROOT': 'iphoneos', |
|
17 |
|
'TARGETED_DEVICE_FAMILY': '1,2', |
|
18 |
|
'CODE_SIGN_IDENTITY': 'iPhone Developer', |
|
19 |
|
'IPHONEOS_DEPLOYMENT_TARGET': '5.0', |
|
20 |
|
'ARCHS': '$(ARCHS_STANDARD_32_64_BIT)', |
|
21 |
|
'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++11', |
|
22 |
|
'CLANG_CXX_LIBRARY': 'libc++', |
|
23 |
|
'INFOPLIST_FILE': 'test-Info.plist' |
|
24 |
|
} #xcode_settings |
|
25 |
|
} #ios |
|
26 |
|
], |
|
27 |
|
] #conditions |
|
28 |
|
} |
|
29 |
|
], #targets |
|
30 |
|
} |
|
File test/plank/src/assert.cpp deleted (index 9f5b85c..0000000) |
1 |
|
#include "assert.h"
|
|
2 |
|
|
|
3 |
|
#undef SMART_ASSERT_A
|
|
4 |
|
#undef SMART_ASSERT_B
|
|
5 |
|
#undef SMART_ASSERT_OP
|
|
6 |
|
#undef SMART_ASSERT
|
|
7 |
|
|
|
8 |
|
#ifndef NDEBUG
|
|
9 |
|
|
|
10 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
11 |
|
// asserter_t
|
|
12 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
13 |
|
asserter_t::asserter_t(bool value)
|
|
14 |
|
: SMART_ASSERT_A( * this )
|
|
15 |
|
, SMART_ASSERT_B( * this )
|
|
16 |
|
, m_value( value )
|
|
17 |
|
{}
|
|
18 |
|
|
|
19 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
20 |
|
bool asserter_t::can_handle() const
|
|
21 |
|
{
|
|
22 |
|
return m_value;
|
|
23 |
|
}
|
|
24 |
|
|
|
25 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
26 |
|
const asserter_t & asserter_t::print_message(const char * file, int line, const char * function, const char * message) const
|
|
27 |
|
{
|
|
28 |
|
static const char * code_red( "\x1b[31m" );
|
|
29 |
|
static const char * code_reset( "\x1b[39;49m" );
|
|
30 |
|
|
|
31 |
|
using namespace std;
|
|
32 |
|
|
|
33 |
|
if (m_value)
|
|
34 |
|
{
|
|
35 |
|
cout << "assertion passed: " << message << endl
|
|
36 |
|
<< "file: " << file << endl
|
|
37 |
|
<< "line: " << line << endl
|
|
38 |
|
<< "function: " << function << endl;
|
|
39 |
|
}
|
|
40 |
|
else
|
|
41 |
|
{
|
|
42 |
|
cout << code_red
|
|
43 |
|
<< "assertion failed: " << message << endl
|
|
44 |
|
<< "file: " << file << endl
|
|
45 |
|
<< "line: " << line << endl
|
|
46 |
|
<< "function: " << function
|
|
47 |
|
<< code_reset << endl;
|
|
48 |
|
}
|
|
49 |
|
return * this;
|
|
50 |
|
}
|
|
51 |
|
|
|
52 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
53 |
|
const asserter_t asserter_t::make_asserter(bool value)
|
|
54 |
|
{ return asserter_t(value); }
|
|
55 |
|
|
|
56 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
57 |
|
const asserter_message_out asserter_t::make_asserter(bool value, const char * message)
|
|
58 |
|
{ return asserter_message_out(value, message); }
|
|
59 |
|
|
|
60 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
61 |
|
// asserter_message_out
|
|
62 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
63 |
|
asserter_message_out::asserter_message_out(bool value, const char * message)
|
|
64 |
|
: asserter_t(value)
|
|
65 |
|
, m_message( message )
|
|
66 |
|
{}
|
|
67 |
|
|
|
68 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
69 |
|
const asserter_t & asserter_message_out::print_message(const char * file, int line, const char * function, const char * ) const
|
|
70 |
|
{
|
|
71 |
|
return asserter_t::print_message( file, line, function, m_message );
|
|
72 |
|
}
|
|
73 |
|
|
|
74 |
|
void asserter_t::on_assert_fail()
|
|
75 |
|
{
|
|
76 |
|
memset((void*)1,0,1);
|
|
77 |
|
}
|
|
78 |
|
|
|
79 |
|
#endif
|
|
File test/plank/src/assert.h deleted (index 894d6fc..0000000) |
1 |
|
/*
|
|
2 |
|
Reference: http://www.drdobbs.com/article/print?articleId=184403745
|
|
3 |
|
*/
|
|
4 |
|
|
|
5 |
|
#ifndef ASSERT_H_9879879hkjh
|
|
6 |
|
#define ASSERT_H_9879879hkjh
|
|
7 |
|
|
|
8 |
|
#include <cstring>
|
|
9 |
|
#include <iostream>
|
|
10 |
|
#include <stdexcept>
|
|
11 |
|
|
|
12 |
|
#ifdef NDEBUG
|
|
13 |
|
|
|
14 |
|
#define ASSERT( expr ) \
|
|
15 |
|
if (false); \
|
|
16 |
|
else \
|
|
17 |
|
struct local_t \
|
|
18 |
|
{ \
|
|
19 |
|
local_t( const asserter_t & ) {} \
|
|
20 |
|
} local_obj = asserter_t::make_asserter(false)
|
|
21 |
|
|
|
22 |
|
// asserter_t
|
|
23 |
|
class asserter_t
|
|
24 |
|
{
|
|
25 |
|
public:
|
|
26 |
|
static const asserter_t make_asserter(bool) { return asserter_t(); }
|
|
27 |
|
static const asserter_t make_asserter(bool, const char *) { return asserter_t(); }
|
|
28 |
|
template<class T> const asserter_t operator()(const T &) const { return asserter_t(); }
|
|
29 |
|
};
|
|
30 |
|
|
|
31 |
|
#else
|
|
32 |
|
|
|
33 |
|
#define SMART_ASSERT_A(x) SMART_ASSERT_OP(x, B)
|
|
34 |
|
#define SMART_ASSERT_B(x) SMART_ASSERT_OP(x, A)
|
|
35 |
|
#define SMART_ASSERT_OP(x, next) SMART_ASSERT_A.print_current_val((x), #x).SMART_ASSERT_ ## next
|
|
36 |
|
|
|
37 |
|
#ifndef TARGET_TEST
|
|
38 |
|
#define TARGET_TEST 0
|
|
39 |
|
#endif
|
|
40 |
|
|
|
41 |
|
#define ASSERT( expr ) \
|
|
42 |
|
if (!TARGET_TEST && (expr)); \
|
|
43 |
|
else \
|
|
44 |
|
struct local_t \
|
|
45 |
|
{ \
|
|
46 |
|
local_t( const asserter_t & o ) \
|
|
47 |
|
{ \
|
|
48 |
|
if( !o.can_handle() ) \
|
|
49 |
|
asserter_t::on_assert_fail(); \
|
|
50 |
|
} \
|
|
51 |
|
} \
|
|
52 |
|
local_obj = \
|
|
53 |
|
asserter_t::make_asserter( expr ).print_message( __FILE__, __LINE__, __FUNCTION__, #expr ).SMART_ASSERT_A
|
|
54 |
|
|
|
55 |
|
class asserter_message_out;
|
|
56 |
|
template<class> class asserter_throw_t;
|
|
57 |
|
|
|
58 |
|
// asserter_t
|
|
59 |
|
class asserter_t
|
|
60 |
|
{
|
|
61 |
|
public:
|
|
62 |
|
virtual bool can_handle() const;
|
|
63 |
|
virtual const asserter_t & print_message(const char * file, int line, const char * function, const char * = "" ) const;
|
|
64 |
|
|
|
65 |
|
template<class U> const asserter_t & print_current_val(const U &, const char*) const;
|
|
66 |
|
|
|
67 |
|
static const asserter_t make_asserter(bool);
|
|
68 |
|
static const asserter_message_out make_asserter(bool, const char *);
|
|
69 |
|
template<class T> static const asserter_throw_t<T> make_asserter(bool, const char *);
|
|
70 |
|
|
|
71 |
|
asserter_t & SMART_ASSERT_A;
|
|
72 |
|
asserter_t & SMART_ASSERT_B;
|
|
73 |
|
|
|
74 |
|
static void on_assert_fail();
|
|
75 |
|
|
|
76 |
|
protected:
|
|
77 |
|
asserter_t(bool);
|
|
78 |
|
|
|
79 |
|
private:
|
|
80 |
|
const bool m_value;
|
|
81 |
|
};
|
|
82 |
|
|
|
83 |
|
// asserter_message_out
|
|
84 |
|
class asserter_message_out : public asserter_t
|
|
85 |
|
{
|
|
86 |
|
public:
|
|
87 |
|
asserter_message_out(bool, const char *);
|
|
88 |
|
|
|
89 |
|
virtual const asserter_t & print_message(const char * file, int line, const char * function, const char * = "" ) const;
|
|
90 |
|
|
|
91 |
|
private:
|
|
92 |
|
const char * m_message;
|
|
93 |
|
};
|
|
94 |
|
|
|
95 |
|
// asserter_throw_t
|
|
96 |
|
template<class T>
|
|
97 |
|
class asserter_throw_t : public asserter_t
|
|
98 |
|
{
|
|
99 |
|
public:
|
|
100 |
|
asserter_throw_t(bool, const char *);
|
|
101 |
|
virtual bool can_handle(const char * file, int line, const char * function) const;
|
|
102 |
|
|
|
103 |
|
private:
|
|
104 |
|
const char * m_message;
|
|
105 |
|
};
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
#include "assert.hxx"
|
|
109 |
|
|
|
110 |
|
#endif // NDEBUG
|
|
111 |
|
|
|
112 |
|
#endif // ASSERT_H_9879879hkjh |
|
File test/plank/src/assert.hxx deleted (index 0abec6c..0000000) |
1 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
2 |
|
// asserter_t
|
|
3 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
4 |
|
template<class T>
|
|
5 |
|
const asserter_throw_t<T> asserter_t::make_asserter(bool value, const char * message)
|
|
6 |
|
{ return asserter_throw_t<T>(value, message); }
|
|
7 |
|
|
|
8 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
9 |
|
template<class U> const asserter_t & asserter_t::print_current_val(const U & value, const char * message) const
|
|
10 |
|
{
|
|
11 |
|
std::cout << message << ": " << value << std::endl;
|
|
12 |
|
return * this;
|
|
13 |
|
}
|
|
14 |
|
|
|
15 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
16 |
|
// asserter_throw_t<T>
|
|
17 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
18 |
|
template<class T>
|
|
19 |
|
bool asserter_throw_t<T>::can_handle(const char * file, int line, const char * function) const
|
|
20 |
|
{
|
|
21 |
|
if( !asserter_t::can_handle( file, line, function) )
|
|
22 |
|
throw T(m_message);
|
|
23 |
|
return true;
|
|
24 |
|
}
|
|
25 |
|
|
|
26 |
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
27 |
|
template<class T>
|
|
28 |
|
asserter_throw_t<T>::asserter_throw_t(bool value, const char * message)
|
|
29 |
|
: asserter_t(value)
|
|
30 |
|
, m_message(message)
|
|
31 |
|
{}
|
|
File test/plank/test/test.js deleted (index 630bcac..0000000) |
1 |
|
#!/usr/bin/env node |
|
2 |
|
|
|
3 |
|
var assert = require( 'assert' ) |
|
4 |
|
, cp = require( 'child_process' ) |
|
5 |
|
, path = require( 'path' ) |
|
6 |
|
, Expector = require( 'expector' ).Expector |
|
7 |
|
, controller = new Expector(); |
|
8 |
|
|
|
9 |
|
controller.expect( 'built' ); |
|
10 |
|
controller.expect( 'hello\n' ); |
|
11 |
|
|
|
12 |
|
cp |
|
13 |
|
.fork( path.join( __dirname, 'plank/bin/test.js' ) ) |
|
14 |
|
.on( 'exit', function() { |
|
15 |
|
controller.emit( 'built' ); |
|
16 |
|
cp.execFile( path.join( __dirname, '/build/Test/test' ), function(err, stdout, stderr) { |
|
17 |
|
if(err) throw err; |
|
18 |
|
controller.emit( stdout ); |
|
19 |
|
} ); |
|
20 |
|
}); |
|
21 |
|
|
|
22 |
|
process.on( 'exit', function() { |
|
23 |
|
controller.check(); |
|
24 |
|
}); |
|