progtest: Return empty array of test cases if none provided

* progtest/src/reader/YamlTestReader.js (loadCases): Handle absence of any
  test cases.
* progtest/test/reader/YamlTestReaderTest.js: New respective test.
master v2.11.1
Mike Gerwitz 2018-03-06 11:41:21 -05:00
parent 0cb43d5e8a
commit 0d169ea9eb
2 changed files with 11 additions and 1 deletions

View File

@ -71,7 +71,7 @@ module.exports = Class( 'YamlTestReader' )
*/
'virtual public loadCases'( yaml )
{
const data = this._yamlParser.safeLoad( yaml )
const data = ( this._yamlParser.safeLoad( yaml ) || [] )
.map( this._createTestCase );
return data;

View File

@ -52,4 +52,14 @@ describe( "YamlTestReader", () =>
expect( Sut( mock_parser, case_ctor ).loadCases( yaml ) )
.to.deep.equal( [ { ok: parsed[0] } ] );
} );
it( "produces empty array given no tests", () =>
{
const mock_parser = { safeLoad: () => null };
const case_ctor = () => null; // unused
expect( Sut( mock_parser, case_ctor ).loadCases( "" ) )
.to.deep.equal( [] );
} );
} );