Loading…

Approval Diff Reporter

Approval testing trades a hand-written expected value for a stored baseline file: run the code, compare its output to what was approved last time, and if they differ, show a human-readable diff so someone can decide whether the change is a regression to fix or a deliberate update to accept. It suits anything whose exact output is easier to eyeball than to encode as individual assertions - a formatted report, a multi-line summary, a serialized config dump. AdrRunApproval does the comparing: it reads "<testName>.approved.txt" from the MQL4 file sandbox (an empty baseline if the file does not exist yet, which is the honest way to describe a first run), compares it against the actual output supplied, and on any mismatch writes that actual output to "<testName>.received.txt" alongside a diff report. The diff itself is a real line-based longest-common-subsequence comparison, not a naive same-index scan - inserting one line in the middle of a ten-line block reports as one insertion, not nine cascading "changed" lines the way index-by-index equality would. AdrApprove is the other half: once a human has looked at the received file and the diff and judged it correct, it promotes the received content to be the new approved baseline and clears the received file, so the next run starts clean. The diff algorithm here is a separate, independent implementation from any other diff tool elsewhere in this catalogue - every submission here is downloaded on its own and must not #include another project's header, so the LCS table (flattened into one 1-D array, since MQL4 cannot resize more than one dimension of a multi-dimensional array) is written fresh for this project rather than shared. Notes and limitations The LCS diff table is O(lines_in_A * lines_in_B) in time and memory and is capped at ADR_MAX_DIFF_LINES (200) lines per side - built for config dumps, formatted reports and similar short text, not for diffing multi-thousand-line logs; inputs longer than the cap are silently truncated for the diff comparison (AdrTextsEqual, used to decide pass/fail, is not truncated and compares the full text). Approved/received files live in MQL4\Files\ (or MQL5\Files\ on the native MQL5 build) named ADR_<testName>.approved.txt / .received.txt - there is no subfolder support, so test names should be unique within a project. AdrApprove has no undo; once a received file is promoted, the previous approved baseline is gone unless the caller has kept a copy of it elsewhere (a version control system tracking the .approved.txt file, if it is checked in alongside the test, is the natural place to recover a bad approval from). AdrRunApproval always leaves either a clean state (matched, no received file) or a mismatch state (received file present) - a caller wanting a hard CI failure on any unreviewed mismatch should treat a leftover .received.txt file at the start of a run as a build failure in its own right.

Script · MT5 · v1.0 · Free

About Approval Diff Reporter

Approval Diff Reporter is a script for MetaTrader 5. MQL source code included.

Files in the download: ApprovalDiffReporter.mq5.mqh, ApprovalDiffReporter.txt, ApprovalDiffReporterDemo.ex5, ApprovalDiffReporterDemo.mq5.

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria