Skip to content

Commit

Permalink
test(CLI): Trying to rewrite the cli test script in AVA.
Browse files Browse the repository at this point in the history
  • Loading branch information
Anadian committed Jun 11, 2020
1 parent 8d31e24 commit 256abb2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
34 changes: 34 additions & 0 deletions source/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ Documentation License: [![Creative Commons License](https://i.creativecommons.or
//##Internal
const RegexTranslator = require('./main.js');
//##Standard
const FileSystem = require('fs');
const ChildProcess = require('child_process');
//##External
const AVA = require('ava');
//#Constants
Expand Down Expand Up @@ -141,3 +143,35 @@ AVA('getMultiPartObjectFromInputString:MaximalInputString', function(t){
var actual_output = RegexTranslator.getMultiPartObjectFromInputString( input_string );
t.deepEqual( actual_output, expected_output );
});
AVA('CLI:HelpData', function(t){
//t.log(process.cwd());
//t.log(process.env);
var process_object = ChildProcess.spawnSync( 'node', ['source/main.js', '-Vhc'] );
//t.log( process_object );
if( process_object.status === 0 ){
t.pass();
} else{
t.fail();
}
});
AVA('CLI:INPUT-REGEX-STRING-to-STDOUT', function(t){
var expected_stdout_string = '\\(simple\\)\\= regex';
var stdout_string = '';
var something = 'something';
var process_object = ChildProcess.spawnSync( 'node', ['source/main.js', '--input-regex-string', 'pcre/(simple)? regex/replace/vim', '-o'], { stdio: ['pipe', 'pipe', 'pipe'] } );
t.log(process_object);
if( process_object.status === 0 ){
try{
stdout_string = process_object.output[1].toString('utf8');
t.log(stdout_string, something);
console.log('stdout_string: %s %s', stdout_string, something);
t.is(stdout_string,expected_stdout_string);
} catch(error){
return_error = new Error(`process_object.toString threw an error: ${error}`);
throw return_error;
}
} else{
t.fail();
}
});

24 changes: 24 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const ChildProcess = require('child_process');
function test(t){
var expected_stdout_string = '\\(simple\\)\\= regex';
var stdout_string = '';
var something = 'something';
var process_object = ChildProcess.spawnSync( 'node', ['source/main.js', '--input-regex-string', 'pcre/(simple)? regex/replace/vim', '-o'], { stdio: ['pipe', 'pipe', 'pipe'] } );
console.log(process_object);
if( process_object.status === 0 ){
try{
console.log(process_object.output[1]);
stdout_string = process_object.output[1].toString('utf8');
console.log(stdout_string, something);
console.log('stdout_string: %s %s', stdout_string, something);
//t.is(stdout_string,expected_stdout_string);
} catch(error){
return_error = new Error(`process_object.toString threw an error: ${error}`);
throw return_error;
}
} else{
//t.fail();
}
}

test(null);

0 comments on commit 256abb2

Please sign in to comment.