|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// MODULES // |
| 4 | + |
| 5 | +var resolve = require( 'path' ).resolve; |
| 6 | +var exec = require( 'child_process' ).exec; |
| 7 | +var tape = require( 'tape' ); |
| 8 | +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); |
| 9 | +var readFileSync = require( '@stdlib/fs/read-file' ).sync; |
| 10 | + |
| 11 | + |
| 12 | +// VARIABLES // |
| 13 | + |
| 14 | +var fpath = resolve( __dirname, '..', 'bin', 'cli' ); |
| 15 | +var opts = { |
| 16 | + 'skip': IS_BROWSER |
| 17 | +}; |
| 18 | + |
| 19 | + |
| 20 | +// FIXTURES // |
| 21 | + |
| 22 | +var PKG_VERSION = require('./../package.json' ).version; |
| 23 | +var HELP = readFileSync( resolve( __dirname, '..', 'bin', 'usage.txt' ), { |
| 24 | + 'encoding': 'utf8' |
| 25 | +}); |
| 26 | + |
| 27 | + |
| 28 | +// TESTS // |
| 29 | + |
| 30 | +tape( 'command-line interface', function test( t ) { |
| 31 | + t.ok( true, __filename ); |
| 32 | + t.end(); |
| 33 | +}); |
| 34 | + |
| 35 | +tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { |
| 36 | + var cmd = [ |
| 37 | + fpath, |
| 38 | + '--help' |
| 39 | + ]; |
| 40 | + |
| 41 | + exec( cmd.join( ' ' ), done ); |
| 42 | + |
| 43 | + function done( error, stdout, stderr ) { |
| 44 | + if ( error ) { |
| 45 | + t.fail( error.message ); |
| 46 | + } else { |
| 47 | + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); |
| 48 | + t.strictEqual( stderr.toString(), HELP+'\n', 'expected value' ); |
| 49 | + } |
| 50 | + t.end(); |
| 51 | + } |
| 52 | +}); |
| 53 | + |
| 54 | +tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { |
| 55 | + var cmd = [ |
| 56 | + fpath, |
| 57 | + '-h' |
| 58 | + ]; |
| 59 | + |
| 60 | + exec( cmd.join( ' ' ), done ); |
| 61 | + |
| 62 | + function done( error, stdout, stderr ) { |
| 63 | + if ( error ) { |
| 64 | + t.fail( error.message ); |
| 65 | + } else { |
| 66 | + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); |
| 67 | + t.strictEqual( stderr.toString(), HELP+'\n', 'expected value' ); |
| 68 | + } |
| 69 | + t.end(); |
| 70 | + } |
| 71 | +}); |
| 72 | + |
| 73 | +tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { |
| 74 | + var cmd = [ |
| 75 | + fpath, |
| 76 | + '--version' |
| 77 | + ]; |
| 78 | + |
| 79 | + exec( cmd.join( ' ' ), done ); |
| 80 | + |
| 81 | + function done( error, stdout, stderr ) { |
| 82 | + if ( error ) { |
| 83 | + t.fail( error.message ); |
| 84 | + } else { |
| 85 | + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); |
| 86 | + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); |
| 87 | + } |
| 88 | + t.end(); |
| 89 | + } |
| 90 | +}); |
| 91 | + |
| 92 | +tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { |
| 93 | + var cmd = [ |
| 94 | + fpath, |
| 95 | + '-V' |
| 96 | + ]; |
| 97 | + |
| 98 | + exec( cmd.join( ' ' ), done ); |
| 99 | + |
| 100 | + function done( error, stdout, stderr ) { |
| 101 | + if ( error ) { |
| 102 | + t.fail( error.message ); |
| 103 | + } else { |
| 104 | + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); |
| 105 | + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); |
| 106 | + } |
| 107 | + t.end(); |
| 108 | + } |
| 109 | +}); |
| 110 | + |
| 111 | +// TODO: additional tests |
0 commit comments