-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheatstroke.ts
148 lines (137 loc) · 4.64 KB
/
heatstroke.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* Heatstrokes Reporter
*
* This reporter integrates with `fast-check` to provide detailed and formatted
* outputs for failed property-based tests. It captures key information such as
* the contract, functions, arguments, outputs, and the specific invariant that
* failed, enabling quick identification of issues.
*/
/**
* Reports the details of a failed property-based test run.
*
* This function provides a detailed report when a fuzzing test fails including
* the contract, functions, arguments, outputs, and the specific invariant that
* failed.
*
* @param runDetails - The details of the test run provided by fast-check.
* @property runDetails.failed - Indicates if the property test failed.
* @property runDetails.counterexample - The input that caused the failure.
* @property runDetails.numRuns - The number of test cases that were run.
* @property runDetails.seed - The seed used to generate the test cases.
* @property runDetails.path - The path to reproduce the failing test.
* @property runDetails.error - The error thrown during the test.
*/
import { green } from "ansicolor";
import { EventEmitter } from "events";
import { getContractNameFromContractId } from "./shared";
export function reporter(
//@ts-ignore
runDetails,
radio: EventEmitter,
type: "invariant" | "test"
) {
if (runDetails.failed) {
// Report general run data.
const r = runDetails.counterexample[0];
radio.emit(
"logFailure",
`\nError: Property failed after ${runDetails.numRuns} tests.`
);
radio.emit("logFailure", `Seed : ${runDetails.seed}`);
if (runDetails.path) {
radio.emit("logFailure", `Path : ${runDetails.path}`);
}
switch (type) {
case "invariant": {
// Report specific run data for the invariant testing type.
radio.emit("logFailure", `\nCounterexample:`);
radio.emit(
"logFailure",
`- Contract : ${getContractNameFromContractId(
r.rendezvousContractId
)}`
);
radio.emit(
"logFailure",
`- Function : ${r.selectedFunction.name} (${r.selectedFunction.access})`
);
radio.emit(
"logFailure",
`- Arguments: ${JSON.stringify(r.functionArgsArb)}`
);
radio.emit("logFailure", `- Caller : ${r.sutCaller[0]}`);
radio.emit(
"logFailure",
`- Outputs : ${JSON.stringify(r.selectedFunction.outputs)}`
);
radio.emit(
"logFailure",
`- Invariant: ${r.selectedInvariant.name} (${r.selectedInvariant.access})`
);
radio.emit(
"logFailure",
`- Arguments: ${JSON.stringify(r.invariantArgsArb)}`
);
radio.emit("logFailure", `- Caller : ${r.invariantCaller[0]}`);
radio.emit(
"logFailure",
`\nWhat happened? Rendezvous went on a rampage and found a weak spot:\n`
);
const formattedError = `The invariant "${
r.selectedInvariant.name
}" returned:\n\n${runDetails.error
?.toString()
.split("\n")
// @ts-ignore
.map((line) => " " + line)
.join("\n")}\n`;
radio.emit("logFailure", formattedError);
break;
}
case "test": {
// Report specific run data for the property testing type.
radio.emit("logFailure", `\nCounterexample:`);
radio.emit(
"logFailure",
`- Test Contract : ${getContractNameFromContractId(r.testContractId)}`
);
radio.emit(
"logFailure",
`- Test Function : ${r.selectedTestFunction.name} (${r.selectedTestFunction.access})`
);
radio.emit(
"logFailure",
`- Arguments : ${JSON.stringify(r.functionArgsArb)}`
);
radio.emit("logFailure", `- Caller : ${r.testCaller[0]}`);
radio.emit(
"logFailure",
`- Outputs : ${JSON.stringify(r.selectedTestFunction.outputs)}`
);
radio.emit(
"logFailure",
`\nWhat happened? Rendezvous went on a rampage and found a weak spot:\n`
);
const formattedError = `The test function "${
r.selectedTestFunction.name
}" returned:\n\n${runDetails.error
?.toString()
.split("\n")
// @ts-ignore
.map((line) => " " + line)
.join("\n")}\n`;
radio.emit("logFailure", formattedError);
break;
}
}
} else {
radio.emit(
"logMessage",
green(
`\nOK, ${
type === "invariant" ? "invariants" : "properties"
} passed after ${runDetails.numRuns} runs.\n`
)
);
}
}