@abaplint/core
Version:
abaplint - Core API
95 lines (93 loc) • 3.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AddTestAttributes = exports.AddTestAttributesConf = void 0;
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const Statements = require("../abap/2_statements/statements");
const Structures = require("../abap/3_structures/structures");
const _irule_1 = require("./_irule");
class AddTestAttributesConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.AddTestAttributesConf = AddTestAttributesConf;
class AddTestAttributes extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new AddTestAttributesConf();
}
getMetadata() {
return {
key: "add_test_attributes",
title: "Add test attributes for tests classes with test methods",
shortDescription: `Add test attributes DURATION and RISK LEVEL for tests classes with test methods`,
tags: [_irule_1.RuleTag.SingleFile],
badExample: `CLASS ltcl_test1 DEFINITION FINAL FOR TESTING.
PUBLIC SECTION.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS test FOR TESTING RAISING cx_static_check.
ENDCLASS.
CLASS ltcl_test1 IMPLEMENTATION.
METHOD test.
ENDMETHOD.
ENDCLASS.`,
goodExample: `CLASS ltcl_test2 DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PUBLIC SECTION.
PROTECTED SECTION.
PRIVATE SECTION.
METHODS test FOR TESTING RAISING cx_static_check.
ENDCLASS.
CLASS ltcl_test2 IMPLEMENTATION.
METHOD test.
ENDMETHOD.
ENDCLASS.`,
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file) {
const issues = [];
const stru = file.getStructure();
if (stru === undefined) {
return [];
}
for (const classStructure of stru.findAllStructures(Structures.ClassDefinition)) {
const cdef = classStructure.findFirstStatement(Statements.ClassDefinition);
if (cdef === undefined) {
continue;
}
const cdefConcat = cdef === null || cdef === void 0 ? void 0 : cdef.concatTokens().toUpperCase();
if ((cdefConcat === null || cdefConcat === void 0 ? void 0 : cdefConcat.includes(" FOR TESTING")) === false) {
continue;
}
const hasDuration = cdefConcat === null || cdefConcat === void 0 ? void 0 : cdefConcat.includes(" DURATION ");
const hasRiskLevel = cdefConcat === null || cdefConcat === void 0 ? void 0 : cdefConcat.includes(" RISK LEVEL ");
if (hasDuration === true && hasRiskLevel === true) {
continue;
}
let hasTestMethod = false;
for (const mdef of classStructure.findAllStatements(Statements.MethodDef)) {
const concat = mdef.concatTokens().toUpperCase();
if (concat.includes(" FOR TESTING")) {
hasTestMethod = true;
}
}
if (hasTestMethod === false) {
continue;
}
if (hasDuration === false) {
issues.push(issue_1.Issue.atStatement(file, cdef, "Add DURATION", this.getMetadata().key, this.getConfig().severity));
}
if (hasRiskLevel === false) {
issues.push(issue_1.Issue.atStatement(file, cdef, "Add RISK LEVEL", this.getMetadata().key, this.getConfig().severity));
}
}
return issues;
}
}
exports.AddTestAttributes = AddTestAttributes;
//# sourceMappingURL=add_test_attributes.js.map