#!/usr/bin/env rexx /******************************************************************************/ /* */ /* oracle.rex - Differential oracle: the RVM vs native ooRexx */ /* =================================================================== */ /* */ /* Usage: oracle.rex [-e] FILE.rex */ /* */ /* Runs FILE with run.rex, next to this file (the RVM under test: see */ /* make-oracle.sh and make-oracle-js.sh), AND with native ooRexx, and diffs */ /* the SAY output line by line. Exit 0 if they match, 1 otherwise. */ /* With -e, the standard error streams (trace output, error reports) are */ /* compared too. The exit codes are always compared. */ /* */ /* Deliberate differences: when FILE.expected exists next to FILE.rex (same */ /* name, .expected instead of .rex), its lines are the expected SAY output */ /* and replace the native one; the exit code is still compared with the */ /* native one. Use it only where the RVM differs ON PURPOSE (the */ /* built-in function errors follow the standard's 40.x codes, for instance). */ /* */ /* This file is part of the RVM, the Rexx Virtual Machine */ /* [See https://rexx.epbcn.com/rexx-parser/] */ /* */ /* Copyright (c) 2026 Josep Maria Blasco */ /* */ /* License: Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0) */ /* */ /******************************************************************************/ Parse Arg file file = Strip( file ) withErrors = .False If Word( file, 1 ) == "-e" Then Do withErrors = .True file = SubWord( file, 2 ) End here = FileSpec("Location", .context~package~name) Parse Value ExecCapture("rexx" here"run.rex" file) - With interpRC "00"x interp "00"x interpErr Parse Value ExecCapture("rexx" file) - With nativeRC "00"x native "00"x nativeErr interp = interp~makeArray("0a"x) native = native~makeArray("0a"x) -- A deliberate difference: the expected output replaces the native one. expectedFile = file If expectedFile~caselessEndsWith(".rex") Then expectedFile = Left( expectedFile, Length( expectedFile ) - 4 ) expectedFile = expectedFile".expected" source = "native" If Stream( expectedFile, "C", "Query Exists" ) \== "" Then Do native = .Array~new Do While Lines( expectedFile ) > 0 native~append( LineIn( expectedFile ) ) End Call Stream expectedFile, "C", "Close" source = "expected" End -- Compare the SAY output (standard output), line by line. If interp~items \== native~items Then Do Say "DIFF: line count differs. interpreter="interp~items source"="native~items Call Dump "int", interp Call Dump "nat", native Exit 1 End Loop i = 1 To native~items If interp[i] \== native[i] Then Do Say "DIFF at line" i":" Say " interpreter: ["interp[i]"]" Say " "Left( source":", 13 )"["native[i]"]" Exit 1 End End -- Compare the standard error streams, when asked to. If withErrors, interpErr \== nativeErr Then Do interpErr = interpErr~makeArray("0a"x) nativeErr = nativeErr~makeArray("0a"x) Loop i = 1 To Max( interpErr~items, nativeErr~items ) If interpErr[i] \== nativeErr[i] Then Leave End Say "DIFF in standard error at line" i":" Say " interpreter: ["interpErr[i]"]" Say " native: ["nativeErr[i]"]" Exit 1 End -- Compare the exit codes (so an error raised by the program is checked too: -- a Rexx error exits with -major, masked to 256-major by the OS on both sides). If interpRC \== nativeRC Then Do Say "DIFF: exit code differs. interpreter="interpRC "native="nativeRC Exit 1 End If source == "expected" Then Say "OK ("native~items "lines match the .expected file, rc" nativeRC")" Else Say "OK ("native~items "lines match, rc" nativeRC")" Exit 0 /* Run a command; return "rc" || "00"x || stdout || "00"x || stderr (lines */ /* joined with line feeds). */ ExecCapture: Procedure Use Strict Arg command Address System command With Output Stem out. Error Stem err. Return rc || "00"x || Joined( out. ) || "00"x || Joined( err. ) Joined: Procedure Use Strict Arg lines. text = "" Do i = 1 To lines.0 If i > 1 Then text = text || "0a"x text = text || lines.i End Return text Dump: Procedure Use Strict Arg label, arr Do i = 1 To arr~items Say " "label"["i"]: ["arr[i]"]" End Return