Work on this exercise locally
This web app is a reference guide — you can read instructions, browse starter code, and view tests here. To actually complete the exercise, you need to work in your local development environment.
git clone https://github.com/weihaoqu/program-analysis-bootcamp-studentfailwith "TODO" with your implementation.dune runtest modules/module6-tools-integration/exercises/analysis-reporterAnalysis Reporter
6. Exercise 5: Analysis Reporter (18 tests)
Goal: Generate human-readable text reports, JSON output, summary lines, and formatted tables from analysis findings.
Time: ~25 minutes
File to edit: exercises/analysis-reporter/starter/reporter.ml
Also provided (do not edit):
finding_types.ml-- unified finding types with all helperssample_findings.ml-- pre-built findings for testing
Dependencies: None (self-contained)
Types provided (not a TODO)
type report = {
program_name : string;
total_findings : int;
findings : Finding_types.finding list;
severity_counts : (Finding_types.severity * int) list;
category_counts : (Finding_types.category * int) list;
pass_counts : (string * int) list;
}
What to implement (in order)
| # | Function | Hint |
|---|---|---|
| 1 | build_report name findings | Fill in all report fields. Count severities, categories, and pass names. |
| 2 | format_text_report r | Header with "=== Analysis Report: name ===", total count, each formatted finding, severity breakdown |
| 3 | format_json_finding f | JSON object string with fields: id, category, severity, pass_name, location, message, suggestion (null if None) |
| 4 | format_json_report r | JSON object with fields: program, total, findings (array), severity_counts, category_counts |
| 5 | format_summary r | Empty: "Analysis of 'name': No findings." Non-empty: "Analysis of 'name': N findings (X Critical, Y High, ...)" -- only include non-zero severity counts |
| 6 | format_findings_table findings | Aligned text table with columns: Severity, Category, Pass, Location, Message |
| 7 | top_n_findings n findings | Sort by severity (highest first), take first n |
| 8 | findings_above_severity threshold findings | Keep findings where severity_to_int f.severity >= severity_to_int threshold |
Run tests
dune runtest modules/module6-tools-integration/exercises/analysis-reporter/
Starter output (all 18 tests error):
EEEEEEEEEEEEEEEEEE
Hints:
- For
format_json_finding, usePrintf.sprintfto build the JSON string. Escape quotes in string values if needed, but the test data does not contain embedded quotes. - For
format_summary, iterate overseverity_countsand build"X Critical, Y High"fragments, filtering out zero counts. - For
format_findings_table, compute the max width of each column first, then pad withPrintf.sprintf "%-*s".
Starter Files
Test Files
Work on this exercise locally
This web app is a reference guide — you can read instructions, browse starter code, and view tests here. To actually complete the exercise, you need to work in your local development environment.
git clone https://github.com/weihaoqu/program-analysis-bootcamp-studentfailwith "TODO" with your implementation.dune runtest modules/module6-tools-integration/exercises/analysis-reporterAnalysis Reporter
6. Exercise 5: Analysis Reporter (18 tests)
Goal: Generate human-readable text reports, JSON output, summary lines, and formatted tables from analysis findings.
Time: ~25 minutes
File to edit: exercises/analysis-reporter/starter/reporter.ml
Also provided (do not edit):
finding_types.ml-- unified finding types with all helperssample_findings.ml-- pre-built findings for testing
Dependencies: None (self-contained)
Types provided (not a TODO)
type report = {
program_name : string;
total_findings : int;
findings : Finding_types.finding list;
severity_counts : (Finding_types.severity * int) list;
category_counts : (Finding_types.category * int) list;
pass_counts : (string * int) list;
}
What to implement (in order)
| # | Function | Hint |
|---|---|---|
| 1 | build_report name findings | Fill in all report fields. Count severities, categories, and pass names. |
| 2 | format_text_report r | Header with "=== Analysis Report: name ===", total count, each formatted finding, severity breakdown |
| 3 | format_json_finding f | JSON object string with fields: id, category, severity, pass_name, location, message, suggestion (null if None) |
| 4 | format_json_report r | JSON object with fields: program, total, findings (array), severity_counts, category_counts |
| 5 | format_summary r | Empty: "Analysis of 'name': No findings." Non-empty: "Analysis of 'name': N findings (X Critical, Y High, ...)" -- only include non-zero severity counts |
| 6 | format_findings_table findings | Aligned text table with columns: Severity, Category, Pass, Location, Message |
| 7 | top_n_findings n findings | Sort by severity (highest first), take first n |
| 8 | findings_above_severity threshold findings | Keep findings where severity_to_int f.severity >= severity_to_int threshold |
Run tests
dune runtest modules/module6-tools-integration/exercises/analysis-reporter/
Starter output (all 18 tests error):
EEEEEEEEEEEEEEEEEE
Hints:
- For
format_json_finding, usePrintf.sprintfto build the JSON string. Escape quotes in string values if needed, but the test data does not contain embedded quotes. - For
format_summary, iterate overseverity_countsand build"X Critical, Y High"fragments, filtering out zero counts. - For
format_findings_table, compute the max width of each column first, then pad withPrintf.sprintf "%-*s".