core.pure.test.testCollection.pure Maven / Gradle / Ivy
// Copyright 2022 Goldman Sachs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import meta::pure::test::*;
Profile meta::pure::test::paramTest
{
stereotypes : [ Test, Ignore, BeforePackage, AfterPackage ];
}
Class meta::pure::test::PureTestCollection
{
pkg: Package[1];
testParameterizationId: String[0..1];
testFunctionParam: Any[0..1];
testFunctionParamCustomizer: FunctionDefinition[0..1];
testFunctions: FunctionDefinition[*];
beforeFunctions: FunctionDefinition[*];
afterFunctions: FunctionDefinition[*];
subCollections: PureTestCollection[*];
}
function meta::pure::test::collectParameterizedTests(pkg: Package[1], testParameterizationId: String[0..1], testFunctionParam: Any[0..1],
testFunctionParamCustomizer: FunctionDefinition[0..1],
testFilter: Function<{FunctionDefinition[1] -> Boolean[1]}>[0..1]): PureTestCollection[1]
{
let subPkgs = $pkg.children->map(c| $c->match([p:Package[1]| $p, x:Any[1]| []]));
let fns = $pkg.children->map(c| $c->match([p:ConcreteFunctionDefinition[1]| $p, x:Any[1]| []]));
^PureTestCollection(
pkg = $pkg,
testParameterizationId = $testParameterizationId,
testFunctionParam = $testFunctionParam,
testFunctionParamCustomizer = $testFunctionParamCustomizer,
testFunctions = $fns->filter(f| $f.stereotypes->contains(paramTest->stereotype('Test')) && ($testFilter->isEmpty() || $testFilter->toOne()->eval($f))),
beforeFunctions = $fns->filter(f| $f.stereotypes->contains(paramTest->stereotype('BeforePackage'))),
afterFunctions = $fns->filter(f| $f.stereotypes->contains(paramTest->stereotype('AfterPackage'))),
subCollections = $subPkgs->map(p| $p->collectParameterizedTests($testParameterizationId, $testFunctionParam, $testFunctionParamCustomizer, $testFilter))
);
}