Initial embedding of YAML test case runner
parent
253f845803
commit
f788edd675
|
@ -17,7 +17,7 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
.PHONY: check test modindex FORCE
|
.PHONY: check test modindex browserify FORCE
|
||||||
|
|
||||||
namespaces=$(shell find src/ -type d)
|
namespaces=$(shell find src/ -type d)
|
||||||
nsindex=$(addsuffix /index.js, $(namespaces))
|
nsindex=$(addsuffix /index.js, $(namespaces))
|
||||||
|
@ -31,3 +31,10 @@ modindex: $(nsindex)
|
||||||
%/index.js: FORCE
|
%/index.js: FORCE
|
||||||
$(CURDIR)/build-aux/gen-index "$*" > "$@"
|
$(CURDIR)/build-aux/gen-index "$*" > "$@"
|
||||||
|
|
||||||
|
browserify: tame-progtest.js
|
||||||
|
tame-progtest.js: FORCE
|
||||||
|
$(CURDIR)/node_modules/.bin/browserify \
|
||||||
|
--debug \
|
||||||
|
-r $(CURDIR)/src/index.js:progtest \
|
||||||
|
$(CURDIR)/src/index.js \
|
||||||
|
-o "$@"
|
||||||
|
|
|
@ -24,36 +24,12 @@
|
||||||
const program = require( process.argv[ 2 ] );
|
const program = require( process.argv[ 2 ] );
|
||||||
const filename = process.argv[ 3 ];
|
const filename = process.argv[ 3 ];
|
||||||
|
|
||||||
const fs = require( 'fs' );
|
const fs = require( 'fs' );
|
||||||
const yaml_reader = require( 'js-yaml' );
|
|
||||||
|
|
||||||
const {
|
const case_yaml = fs.readFileSync( filename, 'utf8' );
|
||||||
TestCase,
|
|
||||||
TestRunner,
|
|
||||||
|
|
||||||
reader: {
|
const runner = require( '../src/env' ).console(
|
||||||
ConstResolver,
|
program, process.stdout
|
||||||
DateResolver,
|
|
||||||
YamlTestReader
|
|
||||||
},
|
|
||||||
|
|
||||||
reporter: {
|
|
||||||
ConsoleTestReporter
|
|
||||||
},
|
|
||||||
} = require( '../src' );
|
|
||||||
|
|
||||||
const runner = TestRunner(
|
|
||||||
ConsoleTestReporter( process.stdout ),
|
|
||||||
program
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const reader = YamlTestReader
|
runner( case_yaml );
|
||||||
.use( DateResolver )
|
|
||||||
.use( ConstResolver( program ) )
|
|
||||||
( yaml_reader, TestCase );
|
|
||||||
|
|
||||||
const cases = reader.loadCases(
|
|
||||||
fs.readFileSync( filename, 'utf8' )
|
|
||||||
);
|
|
||||||
|
|
||||||
const results = runner.runTests( cases );
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
"js-yaml": "3.10.0"
|
"js-yaml": "3.10.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"browserify": "16.10.0"
|
||||||
},
|
},
|
||||||
|
|
||||||
"license": "GPL-3.0+"
|
"license": "GPL-3.0+"
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/**
|
||||||
|
* Environment-specific runner initialization
|
||||||
|
*
|
||||||
|
* Copyright (C) 2018 R-T Specialty, LLC.
|
||||||
|
*
|
||||||
|
* This file is part of TAME.
|
||||||
|
*
|
||||||
|
* TAME is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const yaml_reader = require( 'js-yaml' );
|
||||||
|
|
||||||
|
const {
|
||||||
|
TestCase,
|
||||||
|
TestRunner,
|
||||||
|
|
||||||
|
reader: {
|
||||||
|
ConstResolver,
|
||||||
|
DateResolver,
|
||||||
|
YamlTestReader
|
||||||
|
},
|
||||||
|
|
||||||
|
reporter: {
|
||||||
|
ConsoleTestReporter
|
||||||
|
},
|
||||||
|
} = require( '../src' );
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
console: ( program, stdout ) =>
|
||||||
|
{
|
||||||
|
const runner = TestRunner(
|
||||||
|
ConsoleTestReporter( stdout ),
|
||||||
|
program
|
||||||
|
);
|
||||||
|
|
||||||
|
const reader = YamlTestReader
|
||||||
|
.use( DateResolver )
|
||||||
|
.use( ConstResolver( program ) )
|
||||||
|
( yaml_reader, TestCase );
|
||||||
|
|
||||||
|
return yaml => runner.runTests(
|
||||||
|
reader.loadCases( yaml )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
|
@ -132,6 +132,7 @@
|
||||||
</xsl:for-each-group>
|
</xsl:for-each-group>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<script type="text/javascript" src="{$fw-path}/rater/scripts/tame-progtest.js"></script>
|
||||||
<script type="text/javascript" src="{$fw-path}/rater/scripts/entry-form.js"></script>
|
<script type="text/javascript" src="{$fw-path}/rater/scripts/entry-form.js"></script>
|
||||||
</xsl:template>
|
</xsl:template>
|
||||||
|
|
||||||
|
|
|
@ -1501,8 +1501,41 @@ var client = ( function()
|
||||||
loadQuote( qid, qdata_host );
|
loadQuote( qid, qdata_host );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
const yamlconsole = dom.createElement( 'textarea' );
|
||||||
|
yamlconsole.style.display = 'none';
|
||||||
|
yamlconsole.id = 'yamlconsole';
|
||||||
|
|
||||||
|
const yamlbrowse = dom.createElement( 'input' );
|
||||||
|
yamlbrowse.type = 'file';
|
||||||
|
yamlbrowse.style.display = 'none';
|
||||||
|
yamlbrowse.accept = '.yml, .yaml';
|
||||||
|
yamlbrowse.multiple = 'multiple';
|
||||||
|
yamlbrowse.addEventListener( 'change', e =>
|
||||||
|
{
|
||||||
|
yamlconsole.style.display = '';
|
||||||
|
yamlconsole.textContent = '';
|
||||||
|
|
||||||
|
runYamlTestCases(
|
||||||
|
Array.prototype.slice.call( yamlbrowse.files, 0 ),
|
||||||
|
createYamlRunner( yamlconsole )
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
|
|
||||||
|
const yamlcases = dom.createElement( 'button' );
|
||||||
|
yamlcases.innerHTML = 'Load YAML Test Cases';
|
||||||
|
yamlcases.addEventListener( 'click', e =>
|
||||||
|
{
|
||||||
|
yamlbrowse.click();
|
||||||
|
return false;
|
||||||
|
} );
|
||||||
|
|
||||||
dialog.appendChild( retest );
|
dialog.appendChild( retest );
|
||||||
dialog.appendChild( loadquote );
|
dialog.appendChild( loadquote );
|
||||||
|
dialog.appendChild( yamlcases );
|
||||||
|
dialog.appendChild( yamlbrowse );
|
||||||
|
dialog.appendChild( yamlconsole );
|
||||||
dialog.appendChild( getPriorTable() );
|
dialog.appendChild( getPriorTable() );
|
||||||
|
|
||||||
dom.body.appendChild( dialog );
|
dom.body.appendChild( dialog );
|
||||||
|
@ -1517,6 +1550,57 @@ var client = ( function()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create YAML test case runner
|
||||||
|
*
|
||||||
|
* @param {HTMLElement} yamlconsole element to contain runner output
|
||||||
|
*
|
||||||
|
* @return {function(string)} runner
|
||||||
|
*/
|
||||||
|
const createYamlRunner = yamlconsole => require( 'progtest' )
|
||||||
|
.env.console(
|
||||||
|
{ rater: window.rater },
|
||||||
|
{
|
||||||
|
write( str )
|
||||||
|
{
|
||||||
|
yamlconsole.textContent += str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run test cases in each YAML file FILES
|
||||||
|
*
|
||||||
|
* @param {Array<File>} files YAML files
|
||||||
|
* @param {function(string)} runner test case runner
|
||||||
|
*
|
||||||
|
* @return {undefined}
|
||||||
|
*/
|
||||||
|
const runYamlTestCases = function( files, runner )
|
||||||
|
{
|
||||||
|
if ( files.length === 0 )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const testfile = files.shift();
|
||||||
|
const reader = new FileReader();
|
||||||
|
|
||||||
|
reader.onload = ev =>
|
||||||
|
{
|
||||||
|
const yaml = ev.target.result;
|
||||||
|
|
||||||
|
runner( yaml );
|
||||||
|
|
||||||
|
// run for remaining files
|
||||||
|
runYamlTestCases( files, runner );
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.readAsBinaryString( testfile );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var getPriorTable = function()
|
var getPriorTable = function()
|
||||||
{
|
{
|
||||||
var table = dom.createElement( 'table' ),
|
var table = dom.createElement( 'table' ),
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
../../../progtest/tame-progtest.js
|
|
@ -1020,3 +1020,11 @@ body:not(.prior) #voi-container td.prior
|
||||||
background-color: #ffc0c0;
|
background-color: #ffc0c0;
|
||||||
border-color: #c00000;
|
border-color: #c00000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#yamlconsole
|
||||||
|
{
|
||||||
|
display: block;
|
||||||
|
width: 95%;
|
||||||
|
height: 40ex;
|
||||||
|
margin: 2ex 0px;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue