Skip to content

Commit

Permalink
feat: Improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
aboeglin committed Sep 7, 2022
1 parent fc32139 commit 67f6a49
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,16 @@ import __Coverage__ from "./.prelude/Coverage.mjs";
let Just = (a => ({ __constructor: "Just", __args: [ a ] }));
let Nothing = ({ __constructor: "Nothing", __args: [ ] });
Inspect['Maybe_568c75136c0c369c440814a7af59434a'] = {};
Inspect['Maybe_568c75136c0c369c440814a7af59434a']['inspect'] = () => (Inspect_a4654) => (__$a__ => ((__x__) => {
Inspect['Maybe_568c75136c0c369c440814a7af59434a']['inspect'] = () => (Inspect_p4305) => (__$a__ => ((__x__) => {
if (__x__.__constructor === "Just" && true) {
let a0 = __x__.__args[0];
return (() => {
__branchTracker_0_32_0__.increment(({ __constructor: "Unit", __args: [] }))
return `Just(` + Inspect_a4654.inspect()(a0) + `)`
})();
return `Just(` + Inspect_p4305.inspect()(a0) + `)`;
}
else if (__x__.__constructor === "Nothing") {
return (() => {
__branchTracker_0_32_1__.increment(({ __constructor: "Unit", __args: [] }))
return `Nothing`
})();
return `Nothing`;
}
else if (true) {
return (() => {
__branchTracker_0_32_2__.increment(({ __constructor: "Unit", __args: [] }))
return `Unknown`
})();
return `Unknown`;
}
else {
console.log('non exhaustive patterns for value: ', __x__.toString());
Expand All @@ -33,22 +24,9 @@ Inspect['Maybe_568c75136c0c369c440814a7af59434a']['inspect'] = () => (Inspect_a4
}
})(__$a__));
Inspect['Record_carsf_0568c75136c0c369c440814a7af59434a'] = {};
Inspect['Record_carsf_0568c75136c0c369c440814a7af59434a']['inspect'] = () => (Inspect_e4684) => (__$a__ => `{ ` + `cars: ` + Inspect_e4684.inspect()(__$a__.cars) + ` }`);
Inspect['Record_carsf_0568c75136c0c369c440814a7af59434a']['inspect'] = () => (Inspect_e4320) => (__$a__ => `{ ` + `cars: ` + Inspect_e4320.inspect()(__$a__.cars) + ` }`);
Inspect['Record_namef_0568c75136c0c369c440814a7af59434a_xf_1568c75136c0c369c440814a7af59434a'] = {};
Inspect['Record_namef_0568c75136c0c369c440814a7af59434a_xf_1568c75136c0c369c440814a7af59434a']['inspect'] = () => (Inspect_v4701) => (Inspect_o4694) => (__$a__ => `{ ` + `name: ` + Inspect_o4694.inspect()(__$a__.name) + `, ` + `x: ` + Inspect_v4701.inspect()(__$a__.x) + ` }`);
let __branchTracker_0_32_2__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(32)(2);
let __branchTracker_0_32_1__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(32)(1);
let __branchTracker_0_32_0__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(32)(0);
let __branchTracker_0_31_2__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(31)(2);
let __branchTracker_0_31_1__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(31)(1);
let __branchTracker_0_31_0__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(31)(0);
let __branchTracker_0_30_1__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(30)(1);
let __branchTracker_0_30_0__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(30)(0);
let __branchTracker_0_28_2__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(28)(2);
let __branchTracker_0_28_1__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(28)(1);
let __branchTracker_0_28_0__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(28)(0);
let __branchTracker_0_29_1__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(29)(1);
let __branchTracker_0_29_0__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(0)(29)(0);
Inspect['Record_namef_0568c75136c0c369c440814a7af59434a_xf_1568c75136c0c369c440814a7af59434a']['inspect'] = () => (Inspect_v4337) => (Inspect_o4330) => (__$a__ => `{ ` + `name: ` + Inspect_o4330.inspect()(__$a__.name) + `, ` + `x: ` + Inspect_v4337.inspect()(__$a__.x) + ` }`);
let __functionTracker_123_snd__ = __Coverage__.Reporter.functionTracker(`Module.mad`)(123)(`snd`);
let __lineTracker_127__ = __Coverage__.Reporter.lineTracker(`Module.mad`)(127);
let __branchTracker_124_27_0__ = __Coverage__.Reporter.branchTracker(`Module.mad`)(124)(27)(0);
Expand Down
7 changes: 5 additions & 2 deletions compiler/main/Canonicalize/Coverage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ addTrackers options ast@AST{ apath = Just path } = do
updatedImports' <- addImport processModuleName "Process" processModulePath updatedImports
updatedExps <- mapM (addTrackersToExp options path) $ aexps ast
updatedInstances <- forM (ainstances ast) $ \(Canonical area (Instance n ps p methods)) -> do
methods' <- mapM (addTrackersToExp options path) methods
return $ Canonical area (Instance n ps p methods')
if n == "Eq" || n == "Inspect" then
return $ Canonical area (Instance n ps p methods)
else do
methods' <- mapM (addTrackersToExp options path) methods
return $ Canonical area (Instance n ps p methods')
trackers <- generateTrackerFunctions
return ast { aexps = trackers ++ updatedExps, ainstances = updatedInstances, aimports = updatedImports' }
else
Expand Down
4 changes: 2 additions & 2 deletions madlib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ cabal-version: 2.0
--
-- see: https://github.com/sol/hpack
--
-- hash: cb3fc1f0926b35347069f04ab88bea64d1b40060463bfb8d2bbd265f742396bd
-- hash: 49c153f5415a616a8b168ef16cd7b9fb989d395632ff879384cd44fa2b6cd039

name: madlib
version: 0.15.0
version: 0.15.1
description: Please see the README on GitHub at <https://github.com/madlib-lang/madlib#readme>
homepage: https://github.com/madlib-lang/madlib#readme
bug-reports: https://github.com/madlib-lang/madlib/issues
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: madlib
version: 0.15.0
version: 0.15.1
github: "madlib-lang/madlib"
license: BSD3
author: "Arnaud Boeglin, Brekk Bockrath"
Expand Down
2 changes: 1 addition & 1 deletion pkg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@madlib-lang/madlib",
"version": "0.15.0",
"version": "0.15.1",
"main": "./src/run.js",
"bin": {
"madlib": "src/run.js"
Expand Down
72 changes: 46 additions & 26 deletions prelude/__internal__/Coverage.mad
Original file line number Diff line number Diff line change
Expand Up @@ -373,21 +373,29 @@ buildAllResults = (coverageData) => {
printRows :: List (List String) -> {}
printRows = (rows) => {
finalRows = pipe(
map(
where {
List.mapWithIndex(
(row, index) => where(row) {
[module, line, fn, branch, total] =>
`${module} ${line} ${fn} ${branch} ${total}`
if (index == 0) {
`${module} ${line} ${fn} ${branch} ${total}`
} else {
`${module} ${renderPercentage(line)} ${renderPercentage(fn)} ${renderPercentage(branch)} ${renderPercentage(total)}`
}
}
),
where {
[header, ...moduleRows] =>
[header, String.repeat('-', String.length(header)), ...moduleRows]
[
header,
pipe(String.length, String.repeat('-'), IO.grey)(header),
...moduleRows
]
},
String.join("\n")
)(rows)

IO.putLine("\nCoverage")
IO.putLine("--------\n")
IO.putLine(IO.grey("--------\n"))
IO.putLine(finalRows)
IO.putLine("")
}
Expand Down Expand Up @@ -422,36 +430,48 @@ formatRows = (rows) =>
Math.substract($, String.length(colContent)),
List.repeat(' '),
String.fromList,
(spaces) => colContent ++ spaces
(spaces) => colIndex == 0 ? colContent ++ spaces : spaces ++ colContent
)(colIndex))
)(rows)
}
}


displayCoverageResults :: Dictionary String CoverageData -> {}
displayCoverageResults = (coverageData) => {
rows = pipe(
buildAllResults,
map(
where {
ModuleResult(astPath, line, fn, branch, total) =>
[
astPath,
`${keepTwoDecimals(inspect(line))}%`,
`${keepTwoDecimals(inspect(fn))}%`,
`${keepTwoDecimals(inspect(branch))}%`,
`${keepTwoDecimals(inspect(total))}%`,
]
}
),
(rs) => [["Module", "Lines", "Functions", "Branches", "Total"], ...rs],
formatRows,
printRows
)(coverageData)
renderPercentage :: String -> String
renderPercentage = (input) => where(scan(String.dropLast(1, input))) {
Just(num) =>
if (num > 90) {
IO.green(input)
} else if (num > 75) {
IO.yellow(input)
} else {
IO.red(input)
}

Nothing =>
IO.red(input)
}

displayCoverageResults :: Dictionary String CoverageData -> {}
displayCoverageResults = (coverageData) => pipe(
buildAllResults,
map(
where {
ModuleResult(astPath, line, fn, branch, total) =>
[
astPath,
`${keepTwoDecimals(inspect(line))}%`,
`${keepTwoDecimals(inspect(fn))}%`,
`${keepTwoDecimals(inspect(branch))}%`,
`${keepTwoDecimals(inspect(total))}%`,
]
}
),
(rs) => [["Module", "Lines", "Functions", "Branches", "Total"], ...rs],
formatRows,
printRows
)(coverageData)


generateLcov :: Dictionary String CoverageData -> String
generateLcov = (coverageData) => pipe(
Expand Down

0 comments on commit 67f6a49

Please sign in to comment.