Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Start a basic functional test framework.
Browse files Browse the repository at this point in the history
We use a standard TAP functional test format with `tNNN*.js` test
scripts under a `t/` subdirectory. These can be run directly from
the project root with `node t/t001.js` or similar, and later the
build system will be extended to find and run tests automatically.

The `t/tlib.js` file is a library of handy support functions for
this, including bringing it various test tools (tape, tape-spawn,
etc.) and functions to read in data files that store expected output
and whatnot. tlib itself is tested with `t/t001-tlib.js`.

The first test of the non-test-framework code is `t010-version.js`,
which proves we can run the `gapps` binary.
  • Loading branch information
0cjs authored and nishantjr committed Jan 24, 2016
1 parent 4860c05 commit f563309
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"gulp": "^3.9.0",
"gulp-exclude-gitignore": "^1.0.0",
"gulp-tape": "0.0.7",
"tape": "^4.4.0"
"tape": "^4.4.0",
"tape-spawn": "^1.4.0"
}
}
8 changes: 8 additions & 0 deletions t/t001-tlib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict'
const tlib = require('./tlib')(module)

tlib.test('readTestData', (t) => {
t.equal('A file containing expected output.\n',
tlib.readTestData(tlib.testData('expected')))
t.end()
})
1 change: 1 addition & 0 deletions t/t001/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A file containing expected output.
12 changes: 12 additions & 0 deletions t/t010-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'
const tlib = require('./tlib')(module)

// Smoke test for the command line program.
tlib.test('version', (t) => {
const
expected = require('../package.json').version + '\n',
cmd = tlib.spawn(t, './bin/gapps -V')
cmd.succeeds()
cmd.stdout.match(expected)
cmd.end()
})
22 changes: 22 additions & 0 deletions t/tlib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const
fs = require('fs'),
path = require('path'),
_ = require('lodash')

function testData(test_module, p) {
const
dir = path.dirname(test_module.filename),
subdir = path.basename(test_module.filename, '.js').split('-')[0]
return path.join(dir, subdir, p)
}

function readTestData(p) {
return fs.readFileSync(p, { encoding: 'UTF-8' })
}

module.exports = (test_module) => { return {
test: require('tape'),
spawn: require('tape-spawn'),
testData: _.partial(testData, test_module),
readTestData: readTestData,
}}

0 comments on commit f563309

Please sign in to comment.