Skip to content

Commit 2175273

Browse files
qiuzhongMinggang Wang
authored andcommitted
[UT] Use RegExp to verifiy the console output
Use RegExp to verify the console output rather than compare the exact wording from subscription process output. This is useful when the debug flag is enabled.
1 parent 53f7af9 commit 2175273

File tree

4 files changed

+68
-68
lines changed

4 files changed

+68
-68
lines changed

test/test-cross-lang.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ describe('Cross-language interaction', function() {
194194

195195
var pyClient = utils.launchPythonProcess([`${__dirname}/py/client.py`]);
196196
pyClient.stdout.on('data', function(data) {
197-
assert.deepEqual(parseInt(data, 10), 3);
197+
assert.ok(new RegExp('3').test(data.toString()));
198198
if (!destroy) {
199199
node.destroy();
200200
destroy = true;
@@ -223,7 +223,7 @@ describe('Cross-language interaction', function() {
223223
'add_two_ints_client');
224224
var cppClient = childProcess.spawn(cppClientPath, ['-s', 'cpp_js_add_two_ints']);
225225
cppClient.stdout.on('data', function(data) {
226-
assert.deepStrictEqual(data.toString().trim(), 'Result of add_two_ints: 5');
226+
assert.ok(new RegExp('Result of add_two_ints: 5').test(data.toString()));
227227
node.destroy();
228228
done();
229229
});

test/test-interactive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('rclnodejs interactive testing', function() {
6969
var destroy = false;
7070
var client = childProcess.fork(`${__dirname}/client_setup.js`, {silent: true});
7171
client.stdout.on('data', function(data) {
72-
assert.deepEqual(parseInt(data, 10), 3);
72+
assert.ok(new RegExp('3').test(data.toString()));
7373
if (!destroy) {
7474
client.kill('SIGINT');
7575
node.destroy();

test/test-msg-type-cpp-node.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ describe('Rclnodejs - Cpp message type testing', function() {
395395

396396
subscription.stdout.on('data', (data) => {
397397
if (!destroy) {
398-
assert.deepStrictEqual(data.toString().trim(), expected);
398+
assert.ok(new RegExp(expected).test(data.toString()));
399399
timer.cancel();
400400
node.destroy();
401401
subscription.kill('SIGINT');
@@ -422,7 +422,7 @@ describe('Rclnodejs - Cpp message type testing', function() {
422422

423423
subscription.stdout.on('data', (data) => {
424424
if (!destroy) {
425-
assert.deepStrictEqual(data.toString().trim(), expected);
425+
assert.ok(new RegExp(expected).test(data.toString()));
426426
timer.cancel();
427427
node.destroy();
428428
subscription.kill('SIGINT');
@@ -450,7 +450,7 @@ describe('Rclnodejs - Cpp message type testing', function() {
450450

451451
subscription.stdout.on('data', (data) => {
452452
if (!destroy) {
453-
assert.deepStrictEqual(data.toString().trim(), expected);
453+
assert.ok(new RegExp(expected).test(data.toString()));
454454
timer.cancel();
455455
node.destroy();
456456
subscription.kill('SIGINT');
@@ -477,7 +477,7 @@ describe('Rclnodejs - Cpp message type testing', function() {
477477

478478
subscription.stdout.on('data', (data) => {
479479
if (!destroy) {
480-
assert.deepStrictEqual(data.toString().trim(), expected);
480+
assert.ok(new RegExp(expected).test(data.toString()));
481481
timer.cancel();
482482
node.destroy();
483483
subscription.kill('SIGINT');
@@ -504,7 +504,7 @@ describe('Rclnodejs - Cpp message type testing', function() {
504504

505505
subscription.stdout.on('data', (data) => {
506506
if (!destroy) {
507-
assert.deepStrictEqual(data.toString().trim(), expected);
507+
assert.ok(new RegExp(expected).test(data.toString()));
508508
timer.cancel();
509509
node.destroy();
510510
subscription.kill('SIGINT');
@@ -531,7 +531,7 @@ describe('Rclnodejs - Cpp message type testing', function() {
531531

532532
subscription.stdout.on('data', (data) => {
533533
if (!destroy) {
534-
assert.deepStrictEqual(data.toString().trim(), expected);
534+
assert.ok(new RegExp(expected).test(data.toString()));
535535
timer.cancel();
536536
node.destroy();
537537
subscription.kill('SIGINT');
@@ -558,7 +558,7 @@ describe('Rclnodejs - Cpp message type testing', function() {
558558

559559
subscription.stdout.on('data', (data) => {
560560
if (!destroy) {
561-
assert.deepStrictEqual(data.toString().trim().toLowerCase(), expected);
561+
assert.ok(new RegExp(expected).test(data.toString().toLowerCase()));
562562
timer.cancel();
563563
node.destroy();
564564
subscription.kill('SIGINT');
@@ -585,7 +585,7 @@ describe('Rclnodejs - Cpp message type testing', function() {
585585

586586
subscription.stdout.on('data', (data) => {
587587
if (!destroy) {
588-
assert.deepStrictEqual(data.toString().trim().toLowerCase(), expected);
588+
assert.ok(new RegExp(expected).test(data.toString().toLowerCase()));
589589
timer.cancel();
590590
node.destroy();
591591
subscription.kill('SIGINT');
@@ -611,8 +611,8 @@ describe('Rclnodejs - Cpp message type testing', function() {
611611
const expected = '7fffffff';
612612

613613
subscription.stdout.on('data', (data) => {
614-
if (!destroy) {
615-
assert.deepStrictEqual(data.toString().trim().toLowerCase(), expected);
614+
if (!destroy) {
615+
assert.ok(new RegExp(expected).test(data.toString().toLowerCase()));
616616
timer.cancel();
617617
node.destroy();
618618
subscription.kill('SIGINT');
@@ -638,8 +638,8 @@ describe('Rclnodejs - Cpp message type testing', function() {
638638
const expected = 'ffffffff';
639639

640640
subscription.stdout.on('data', (data) => {
641-
if (!destroy) {
642-
assert.deepStrictEqual(data.toString().trim().toLowerCase(), expected);
641+
if (!destroy) {
642+
assert.ok(new RegExp(expected).test(data.toString().toLowerCase()));
643643
timer.cancel();
644644
node.destroy();
645645
subscription.kill('SIGINT');
@@ -665,8 +665,8 @@ describe('Rclnodejs - Cpp message type testing', function() {
665665
const expected = '1fffffffffffff';
666666

667667
subscription.stdout.on('data', (data) => {
668-
if (!destroy) {
669-
assert.deepStrictEqual(data.toString().trim().toLowerCase(), expected);
668+
if (!destroy) {
669+
assert.ok(new RegExp(expected).test(data.toString().toLowerCase()));
670670
timer.cancel();
671671
node.destroy();
672672
subscription.kill('SIGINT');
@@ -692,8 +692,8 @@ describe('Rclnodejs - Cpp message type testing', function() {
692692
const expected = '1fffffffffffff';
693693

694694
subscription.stdout.on('data', (data) => {
695-
if (!destroy) {
696-
assert.deepStrictEqual(data.toString().trim().toLowerCase(), expected);
695+
if (!destroy) {
696+
assert.ok(new RegExp(expected).test(data.toString().toLowerCase()));
697697
timer.cancel();
698698
node.destroy();
699699
subscription.kill('SIGINT');
@@ -719,8 +719,8 @@ describe('Rclnodejs - Cpp message type testing', function() {
719719
const expected = '3.14';
720720

721721
subscription.stdout.on('data', (data) => {
722-
if (!destroy) {
723-
assert.deepStrictEqual(data.toString().trim(), expected);
722+
if (!destroy) {
723+
assert.ok(new RegExp(expected).test(data.toString()));
724724
timer.cancel();
725725
node.destroy();
726726
subscription.kill('SIGINT');
@@ -746,8 +746,8 @@ describe('Rclnodejs - Cpp message type testing', function() {
746746
const expected = '3.1415926';
747747

748748
subscription.stdout.on('data', (data) => {
749-
if (!destroy) {
750-
assert.deepStrictEqual(data.toString().trim(), expected);
749+
if (!destroy) {
750+
assert.ok(new RegExp(expected).test(data.toString()));
751751
timer.cancel();
752752
node.destroy();
753753
subscription.kill('SIGINT');
@@ -780,8 +780,8 @@ describe('Rclnodejs - Cpp message type testing', function() {
780780
const expected = '(0.5, 127, 255, 255)';
781781

782782
subscription.stdout.on('data', (data) => {
783-
if (!destroy) {
784-
assert.deepStrictEqual(data.toString().trim(), expected);
783+
if (!destroy) {
784+
assert.ok(new RegExp(expected).test(data.toString()));
785785
timer.cancel();
786786
node.destroy();
787787
subscription.kill('SIGINT');
@@ -820,8 +820,8 @@ describe('Rclnodejs - Cpp message type testing', function() {
820820
const expected = 'ABC';
821821

822822
subscription.stdout.on('data', (data) => {
823-
if (!destroy) {
824-
assert.deepStrictEqual(data.toString().trim(), expected);
823+
if (!destroy) {
824+
assert.ok(new RegExp(expected).test(data.toString()));
825825
timer.cancel();
826826
node.destroy();
827827
subscription.kill('SIGINT');
@@ -854,8 +854,8 @@ describe('Rclnodejs - Cpp message type testing', function() {
854854
const expected = '(123456,789,main frame)';
855855

856856
subscription.stdout.on('data', (data) => {
857-
if (!destroy) {
858-
assert.deepStrictEqual(data.toString().trim(), expected);
857+
if (!destroy) {
858+
assert.ok(new RegExp(expected).test(data.toString()));
859859
timer.cancel();
860860
node.destroy();
861861
subscription.kill('SIGINT');
@@ -894,7 +894,7 @@ describe('Rclnodejs - Cpp message type testing', function() {
894894
const expected = '(123456,789,main frame,[Tom,Jerry,],[1,2,],[2,3,],[4,5,6,])';
895895
subscription.stdout.on('data', (data) => {
896896
if (!destroy) {
897-
assert.deepStrictEqual(data.toString().trim(), expected);
897+
assert.notDeepStrictEqual(data.toString().indexOf(expected), -1);
898898
timer.cancel();
899899
node.destroy();
900900
subscription.kill('SIGINT');

0 commit comments

Comments
 (0)