Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve API test output #24

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 28 additions & 30 deletions tests/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ const cdlTxt = fs.readFileSync("csl-types/cardano-data-lite.d.ts", { "encoding":

// Arrays of parameters for the tests
let compareToCslTests: Array<TestParameters> = [];
let compareToCdlTests: Array<TestParameters> = [];

// Paths where the reports will be saved
const missingClassesPath = "tests/reports/api_missing_classes.csv";
const missingMethodsPath = "tests/reports/api_missing_methods.csv";
const methodFailuresPath = "tests/reports/api_failing_methods.csv"

console.log("Parsing CSL declaration files...")
const cslMatch = grammar.match(cslStrippedTxt);
Expand Down Expand Up @@ -138,29 +142,24 @@ semantics.addOperation<string>("attrName()", {
// for parsing renaming exports.
}).addOperation<ClassRename>("rename()", {
Rename(originalName, _as, newName) {
// console.log("Rename");
return { originalName: originalName.sourceString, newName: newName.sourceString };
}
}).addOperation<Array<ClassRename> | undefined>("renames_maybe()", {
OtherExport(otherExportNode) {
// console.log("OtherExport");
if (otherExportNode.ctorName == "OtherExport_export_rename") {
return otherExportNode.renames();
} else {
return undefined;
}
},
Import(_0, _1, _2, _3, _4, _5, _6) {
// console.log("Import");
return undefined;
},
ClassDecl(_0, _1, _2, _3, _4, _5, _6) {
// console.log("ClassDecl");
return undefined
}
}).addOperation<Array<ClassRename>>("renames()", {
TopLevel(topLevelNodes) {
// console.log("TopLevel");
let renames: Array<ClassRename> = [];
for (const node of topLevelNodes.children) {
const rename: Array<ClassRename> | undefined = node.renames_maybe();
Expand All @@ -171,7 +170,6 @@ semantics.addOperation<string>("attrName()", {
return renames;
},
OtherExport_export_rename(_export, _braceOpen, renamesList, _braceClose, _semicolon) {
// console.log("OtherExport_export_rename")
let renames: Array<ClassRename> = [];
for (const renameNode of renamesList.asIteration().children) {
const rename: ClassRename = renameNode.rename();
Expand Down Expand Up @@ -258,8 +256,20 @@ for (const [cls, methods] of cslClassesMap) {
}
}

console.log("Missing classes:\n\t", missingClasses.join("\n\t"))
console.log("Missing methods:\n\t", missingMethods.join("\n\t"))
console.log(
"Missing classes:\n\t"
, missingClasses.length
? `${missingClasses.length} missing classes found. Check ${missingClassesPath} for more details.`
: "(No missing classes)"
)

console.log(
"Missing methods:\n\t"
, missingClasses.length
? `${missingMethods.length} missing methods found. Check ${missingMethodsPath} for more details.`
: "(No missing methods)"
)


// We export the missing classes and methods to CSV files
try {
Expand All @@ -271,12 +281,12 @@ try {

let missingClassesCsv = "Missing Class\n";
missingClassesCsv += missingClasses.join("\n");
fs.writeFileSync("tests/reports/api_missing_classes.csv", missingClassesCsv);
fs.writeFileSync(missingClassesPath, missingClassesCsv);
let missingMethodsCsv = "Missing method\n"
missingMethodsCsv += missingMethods.join("\n");
fs.writeFileSync("tests/reports/api_missing_methods.csv", missingMethodsCsv);
fs.writeFileSync(missingMethodsPath, missingMethodsCsv);

// We construct the test tables
// We construct the test table
let n: number = 0;
for (const cls of cslClasses) {
for (const method of cls.methods) {
Expand All @@ -285,28 +295,16 @@ for (const cls of cslClasses) {
}
}

n = 0;
for (const cls of cdlClasses) {
for (const method of cls.methods) {
compareToCdlTests.push({ n: n, class: cls.name, comparedToMethod: method })
n += 1;
}
}
console.log("compareToCslTests.length: ", compareToCslTests.length)
console.log("compareToCdlTests.length: ", compareToCdlTests.length)

// We open a report file to write down each method comparison failure as we find it
let methodFailuresFile = fs.openSync("tests/reports/api_failing_methods.csv", "w");
let methodFailuresFile = fs.openSync(methodFailuresPath, "w");
fs.writeFileSync(methodFailuresFile, "Affected class,Method,Failure reason,Failure message\n");

// Used for debugging
const testN = 2752;
const testNConfig = { testTable: compareToCdlTests, srcMap: cslClassesMap };
test.skip(`Test N. ${testN}`, () => {
const { testTable, srcMap } = testNConfig;
const params = testTable[testN];
compareToClass(srcMap, params.class, params.comparedToMethod);
});
// const testN = 2752;
// test.skip(`Test N. ${testN}`, () => {
// const params = compareToCslTests[testN];
// compareToClass(cslClassesMap, params.class, params.comparedToMethod);
// });

// Tests
describe("API coverage tests", () => {
Expand Down
Loading