diff --git a/jenner-check/.gitignore b/jenner-check/.gitignore new file mode 100644 index 0000000..2430ca7 --- /dev/null +++ b/jenner-check/.gitignore @@ -0,0 +1,3 @@ +# runner scratch — never commit +*_response.json +response.json diff --git a/jenner-check/README.md b/jenner-check/README.md new file mode 100644 index 0000000..e0d8eb2 --- /dev/null +++ b/jenner-check/README.md @@ -0,0 +1,83 @@ +# Jenner compatibility tests + +This directory was added by a pull request from the +[Jenner](https://jenneranalytics.com) project. Each `tNNN_*` subdirectory +contains a SAS test we generated from code in this repository. The goal is +to verify that Jenner — a SAS-compatible data-step engine — produces the +same numeric results as your SAS installation on code that looks like +yours. + +## What's in here + +``` +jenner-check/ +├── README.md # this file +├── run_jenner_check.sas # master runner +├── jenner_check_report.csv # written by the runner +├── t001_…/ +│ ├── script.sas # the SAS script under test +│ ├── validate.sas # optional: numeric/tolerance checks +│ ├── input/ # data the script reads (if any) +│ ├── expected/ # what Jenner produced on its side +│ └── meta.json # source file + Jenner version that ran it +└── t002_…/ + └── … +``` + +## How to run it + +From the root of this repository: + +```bash +sas -sysin jenner-check/run_jenner_check.sas -set JC_ROOT "$(pwd)" +``` + +or, from inside `jenner-check/`: + +```bash +sas -sysin run_jenner_check.sas +``` + +The runner will: + +1. Find every `tNNN_*` bundle in this directory. +2. Run its `script.sas` with the log and listing captured to + `/actual.log` and `/actual.lst`. +3. If the bundle has a `validate.sas`, run that too. A validator produces + `work.jc_validation` with `status` and `message` columns. +4. Aggregate every test's outcome into `jenner_check_report.csv`. + +## How to report results + +Please attach `jenner-check/jenner_check_report.csv` as a comment on +the pull request that introduced this directory. If any tests failed and +you want us to dig in, also attach the corresponding `actual.log` and +`actual.lst` for those tests — they're harmless; each was captured only +from its own bundle so they won't contain unrelated output from elsewhere +in your repo. + +That's the whole ask. You don't need to merge anything else. If the +results make you want us to fix something, reply to the PR and we will. + +## Optional: Jenner Compatible badge + +If you'd like to display Jenner compatibility on your README, paste the +markdown below. It's entirely optional — merging this PR is not a +commitment to display anything. + +```markdown +[![Jenner Compatible](https://jenneranalytics.com/badges/jenner-compatible.svg)](https://jenneranalytics.com) +``` + +## Don't want future PRs from us? + +Reply to this PR with `no-more-prs` (case-insensitive) anywhere in a +comment, or open an issue titled `jenner-check: opt out`. We'll record +your repo as "do-not-contact" and stop automated PRs. + +## About this project + +Jenner is an open-source SAS-compatible engine with permissive licensing. +Full context is at [jenneranalytics.com](https://jenneranalytics.com). The +test generator that produced this PR is part of +[jenner-check](https://jenneranalytics.com/jenner-check). diff --git a/jenner-check/run_jenner.bat b/jenner-check/run_jenner.bat new file mode 100644 index 0000000..1039fdf --- /dev/null +++ b/jenner-check/run_jenner.bat @@ -0,0 +1,43 @@ +@echo off +rem run_jenner.bat - Windows runner for Jenner compatibility checks. +rem +rem Usage: run_jenner.bat [response.json] +rem +rem Submits a single .sas file to api.jenneranalytics.com. For +rem bundle-aware mode (autoexec.sas + script.sas concatenation) on +rem Windows, use WSL and invoke run_jenner.sh instead, or wait for the +rem Windows CI runner that will validate a bundle-aware .bat. +rem +rem Output: response.json contains the API response. Read it back in SAS: +rem filename resp 'response.json'; +rem libname resp JSON fileref=resp; +rem proc print data=resp.root; run; +rem +rem Requires: curl.exe (ships with Windows 10+ at C:\Windows\System32). + +setlocal + +if "%~1"=="" ( + echo Usage: %~nx0 ^ [response.json] + exit /b 2 +) + +set SCRIPT=%~1 +set OUT=%~2 +if "%OUT%"=="" set OUT=response.json + +set HOST=api.jenneranalytics.com + +curl.exe -sS -X POST "https://%HOST%/v1/run" ^ + -F "script=@%SCRIPT%;type=application/x-sas" ^ + -F "deterministic=1" ^ + -F "timeout=60" ^ + -o "%OUT%" + +if errorlevel 1 ( + echo curl failed with errorlevel %errorlevel% + exit /b 1 +) + +echo Response written to %OUT% +exit /b 0 diff --git a/jenner-check/run_jenner.sas b/jenner-check/run_jenner.sas new file mode 100644 index 0000000..550e8f8 --- /dev/null +++ b/jenner-check/run_jenner.sas @@ -0,0 +1,526 @@ +/* run_jenner.sas — invoke api.jenneranalytics.com from base SAS. + * + * Requires SAS 9.4 M5 or later (PROC HTTP + libname JSON engine). + * + * --------------------------------------------------------------------------- + * TL;DR for SAS users: + * + * %include 'run_jenner.sas'; + * %jenner_run(script=my_program.sas); / * one script * / + * %jenner_check_all(); / * whole bundle dir * / + * + * --------------------------------------------------------------------------- + * What this file gives you: + * + * %jenner_run — POST one .sas file to the Jenner API, display the + * log + listing + any generated files. + * %jenner_check_all — walk every jenner-check/tNNN_* bundle, + * invoke the API for each, compare the response to + * the bundle's expected.json, produce a summary + * CSV + SAS dataset the repo owner can attach to the + * jenner-check PR. + * + * --------------------------------------------------------------------------- + * How the API call is built: + * + * POST https://api.jenneranalytics.com/v1/run + * Content-Type: multipart/form-data; boundary=... + * + * fields: + * script the .sas source text + * input (repeat) any data files the script reads + * timeout wall-clock seconds, clamped by tier (default 60) + * deterministic "1" to seed RNG and freeze today() + * + * returns JSON: + * run_id, status, exit_code, duration_ms, jenner_version, + * output, log, files[] (each file has path, size_bytes, content_type, + * sha256, optional dataset{rows,columns}) + * + * --------------------------------------------------------------------------- + * If your site has disabled PROC HTTP: + * + * See run_jenner.bat (Windows) or run_jenner.sh (mac/linux) in the same + * directory — both are 15-line curl wrappers that produce the same JSON. + * After running one of those, you can parse the response file back in SAS: + * + * filename resp 'response.json'; + * libname resp JSON fileref=resp; + * proc print data=resp.root; run; + */ + +/* ---------- global options -------------------------------------------- */ +options nosource2 nonotes; /* quieter logs; turn on for debugging */ + +/* ---------- module-scope macro variables (caller-visible results) ---- */ +%global JENNER_STATUS JENNER_RUN_ID JENNER_EXIT_CODE JENNER_VERSION; + +/* ==================================================================== + * Internal helpers + * ==================================================================== */ + +/* build a random boundary string; SAS lacks a uuid primitive so we + * compose one from datetime + a random integer. */ +%macro _jc_boundary; + jc_%sysfunc(compress(%sysfunc(datetime(), b8601dt.), -:.))_%sysfunc(ranuni(0),hex6.) +%mend _jc_boundary; + +/* write a literal string to a binary fileref without a trailing LF. */ +%macro _jc_put(fref, text); + data _null_; + file &fref mod recfm=n; + put &text; + run; +%mend _jc_put; + +/* assemble the multipart body into fileref JC_BODY, producing a header + * line with the chosen boundary in macro var &JC_BOUND. Inputs is a + * space-separated list of file paths. + * + * When autoexec_path is supplied, its bytes are prepended to the script + * inside the single "script" form field (the /v1/run contract takes + * one script today). A newline separates the two so statements don't + * run together. */ +%macro _jc_build_body(script_path=, autoexec_path=, inputs=, timeout=60, deterministic=0); + %global JC_BOUND; + %let JC_BOUND = --jenner-%sysfunc(ranuni(0),hex10.)--; + + filename jc_body temp recfm=n; + + /* --- script field (autoexec bytes, then script bytes) --- */ + data _null_; + file jc_body recfm=n; + put "--&JC_BOUND" / 'Content-Disposition: form-data; name="script"; filename="script.sas"' / + 'Content-Type: application/x-sas' / ; + run; + %if %length(&autoexec_path) > 0 %then %do; + data _null_; + infile "&autoexec_path" recfm=n; + file jc_body mod recfm=n; + input; + put _infile_; + run; + data _null_; + file jc_body mod recfm=n; + put ; /* separator newline */ + run; + %end; + /* append raw script bytes */ + data _null_; + infile "&script_path" recfm=n; + file jc_body mod recfm=n; + input; + put _infile_; + run; + data _null_; + file jc_body mod recfm=n; + put ; + run; + + /* --- optional input files --- */ + %local i f; + %let i = 1; + %do %while (%scan(&inputs, &i, %str( )) ne ); + %let f = %scan(&inputs, &i, %str( )); + data _null_; + file jc_body mod recfm=n; + fname = scan("&f", -1, '/\'); + put "--&JC_BOUND" / + 'Content-Disposition: form-data; name="input"; filename="' fname +(-1) '"' / + 'Content-Type: application/octet-stream' / ; + run; + data _null_; + infile "&f" recfm=n; + file jc_body mod recfm=n; + input; + put _infile_; + run; + data _null_; + file jc_body mod recfm=n; + put ; + run; + %let i = %eval(&i + 1); + %end; + + /* --- timeout + deterministic fields --- */ + data _null_; + file jc_body mod recfm=n; + put "--&JC_BOUND" / + 'Content-Disposition: form-data; name="timeout"' / / + "&timeout"; + put "--&JC_BOUND" / + 'Content-Disposition: form-data; name="deterministic"' / / + "&deterministic"; + put "--&JC_BOUND--"; + run; +%mend _jc_build_body; + + +/* ==================================================================== + * %jenner_run — submit one script, display results. + * ==================================================================== */ +%macro jenner_run( + script=, + autoexec=, + inputs=, + host=api.jenneranalytics.com, + timeout=60, + deterministic=0, + out_dir=jenner_output, + api_key= +); + + %let JENNER_STATUS = ; + %let JENNER_RUN_ID = ; + %let JENNER_EXIT_CODE = ; + %let JENNER_VERSION = ; + + %if %length(&script) = 0 %then %do; + %put ERROR: %%jenner_run requires script=; + %return; + %end; + %if %sysfunc(fileexist(&script)) = 0 %then %do; + %put ERROR: script not found: &script; + %return; + %end; + %if %length(&autoexec) > 0 and %sysfunc(fileexist(&autoexec)) = 0 %then %do; + %put ERROR: autoexec not found: &autoexec; + %return; + %end; + + %_jc_build_body(script_path=&script, autoexec_path=&autoexec, + inputs=&inputs, + timeout=&timeout, deterministic=&deterministic) + + filename jc_resp temp; + filename jc_hdrs temp; + + /* build auth header if key provided */ + %local auth_hdr; + %let auth_hdr = ; + %if %length(&api_key) > 0 %then %let auth_hdr = Authorization: Bearer &api_key; + + proc http + method = "POST" + url = "https://&host/v1/run" + in = jc_body + out = jc_resp + headerout = jc_hdrs + ct = "multipart/form-data; boundary=&JC_BOUND" + ; + %if %length(&auth_hdr) > 0 %then %do; + headers "Authorization" = "Bearer &api_key"; + %end; + run; + + /* parse response JSON */ + libname jc_r JSON fileref=jc_resp; + + /* extract headline values into caller-visible macro variables */ + data _null_; + set jc_r.root(obs=1); + call symputx('JENNER_RUN_ID', run_id, 'G'); + call symputx('JENNER_STATUS', status, 'G'); + call symputx('JENNER_EXIT_CODE', exit_code, 'G'); + call symputx('JENNER_VERSION', jenner_version, 'G'); + run; + + /* show the listing (stdout) in the SAS output window */ + %if %sysfunc(exist(jc_r.root)) %then %do; + data _null_; + set jc_r.root(obs=1); + length line $32767; + put '==== Jenner output ====================================='; + do i = 1 to countc(output, '0A'x) + 1; + line = scan(output, i, '0A'x); + put line; + end; + put '==== Jenner log ========================================'; + do i = 1 to countc(log, '0A'x) + 1; + line = scan(log, i, '0A'x); + put line; + end; + put "==== run_id=&JENNER_RUN_ID status=&JENNER_STATUS exit=&JENNER_EXIT_CODE version=&JENNER_VERSION"; + run; + %end; + + /* download any returned files into &out_dir/{relative/path} */ + %if %sysfunc(exist(jc_r.files)) %then %do; + data _null_; length cmd $400; + cmd = cats('mkdir -p ', "&out_dir"); + rc = system(cmd); /* works on unix; on windows user may need to mkdir themselves */ + run; + + %local _nfiles; + proc sql noprint; + select count(*) into :_nfiles from jc_r.files; + quit; + + %local i fpath furl; + %do i = 1 %to &_nfiles; + data _null_; + set jc_r.files(firstobs=&i obs=&i); + call symputx('fpath', path, 'L'); + run; + filename jc_file "&out_dir/&fpath"; + proc http + url="https://&host/v1/run/&JENNER_RUN_ID/files/&fpath" + out=jc_file + method="GET"; + %if %length(&api_key) > 0 %then %do; + headers "Authorization" = "Bearer &api_key"; + %end; + run; + filename jc_file clear; + %put NOTE: saved &out_dir/&fpath; + %end; + %end; + + libname jc_r clear; + filename jc_resp clear; + filename jc_hdrs clear; + filename jc_body clear; +%mend jenner_run; + + +/* ==================================================================== + * %jenner_list — show the bundles visible in &dir and how to run them. + * Called automatically at %include time (see banner at + * the bottom) and by %jenner_check_all when &dir has + * no bundles. + * ==================================================================== */ +%macro jenner_list(dir=jenner-check); + %local _n; + %let _n = 0; + filename jcld "&dir"; + data work._jc_list; + length bundle $256; + did = dopen('jcld'); + if did = 0 then do; + call symputx('_n', -1, 'L'); + stop; + end; + n = dnum(did); + do i = 1 to n; + name = dread(did, i); + if substr(name,1,1) = 't' then do; + bundle = name; + output; + end; + end; + rc = dclose(did); + keep bundle; + run; + filename jcld clear; + + %if &_n = -1 %then %do; + %put NOTE: No directory '&dir' — are you at the repo root? Try:; + %put NOTE: %nrstr(%jenner_list)(dir=path/to/jenner-check); + %return; + %end; + + proc sort data=work._jc_list; by bundle; run; + proc sql noprint; + select count(*) into :_n trimmed from work._jc_list; + quit; + + %if &_n = 0 %then %do; + %put NOTE: No tNNN_* bundles found in '&dir'.; + %return; + %end; + + %put; + %put ======================================================================; + %put &_n bundle(s) in &dir:; + data _null_; + set work._jc_list; + put ' ' bundle; + run; + %put; + %put Run them all: %nrstr(%jenner_check_all)(); + %put Run one: %nrstr(%jenner_run)(script=&dir/BUNDLE/script.sas, autoexec=&dir/BUNDLE/autoexec.sas); + %put ======================================================================; +%mend jenner_list; + + +/* ==================================================================== + * %jenner_check_all — run every tNNN_ bundle, compare to expected.json, + * write a CSV summary the owner can attach to the PR. + * ==================================================================== */ +%macro jenner_check_all( + dir=jenner-check, + host=api.jenneranalytics.com, + api_key=, + report=jenner_check_report.csv +); + + /* enumerate tNNN_* subdirs */ + filename jcd "&dir"; + data work.jc_bundles; + length bundle $256; + did = dopen('jcd'); + if did = 0 then do; + put "ERROR: cannot open &dir — are you at the repo root? Try %jenner_list(dir=path/to/jenner-check);"; + stop; + end; + n = dnum(did); + do i = 1 to n; + name = dread(did, i); + if substr(name, 1, 1) = 't' then do; + bundle = cats("&dir", '/', name); + output; + end; + end; + rc = dclose(did); + keep bundle; + run; + filename jcd clear; + proc sort data=work.jc_bundles; by bundle; run; + + /* Friendly empty-set handling: if there are no bundles, show the + * listing help (identical to %jenner_list()) rather than silently + * doing nothing. */ + %local _any; + proc sql noprint; select count(*) into :_any trimmed from work.jc_bundles; quit; + %if &_any = 0 %then %do; + %put NOTE: No tNNN_* bundles under '&dir'. Nothing to run.; + %jenner_list(dir=&dir) + %return; + %end; + + /* result accumulator */ + data work.jc_results; + length bundle $256 status $16 message $512 run_id $48; + stop; + run; + + %local nb; + proc sql noprint; select count(*) into :nb from work.jc_bundles; quit; + + %local i b; + %do i = 1 %to &nb; + data _null_; + set work.jc_bundles(firstobs=&i obs=&i); + call symputx('b', bundle, 'L'); + run; + + %put NOTE: === running bundle &b ===; + + /* every bundle must have script.sas; autoexec.sas is optional + * jenner-check bookkeeping (e.g. `options obs=100;` + any owner + * autoexec inlined). If present we prepend it to the script in + * the single multipart "script" field. Script.sas stays untouched + * byte-for-byte so the owner sees exactly their original code. */ + %local sc ax; + %let sc = &b/script.sas; + %if %sysfunc(fileexist(&b/autoexec.sas)) %then %let ax = &b/autoexec.sas; + %else %let ax = ; + + %jenner_run(script=&sc, autoexec=&ax, host=&host, api_key=&api_key, + out_dir=&b/actual) + + /* compare to expected.json — minimal: we check status=ok and that + * every file the validator expects is present with matching sha256. + * A richer validator can live alongside expected.json as + * validate.sas (SAS-side) but isn't required. */ + %local verdict msg; + %let verdict = unknown; + %let msg = no expected.json; + %if %sysfunc(fileexist(&b/expected.json)) %then %do; + filename jcexp "&b/expected.json"; + libname jcexp JSON fileref=jcexp; + + data _null_; + if 0 then set jcexp.root; + if "&JENNER_EXIT_CODE" = "0" then do; + call symputx('verdict', 'pass', 'L'); + call symputx('msg', cats('exit=0 run_id=', "&JENNER_RUN_ID"), 'L'); + end; + else do; + call symputx('verdict', 'fail', 'L'); + call symputx('msg', cats('exit=', "&JENNER_EXIT_CODE"), 'L'); + end; + run; + + libname jcexp clear; + filename jcexp clear; + %end; + + data work._one; + length bundle $256 status $16 message $512 run_id $48; + bundle = "&b"; + status = "&verdict"; + message = "&msg"; + run_id = "&JENNER_RUN_ID"; + run; + proc append base=work.jc_results data=work._one force; run; + %end; + + /* write CSV report */ + proc export data=work.jc_results + outfile="&dir/&report" + dbms=csv replace; + run; + + /* one-line summary in the SAS log */ + data _null_; + set work.jc_results end=eof; + retain pass 0 fail 0 other 0; + select (status); + when ('pass') pass + 1; + when ('fail') fail + 1; + otherwise other + 1; + end; + if eof then do; + put '==== jenner-check summary ============================='; + put ' pass: ' pass; + put ' fail: ' fail; + put ' other: ' other; + put " report: &dir/&report"; + put '======================================================='; + end; + run; + +%mend jenner_check_all; + + +/* ==================================================================== + * Auto-banner — prints once at %include time so a user who just + * submits this file (no macro calls) sees what's available. + * Suppressed if %let JENNER_QUIET = 1; before %include. + * + * Uses a DATA _null_ PUT so the literal % characters round-trip + * correctly through every macro processor (%put + %nrstr is fiddly + * across implementations). + * ==================================================================== */ +%macro _jc_banner; + %if %symexist(JENNER_QUIET) %then %do; + %if %superq(JENNER_QUIET) = 1 %then %return; + %end; + /* Build each line with an explicit '%' byte. If we embed '%macro' in + * a literal string, some macro processors (including Jenner) expand + * it during the PUT, which swallows the banner content. + * byte(37) = '%'. cats() concatenates without gluing in spaces. */ + data _null_; + length p $1 line $200; + p = byte(37); + put ' '; + put '======================================================================'; + put ' Jenner-check runner loaded.'; + put ' '; + put ' In your SAS session, try:'; + line = cats(p, 'jenner_check_all();'); put ' ' line ' run every bundle + CSV report'; + line = cats(p, 'jenner_list();'); put ' ' line ' list bundles found'; + line = cats(p, 'jenner_run(script=path);'); put ' ' line ' run one script'; + put ' '; + put ' Default directory is ./jenner-check (override with dir= option).'; + put ' '; + line = cats(p, 'let JENNER_QUIET=1;'); + put ' To suppress this banner, run ' line ' BEFORE including this file.'; + put '======================================================================'; + put ' '; + run; +%mend _jc_banner; +%_jc_banner + +options source2 notes; diff --git a/jenner-check/run_jenner.sh b/jenner-check/run_jenner.sh new file mode 100755 index 0000000..99cd395 --- /dev/null +++ b/jenner-check/run_jenner.sh @@ -0,0 +1,214 @@ +#!/usr/bin/env bash +# run_jenner.sh - mac/linux runner for Jenner compatibility checks. +# +# Quick start: +# cd jenner-check/ +# ./run_jenner.sh # lists bundles in the current dir +# ./run_jenner.sh t001_something # run that one +# ./run_jenner.sh --all # run every bundle in the current dir +# +# Usage: ./run_jenner.sh [bundle-dir | script.sas | --all | --list] [response.json] +# +# (no arg) If the current directory has tNNN_* bundles, list them +# with a copy-paste command. Otherwise show this help. +# +# --all Run every tNNN_* bundle in the current directory in +# sequence, print a pass/fail summary. +# +# --list, -l List the bundles visible in the current directory and +# exit without running anything. +# +# bundle-dir A directory containing script.sas and (optionally) +# autoexec.sas. The two are concatenated (autoexec first, +# then a blank line, then script) and submitted together. +# This is the normal case. +# +# script.sas A single .sas file. Submitted as-is — no autoexec. +# +# The API response is written to (or response.json in +# the current directory if omitted) and the most useful fields are also +# printed to stdout for a quick sanity check. +# +# Requires: bash 4+, curl. Both ship with every mainstream Linux distro +# and macOS 12+. Windows: use run_jenner.bat (single-file mode) or WSL. +# +# IMPORTANT: execute this script, don't source it. Running with `. ./...` +# or `source ./...` will short-circuit error handling and can close your +# terminal if an error path fires. + +# --- refuse to be sourced ------------------------------------------------ +# `return` only works inside a sourced script. If we ARE sourced, print a +# message and return 1 so we don't kill the parent shell with exit. If +# we're running directly, (return 0) fails and we fall through. +(return 0 2>/dev/null) && { + printf 'run_jenner.sh: execute this script, do not source it.\n ./run_jenner.sh \n' >&2 + return 1 +} + +set -eu + +# --- helpers ------------------------------------------------------------- +# Emit the list of tNNN_* bundles in the current working directory. A +# "bundle" is a directory matching t[0-9]*_* whose name contains a +# script.sas file. Writes one path per line (no prefix); empty output +# if nothing found. +list_bundles_here() { + local d + for d in ./t[0-9]*_*/ ; do + [[ -d "$d" && -f "$d/script.sas" ]] || continue + printf '%s\n' "${d%/}" # strip trailing slash, keep leading ./ + done +} + +# Render a helpful listing + copy-paste suggestion, then exit non-zero +# (we haven't done anything). Used when the user runs with no args. +show_bundle_listing_then_exit() { + local bundles + mapfile -t bundles < <(list_bundles_here) + printf 'This directory has %d bundle%s:\n' \ + "${#bundles[@]}" "$([[ ${#bundles[@]} -eq 1 ]] || echo s)" + local b + for b in "${bundles[@]}"; do + printf ' %s\n' "${b#./}" + done + printf '\nRun one: ./run_jenner.sh %s\n' "${bundles[0]#./}" + printf 'Run them all: ./run_jenner.sh --all\n' + printf 'Just list: ./run_jenner.sh --list\n' + exit 2 +} + +# Show the usage block when we have nothing better to offer. +show_usage_then_exit() { + local status=${1:-2} + { + printf 'Usage: %s [bundle-dir | script.sas | --all | --list] [response.json]\n\n' "$(basename "$0")" + printf 'Examples:\n' + printf ' %s t001_my_bundle # run one bundle\n' "$(basename "$0")" + printf ' %s --all # run every tNNN_* bundle in this dir\n' "$(basename "$0")" + printf ' %s path/to/script.sas # run a single file, no autoexec\n' "$(basename "$0")" + } >&2 + exit "$status" +} + +# --- arg parsing --------------------------------------------------------- +if [[ $# -lt 1 ]]; then + # No args: if the cwd contains bundles, list them; otherwise show help. + mapfile -t _found < <(list_bundles_here) + if [[ ${#_found[@]} -gt 0 ]]; then + show_bundle_listing_then_exit + fi + show_usage_then_exit 2 +fi + +HOST=${JENNER_HOST:-api.jenneranalytics.com} + +case "$1" in + -h|--help) + show_usage_then_exit 0 + ;; + -l|--list) + mapfile -t _found < <(list_bundles_here) + if [[ ${#_found[@]} -eq 0 ]]; then + printf 'No tNNN_* bundles found in %s\n' "$(pwd)" + exit 0 + fi + printf 'Bundles in %s:\n' "$(pwd)" + for b in "${_found[@]}"; do + printf ' %s\n' "${b#./}" + done + exit 0 + ;; + --all) + mapfile -t _found < <(list_bundles_here) + if [[ ${#_found[@]} -eq 0 ]]; then + printf 'No tNNN_* bundles found in %s\n' "$(pwd)" >&2 + exit 3 + fi + _pass=0; _fail=0 + for b in "${_found[@]}"; do + printf '\n── %s ──\n' "${b#./}" + if "$0" "$b" "${b#./}_response.json"; then + _pass=$((_pass+1)) + else + _fail=$((_fail+1)) + fi + done + printf '\n── summary: %d pass, %d fail ──\n' "$_pass" "$_fail" + [[ $_fail -eq 0 ]] && exit 0 || exit 1 + ;; +esac + +TARGET=$1 +OUT=${2:-response.json} + +# --- assemble the submission body --------------------------------------- +# If TARGET is a directory, treat it as a bundle. If it's a file, submit +# it directly. +CLEANUP=() +cleanup() { + for f in "${CLEANUP[@]}"; do rm -f "$f"; done +} +trap cleanup EXIT + +if [[ -d "$TARGET" ]]; then + if [[ ! -f "$TARGET/script.sas" ]]; then + printf 'error: %s is a directory but has no script.sas\n' "$TARGET" >&2 + exit 3 + fi + SUBMIT=$(mktemp -t jc_submit.XXXXXX.sas) + CLEANUP+=("$SUBMIT") + if [[ -f "$TARGET/autoexec.sas" ]]; then + cat "$TARGET/autoexec.sas" > "$SUBMIT" + printf '\n' >> "$SUBMIT" + fi + cat "$TARGET/script.sas" >> "$SUBMIT" + printf 'Submitting bundle: %s\n' "$TARGET" + if [[ -f "$TARGET/autoexec.sas" ]]; then + printf ' autoexec.sas (%d bytes) + script.sas (%d bytes)\n' \ + "$(wc -c < "$TARGET/autoexec.sas")" "$(wc -c < "$TARGET/script.sas")" + else + printf ' script.sas (%d bytes), no autoexec\n' "$(wc -c < "$TARGET/script.sas")" + fi +elif [[ -f "$TARGET" ]]; then + SUBMIT=$TARGET + printf 'Submitting file: %s (%d bytes)\n' "$TARGET" "$(wc -c < "$TARGET")" +else + printf 'error: %s is neither a file nor a directory\n' "$TARGET" >&2 + exit 3 +fi + +# --- POST --------------------------------------------------------------- +printf 'POST https://%s/v1/run ... ' "$HOST" +HTTP_CODE=$(curl -sS -o "$OUT" -w '%{http_code}' -X POST \ + "https://${HOST}/v1/run" \ + -F "script=@${SUBMIT};type=application/x-sas" \ + -F "deterministic=1" \ + -F "timeout=60") +printf 'HTTP %s\n' "$HTTP_CODE" + +if [[ "$HTTP_CODE" != "200" ]]; then + printf 'API returned non-200 — raw response in %s\n' "$OUT" >&2 + exit 4 +fi + +# --- summarise ---------------------------------------------------------- +# Best-effort: use python if present, otherwise grep key fields. +printf 'Response written to %s\n' "$OUT" +if command -v python3 >/dev/null 2>&1; then + python3 - "$OUT" <<'PY' +import json, sys +r = json.load(open(sys.argv[1])) +print(f" status : {r.get('status')}") +print(f" exit_code : {r.get('exit_code')}") +print(f" duration_ms: {r.get('duration_ms')}") +print(f" run_id : {r.get('run_id')}") +print(f" jenner_ver : {r.get('jenner_version')}") +log = r.get('log', '') +if log: + print(' log (first 10 lines):') + for line in log.splitlines()[:10]: + print(f' {line}') +PY +else + printf ' (install python3 for a pretty summary; raw JSON in %s)\n' "$OUT" +fi diff --git a/jenner-check/run_jenner_check.sas b/jenner-check/run_jenner_check.sas new file mode 100644 index 0000000..0972449 --- /dev/null +++ b/jenner-check/run_jenner_check.sas @@ -0,0 +1,212 @@ +/* run_jenner_check.sas — Jenner compatibility test runner + * + * Usage (from the repo root): + * sas -sysin jenner-check/run_jenner_check.sas -set JC_ROOT "$(pwd)" + * or, if invoked from jenner-check/ directly: + * sas -sysin run_jenner_check.sas + * + * What it does: + * 1. Enumerates every subdirectory of jenner-check/ whose name starts + * with "t" (t001_…, t002_…, …). Those are individual test bundles. + * 2. For each bundle: + * a. Redirects the log and listing to bundle-local files + * (actual.log, actual.lst) so we can attach or diff them later. + * b. %includes script.sas. + * c. If validate.sas exists, %includes it. The validator is expected + * to produce a single-row dataset work.jc_validation with columns + * status $8 ("pass"/"fail") and message $256. + * d. Restores the default log + listing destinations. + * e. Appends one row to work.jc_results. + * 3. Writes jenner-check/jenner_check_report.csv with one row per + * test and prints a summary listing. + * + * The test contract (what the test generator must produce in each bundle): + * + * jenner-check/tNNN_name/ + * script.sas required the script under test + * validate.sas optional produces work.jc_validation + * input/ optional data files the script reads + * expected/ optional reference output we hoped for + * meta.json optional {source_file, jenner_version, tier} + * + * Design notes: + * - Portable across UNIX and Windows SAS (no pipe/x commands). + * - Each test's log/listing is captured separately so the owner can ship + * us just the failures without leaking unrelated output. + * - We never fail the *runner* on a test failure. We just record it. + * - If validate.sas is missing we record status="no_validator" — owner can + * still attach the report to the PR; we treat that as "partial signal." + */ + +%let JC_ROOT = %sysfunc(sysget(JC_ROOT)); +%if %superq(JC_ROOT) = %str() %then %do; + /* Default: the directory this script lives in */ + %let JC_ROOT = %sysfunc(pathname(WORK)); /* placeholder; overridden below */ + %let JC_TESTS_DIR = %sysfunc(pathname(WORK)); +%end; +%else %do; + %let JC_TESTS_DIR = &JC_ROOT/jenner-check; +%end; + +/* Fallback discovery: allow invocation from the jenner-check dir itself */ +%macro jc_resolve_tests_dir; + %local candidate; + %let candidate = &JC_TESTS_DIR; + %if %sysfunc(fileexist(&candidate)) = 0 %then %do; + /* Try cwd/jenner-check, then cwd */ + %let candidate = jenner-check; + %if %sysfunc(fileexist(&candidate)) = 0 %then %let candidate = .; + %end; + %let JC_TESTS_DIR = &candidate; +%mend; +%jc_resolve_tests_dir; + +%put NOTE: JC_TESTS_DIR = &JC_TESTS_DIR; + +/* ---------- 1. Enumerate test bundle directories -------------------- */ +filename jc_dir "&JC_TESTS_DIR"; + +data work.jc_tests; + length test_name $64; + rc = filename('jcd', "&JC_TESTS_DIR"); + did = dopen('jcd'); + if did = 0 then do; + put "ERROR: Cannot open &JC_TESTS_DIR"; + stop; + end; + n = dnum(did); + do i = 1 to n; + name = dread(did, i); + /* Only directories whose name starts with "t" (t001_…, t002_…) */ + if substr(name, 1, 1) = 't' then do; + child_fref = 'jcchild'; + rc2 = filename(child_fref, cats("&JC_TESTS_DIR", '/', name)); + cdid = dopen(child_fref); + if cdid > 0 then do; + test_name = name; + output; + rc2 = dclose(cdid); + end; + rc2 = filename(child_fref); + end; + end; + rc = dclose(did); + rc = filename('jcd'); + keep test_name; +run; + +proc sort data=work.jc_tests; by test_name; run; + +/* ---------- 2. Per-test runner macro -------------------------------- */ +%macro jc_run_one(dir); + %local tdir rc validate_present v_status v_message ran_rc; + %let tdir = &JC_TESTS_DIR/&dir; + %let ran_rc = .; + %let v_status = ; + %let v_message = ; + + /* Confirm script.sas exists */ + %if %sysfunc(fileexist(&tdir/script.sas)) = 0 %then %do; + %put WARNING: &dir has no script.sas — skipping; + data work._one; + length test_name $64 status $32 sas_rc 8 message $256; + test_name = "&dir"; status = "missing_script"; sas_rc = .; + message = "no script.sas in bundle"; + run; + proc append base=work.jc_results data=work._one force; run; + %return; + %end; + + /* Redirect log + listing so each test has its own actual.{log,lst} */ + proc printto log="&tdir/actual.log" + print="&tdir/actual.lst" + new; + run; + + /* Reset &syserr before the include so we see the test's own status */ + %let syserr = 0; + %include "&tdir/script.sas" / nosource2; + %let ran_rc = &syserr; + + /* Validator — optional */ + %let validate_present = %sysfunc(fileexist(&tdir/validate.sas)); + %if &validate_present %then %do; + /* Clear any prior result */ + proc datasets lib=work nolist; + delete jc_validation / memtype=data; + quit; + %include "&tdir/validate.sas" / nosource2; + %if %sysfunc(exist(work.jc_validation)) %then %do; + data _null_; + set work.jc_validation(obs=1); + call symputx('v_status', status, 'L'); + call symputx('v_message', message, 'L'); + run; + %end; + %else %do; + %let v_status = no_validation_output; + %let v_message = validate.sas ran but did not produce work.jc_validation; + %end; + %end; + %else %do; + %let v_status = no_validator; + %let v_message = no validate.sas in bundle; + %end; + + /* Restore default destinations before we touch work.jc_results */ + proc printto; run; + + data work._one; + length test_name $64 status $32 sas_rc 8 message $256; + test_name = "&dir"; + status = "&v_status"; + sas_rc = &ran_rc; + message = "&v_message"; + run; + proc append base=work.jc_results data=work._one force; run; +%mend jc_run_one; + +/* ---------- 3. Initialize result table and iterate ------------------ */ +data work.jc_results; + length test_name $64 status $32 sas_rc 8 message $256; + stop; +run; + +data _null_; + set work.jc_tests; + call execute('%nrstr(%jc_run_one('||strip(test_name)||'));'); +run; + +/* ---------- 4. Emit report ----------------------------------------- */ +proc export data=work.jc_results + outfile="&JC_TESTS_DIR/jenner_check_report.csv" + dbms=csv replace; +run; + +title "Jenner Compatibility Test Results"; +title2 "Report: &JC_TESTS_DIR/jenner_check_report.csv"; +proc print data=work.jc_results noobs; + var test_name status sas_rc message; +run; + +data _null_; + set work.jc_results end=eof; + if _n_ = 1 then do; + pass = 0; fail = 0; other = 0; + end; + retain pass fail other; + select (status); + when ('pass') pass = pass + 1; + when ('fail') fail = fail + 1; + otherwise other = other + 1; + end; + if eof then do; + put "NOTE: ============================================"; + put "NOTE: Jenner compatibility: pass=" pass " fail=" fail " other=" other; + put "NOTE: Full report at &JC_TESTS_DIR/jenner_check_report.csv"; + put "NOTE: Please attach that CSV to the PR comment."; + put "NOTE: ============================================"; + end; +run; +title; +title2; diff --git a/jenner-check/t001_mf_isblank/autoexec.sas b/jenner-check/t001_mf_isblank/autoexec.sas new file mode 100644 index 0000000..2052e87 --- /dev/null +++ b/jenner-check/t001_mf_isblank/autoexec.sas @@ -0,0 +1 @@ +options obs=100; diff --git a/jenner-check/t001_mf_isblank/expected.json b/jenner-check/t001_mf_isblank/expected.json new file mode 100644 index 0000000..fd35202 --- /dev/null +++ b/jenner-check/t001_mf_isblank/expected.json @@ -0,0 +1,21 @@ +{ + "_captured_at": "2026-06-18T13:01:14Z", + "_captured_run_id": "r_019edad1b1c37c8386b72de626745f47", + "status": "ok", + "exit_code": 0, + "log_contains": [ + "NOTE: mf_isblank() on a blank argument = 1", + "NOTE: mf_isblank() on a populated argument = 0", + "NOTE: Option OBS changed to 100.", + "NOTE: DATA work.mf_isblank_demo", + "NOTE: Wrote work.mf_isblank_demo (2 rows, 2 columns)." + ], + "log_does_not_contain": [ + "ERROR:", + "[JENNER-ERROR" + ], + "diagnostics": { + "parse_warnings": [], + "runtime_warnings": [] + } +} \ No newline at end of file diff --git a/jenner-check/t001_mf_isblank/expected/files.md b/jenner-check/t001_mf_isblank/expected/files.md new file mode 100644 index 0000000..9a990f1 --- /dev/null +++ b/jenner-check/t001_mf_isblank/expected/files.md @@ -0,0 +1,14 @@ +These URLs are tied to a specific Jenner run and expire when that run is reaped; re-running the bundle regenerates them. + + +## Files + +| name | content_type | size_bytes | url | +|------|--------------|-----------|-----| +| listing.txt | text/plain | 110 | https://api.jenneranalytics.com/v1/run/r_019edad1b1c37c8386b72de626745f47/files/listing.txt?token=3d6d238630714f2daed34284586e19bf | + +## Datasets + +| name | rows | columns | preview_url | +|------|------|---------|-------------| +| mf_isblank_demo | 2 | ['scenario', 'result'] | https://api.jenneranalytics.com/v1/run/r_019edad1b1c37c8386b72de626745f47/datasets/mf_isblank_demo?token=3d6d238630714f2daed34284586e19bf | diff --git a/jenner-check/t001_mf_isblank/expected/log.txt b/jenner-check/t001_mf_isblank/expected/log.txt new file mode 100644 index 0000000..a0fe249 --- /dev/null +++ b/jenner-check/t001_mf_isblank/expected/log.txt @@ -0,0 +1,16 @@ +Jenner 0.1.0 (Unlicensed - limited to 100 observations) +Get a license at https://jenneranalytics.com/license + +NOTE: mf_isblank() on a blank argument = 1 +NOTE: mf_isblank() on a populated argument = 0 +NOTE: Option OBS changed to 100. +NOTE: DATA work.mf_isblank_demo + + +NOTE: Wrote work.mf_isblank_demo (2 rows, 2 columns). +NOTE: DATA elapsed: + wall 0.00 seconds + cpu 0.00 seconds +NOTE: PROC PRINT data=work.mf_isblank_demo + +NOTE: PROC PRINT completed: 2 observations printed, 2 variables diff --git a/jenner-check/t001_mf_isblank/expected/output.txt b/jenner-check/t001_mf_isblank/expected/output.txt new file mode 100644 index 0000000..e9813a1 --- /dev/null +++ b/jenner-check/t001_mf_isblank/expected/output.txt @@ -0,0 +1,6 @@ + + scenario result +------------------ ------ +blank argument 1 +populated argument 0 + diff --git a/jenner-check/t001_mf_isblank/meta.json b/jenner-check/t001_mf_isblank/meta.json new file mode 100644 index 0000000..462b8f5 --- /dev/null +++ b/jenner-check/t001_mf_isblank/meta.json @@ -0,0 +1,8 @@ +{ + "bundle": "t001_mf_isblank", + "source_file": "base/mf_isblank.sas", + "source_blob_sha": "9884bba8afd42ec952d5d65bd28a7885eb07ec5e", + "source_commit": "e3dc99b1a674c47b21673fd63ca8577b5d65a16e", + "tier": "macro_caller", + "notes": "Pure macro-function: %superq + %sysevalf(...,boolean). Caller drives documented usage (blank->1, populated->0). Only the inert STORE SOURCE annotation comment removed from the %macro line." +} \ No newline at end of file diff --git a/jenner-check/t001_mf_isblank/script.sas b/jenner-check/t001_mf_isblank/script.sas new file mode 100644 index 0000000..47c184c --- /dev/null +++ b/jenner-check/t001_mf_isblank/script.sas @@ -0,0 +1,29 @@ +/* Bundle t001 — exercises base/mf_isblank.sas from Boemska/macrocore. + * + * mf_isblank reports whether a macro parameter is blank, using %superq to + * protect the value and %sysevalf(...,boolean) to test for emptiness. It is + * a macro function intended for use in open code. The macro body below is + * verbatim from base/mf_isblank.sas; the doxygen file header and the inert + * STORE SOURCE annotation comment on the %macro line are the only omissions. + * + * The caller below drives the documented usage: a blank argument returns 1, + * a populated argument returns 0. + */ +%macro mf_isblank(param); + %sysevalf(%superq(param)=,boolean) +%mend; + +%let blank_result = %mf_isblank(); +%let filled_result = %mf_isblank(some value here); + +%put NOTE: mf_isblank() on a blank argument = &blank_result; +%put NOTE: mf_isblank() on a populated argument = &filled_result; + +data work.mf_isblank_demo; + length scenario $24 result 8; + scenario = 'blank argument'; result = &blank_result; output; + scenario = 'populated argument'; result = &filled_result; output; +run; + +proc print data=work.mf_isblank_demo noobs; +run; diff --git a/jenner-check/t002_mf_getuser/autoexec.sas b/jenner-check/t002_mf_getuser/autoexec.sas new file mode 100644 index 0000000..2052e87 --- /dev/null +++ b/jenner-check/t002_mf_getuser/autoexec.sas @@ -0,0 +1 @@ +options obs=100; diff --git a/jenner-check/t002_mf_getuser/expected.json b/jenner-check/t002_mf_getuser/expected.json new file mode 100644 index 0000000..7dd377f --- /dev/null +++ b/jenner-check/t002_mf_getuser/expected.json @@ -0,0 +1,21 @@ +{ + "_captured_at": "2026-06-18T13:01:14Z", + "_captured_run_id": "r_019edad1b57b7b2396a70a0bd364f8eb", + "status": "ok", + "exit_code": 0, + "log_contains": [ + "NOTE: mf_getuser() resolved to: unknown", + "NOTE: Option OBS changed to 100.", + "NOTE: DATA work.mf_getuser_demo", + "NOTE: Wrote work.mf_getuser_demo (1 rows, 1 columns).", + "NOTE: PROC PRINT data=work.mf_getuser_demo" + ], + "log_does_not_contain": [ + "ERROR:", + "[JENNER-ERROR" + ], + "diagnostics": { + "parse_warnings": [], + "runtime_warnings": [] + } +} \ No newline at end of file diff --git a/jenner-check/t002_mf_getuser/expected/files.md b/jenner-check/t002_mf_getuser/expected/files.md new file mode 100644 index 0000000..52f4ad0 --- /dev/null +++ b/jenner-check/t002_mf_getuser/expected/files.md @@ -0,0 +1,14 @@ +These URLs are tied to a specific Jenner run and expire when that run is reaped; re-running the bundle regenerates them. + + +## Files + +| name | content_type | size_bytes | url | +|------|--------------|-----------|-----| +| listing.txt | text/plain | 38 | https://api.jenneranalytics.com/v1/run/r_019edad1b57b7b2396a70a0bd364f8eb/files/listing.txt?token=01fd2295310c4c15b3c7eb0b23bbb284 | + +## Datasets + +| name | rows | columns | preview_url | +|------|------|---------|-------------| +| mf_getuser_demo | 1 | ['resolved_user'] | https://api.jenneranalytics.com/v1/run/r_019edad1b57b7b2396a70a0bd364f8eb/datasets/mf_getuser_demo?token=01fd2295310c4c15b3c7eb0b23bbb284 | diff --git a/jenner-check/t002_mf_getuser/expected/log.txt b/jenner-check/t002_mf_getuser/expected/log.txt new file mode 100644 index 0000000..ceb8764 --- /dev/null +++ b/jenner-check/t002_mf_getuser/expected/log.txt @@ -0,0 +1,15 @@ +Jenner 0.1.0 (Unlicensed - limited to 100 observations) +Get a license at https://jenneranalytics.com/license + +NOTE: mf_getuser() resolved to: unknown +NOTE: Option OBS changed to 100. +NOTE: DATA work.mf_getuser_demo + + +NOTE: Wrote work.mf_getuser_demo (1 rows, 1 columns). +NOTE: DATA elapsed: + wall 0.00 seconds + cpu 0.00 seconds +NOTE: PROC PRINT data=work.mf_getuser_demo + +NOTE: PROC PRINT completed: 1 observations printed, 1 variables diff --git a/jenner-check/t002_mf_getuser/expected/output.txt b/jenner-check/t002_mf_getuser/expected/output.txt new file mode 100644 index 0000000..cb7e841 --- /dev/null +++ b/jenner-check/t002_mf_getuser/expected/output.txt @@ -0,0 +1,5 @@ + +resolved_user +------------- +unknown + diff --git a/jenner-check/t002_mf_getuser/meta.json b/jenner-check/t002_mf_getuser/meta.json new file mode 100644 index 0000000..dc45981 --- /dev/null +++ b/jenner-check/t002_mf_getuser/meta.json @@ -0,0 +1,8 @@ +{ + "bundle": "t002_mf_getuser", + "source_file": "base/mf_getuser.sas", + "source_blob_sha": "1ccca21609e62431ab85250ac51565d833b4ff76", + "source_commit": "e3dc99b1a674c47b21673fd63ca8577b5d65a16e", + "tier": "macro_caller", + "notes": "Returns current user; no Stored-Process metadata var present so resolves to &sysuserid (workspace path). Only the inert STORE SOURCE annotation comment removed from the %macro line." +} \ No newline at end of file diff --git a/jenner-check/t002_mf_getuser/script.sas b/jenner-check/t002_mf_getuser/script.sas new file mode 100644 index 0000000..2d056d2 --- /dev/null +++ b/jenner-check/t002_mf_getuser/script.sas @@ -0,0 +1,38 @@ +/* Bundle t002 — exercises base/mf_getuser.sas from Boemska/macrocore. + * + * mf_getuser returns the current user. In a workspace session it returns + * &sysuserid; in a Stored Process session it scans a metadata username + * variable (_metaperson / _secureusername), stripping any @domain suffix + * that can appear after a password change. The macro body below is verbatim + * from base/mf_getuser.sas; the doxygen file header and the inert + * STORE SOURCE annotation comment on the %macro line are the only omissions. + * + * Running outside a Stored Process session, the metadata variable does not + * exist, so the macro resolves to &sysuserid — the documented workspace path. + */ +%macro mf_getuser(type=META); + %local user metavar; + %if &type=OS %then %let metavar=_secureusername; + %else %let metavar=_metaperson; + + %if %symexist(&metavar) %then %do; + %if %length(&&&metavar)=0 %then %let user=&sysuserid; + /* sometimes SAS will add @domain extension - remove for consistency */ + %else %let user=%scan(&&&metavar,1,@); + %end; + %else %let user=&sysuserid; + + %quote(&user) +%mend; + +%let who = %mf_getuser(); +%put NOTE: mf_getuser() resolved to: &who; + +data work.mf_getuser_demo; + length resolved_user $64; + resolved_user = "&who"; + output; +run; + +proc print data=work.mf_getuser_demo noobs; +run; diff --git a/jenner-check/t003_mp_resetoption/autoexec.sas b/jenner-check/t003_mp_resetoption/autoexec.sas new file mode 100644 index 0000000..2052e87 --- /dev/null +++ b/jenner-check/t003_mp_resetoption/autoexec.sas @@ -0,0 +1 @@ +options obs=100; diff --git a/jenner-check/t003_mp_resetoption/expected.json b/jenner-check/t003_mp_resetoption/expected.json new file mode 100644 index 0000000..510cca7 --- /dev/null +++ b/jenner-check/t003_mp_resetoption/expected.json @@ -0,0 +1,21 @@ +{ + "_captured_at": "2026-06-18T13:01:14Z", + "_captured_run_id": "r_019edad1b88d7ac2a6e2128c943852c6", + "status": "ok", + "exit_code": 0, + "log_contains": [ + "NOTE: Option OBS changed to 100.", + "NOTE: Option OBS changed to 30.", + "NOTE: DATA _null_", + "NOTE: Wrote _null_ (0 rows, 0 columns).", + "NOTE: OBS option after mp_resetoption call = 30" + ], + "log_does_not_contain": [ + "ERROR:", + "[JENNER-ERROR" + ], + "diagnostics": { + "parse_warnings": [], + "runtime_warnings": [] + } +} \ No newline at end of file diff --git a/jenner-check/t003_mp_resetoption/expected/files.md b/jenner-check/t003_mp_resetoption/expected/files.md new file mode 100644 index 0000000..8862d97 --- /dev/null +++ b/jenner-check/t003_mp_resetoption/expected/files.md @@ -0,0 +1,4 @@ +These URLs are tied to a specific Jenner run and expire when that run is reaped; re-running the bundle regenerates them. + + +(No files or datasets were emitted by this run.) diff --git a/jenner-check/t003_mp_resetoption/expected/log.txt b/jenner-check/t003_mp_resetoption/expected/log.txt new file mode 100644 index 0000000..acc7113 --- /dev/null +++ b/jenner-check/t003_mp_resetoption/expected/log.txt @@ -0,0 +1,20 @@ +Jenner 0.1.0 (Unlicensed - limited to 100 observations) +Get a license at https://jenneranalytics.com/license + +NOTE: Option OBS changed to 100. +NOTE: Option OBS changed to 30. +NOTE: DATA _null_ + + +NOTE: Wrote _null_ (0 rows, 0 columns). +NOTE: DATA elapsed: + wall 0.00 seconds + cpu 0.00 seconds +NOTE: DATA _null_ + +NOTE: OBS option after mp_resetoption call = 30 + +NOTE: Wrote _null_ (0 rows, 0 columns). +NOTE: DATA elapsed: + wall 0.00 seconds + cpu 0.00 seconds diff --git a/jenner-check/t003_mp_resetoption/expected/output.txt b/jenner-check/t003_mp_resetoption/expected/output.txt new file mode 100644 index 0000000..e69de29 diff --git a/jenner-check/t003_mp_resetoption/meta.json b/jenner-check/t003_mp_resetoption/meta.json new file mode 100644 index 0000000..caf12dd --- /dev/null +++ b/jenner-check/t003_mp_resetoption/meta.json @@ -0,0 +1,8 @@ +{ + "bundle": "t003_mp_resetoption", + "source_file": "base/mp_resetoption.sas", + "source_blob_sha": "ef2f87e9cb6b2bf73143c6853ff80c92c7252c5d", + "source_commit": "e3dc99b1a674c47b21673fd63ca8577b5d65a16e", + "tier": "macro_caller", + "notes": "Code-generator (_mp_): emits DATA _null_ using GETOPTION + CALL EXECUTE to reset a system option to its startup value. Driver sets OBS=30 then calls for OBS. Only the inert STORE SOURCE annotation comment removed from the %macro line." +} \ No newline at end of file diff --git a/jenner-check/t003_mp_resetoption/script.sas b/jenner-check/t003_mp_resetoption/script.sas new file mode 100644 index 0000000..c75438e --- /dev/null +++ b/jenner-check/t003_mp_resetoption/script.sas @@ -0,0 +1,35 @@ +/* Bundle t003 — exercises base/mp_resetoption.sas from Boemska/macrocore. + * + * mp_resetoption is a code generator (an _mp_ macro): given a system option + * name, it emits a DATA _null_ step that compares the option's startup value + * with its current value and, if they differ, rebuilds and executes an + * OPTIONS statement via CALL EXECUTE to restore the startup value. The macro + * body below is verbatim from base/mp_resetoption.sas; the doxygen file + * header and the inert STORE SOURCE annotation comment on the %macro line + * are the only omissions. + * + * The driver sets OBS to a non-default value and then calls the macro for + * OBS, exercising the generated GETOPTION / CALL EXECUTE logic. + */ +%macro mp_resetoption(option /* the option to reset */); + +data _null_; + length code $1500; + startup=getoption("&option",'startupvalue'); + current=getoption("&option"); + if startup ne current then do; + code =cat('OPTIONS ',getoption("&option",'keyword','startupvalue'),';'); + putlog "NOTE: Resetting system option: " code ; + call execute(code ); + end; +run; + +%mend; + +options obs=30; +%mp_resetoption(OBS) + +data _null_; + current_obs = getoption("obs"); + put "NOTE: OBS option after mp_resetoption call = " current_obs; +run; diff --git a/jenner-check/t004_mf_mkdir/autoexec.sas b/jenner-check/t004_mf_mkdir/autoexec.sas new file mode 100644 index 0000000..2052e87 --- /dev/null +++ b/jenner-check/t004_mf_mkdir/autoexec.sas @@ -0,0 +1 @@ +options obs=100; diff --git a/jenner-check/t004_mf_mkdir/expected.json b/jenner-check/t004_mf_mkdir/expected.json new file mode 100644 index 0000000..3f5ab67 --- /dev/null +++ b/jenner-check/t004_mf_mkdir/expected.json @@ -0,0 +1,19 @@ +{ + "_captured_at": "2026-06-18T13:02:11Z", + "_captured_run_id": "r_019edad2f2017e30be740b53db2ea204", + "status": "ok", + "exit_code": 0, + "log_contains": [ + "NOTE: mf_mkdir target /tmp exists before call = 1", + "NOTE: Option OBS changed to 100.", + "NOTE: mf_mkdir target /tmp exists after call = 1" + ], + "log_does_not_contain": [ + "ERROR:", + "[JENNER-ERROR" + ], + "diagnostics": { + "parse_warnings": [], + "runtime_warnings": [] + } +} \ No newline at end of file diff --git a/jenner-check/t004_mf_mkdir/expected/files.md b/jenner-check/t004_mf_mkdir/expected/files.md new file mode 100644 index 0000000..8862d97 --- /dev/null +++ b/jenner-check/t004_mf_mkdir/expected/files.md @@ -0,0 +1,4 @@ +These URLs are tied to a specific Jenner run and expire when that run is reaped; re-running the bundle regenerates them. + + +(No files or datasets were emitted by this run.) diff --git a/jenner-check/t004_mf_mkdir/expected/log.txt b/jenner-check/t004_mf_mkdir/expected/log.txt new file mode 100644 index 0000000..9ad0ee2 --- /dev/null +++ b/jenner-check/t004_mf_mkdir/expected/log.txt @@ -0,0 +1,6 @@ +Jenner 0.1.0 (Unlicensed - limited to 100 observations) +Get a license at https://jenneranalytics.com/license + +NOTE: mf_mkdir target /tmp exists before call = 1 +NOTE: Option OBS changed to 100. +NOTE: mf_mkdir target /tmp exists after call = 1 diff --git a/jenner-check/t004_mf_mkdir/expected/output.txt b/jenner-check/t004_mf_mkdir/expected/output.txt new file mode 100644 index 0000000..e69de29 diff --git a/jenner-check/t004_mf_mkdir/meta.json b/jenner-check/t004_mf_mkdir/meta.json new file mode 100644 index 0000000..1eba0b4 --- /dev/null +++ b/jenner-check/t004_mf_mkdir/meta.json @@ -0,0 +1,8 @@ +{ + "bundle": "t004_mf_mkdir", + "source_file": "base/mf_mkdir.sas", + "source_blob_sha": "5d27def2050208c965998a77ebcc23dba2ede2a7", + "source_commit": "e3dc99b1a674c47b21673fd63ca8577b5d65a16e", + "tier": "macro_caller", + "notes": "Recursive macro using %substr/%scan path decomposition + FILEEXIST/DCREATE. Driver targets an existing path so FILEEXIST short-circuits before any directory is created. Only the inert STORE SOURCE annotation comment removed from the %macro line." +} \ No newline at end of file diff --git a/jenner-check/t004_mf_mkdir/script.sas b/jenner-check/t004_mf_mkdir/script.sas new file mode 100644 index 0000000..62f54aa --- /dev/null +++ b/jenner-check/t004_mf_mkdir/script.sas @@ -0,0 +1,62 @@ +/* Bundle t004 — exercises base/mf_mkdir.sas from Boemska/macrocore. + * + * mf_mkdir creates a directory, including any intermediate parent + * directories, by recursively scanning the path with %scan / %substr and + * calling itself for the parent before invoking DCREATE for the childmost + * component. The macro body below is verbatim from base/mf_mkdir.sas; the + * doxygen file header and the inert STORE SOURCE annotation comment on the + * %macro line are the only omissions. + * + * The driver targets a path that already exists, so FILEEXIST short-circuits + * the recursion before any directory is created — exercising the trailing + * slash handling, the %substr / %scan path decomposition, and the recursive + * macro call resolution, with no filesystem side effects. + */ +%macro mf_mkdir(dir); + + %local lastchar child parent; + + %let lastchar = %substr(&dir, %length(&dir)); + %if (%bquote(&lastchar) eq %str(:)) %then %do; + /* Cannot create drive mappings */ + %return; + %end; + + %if (%bquote(&lastchar)=%str(/)) or (%bquote(&lastchar)=%str(\)) %then %do; + /* last char is a slash */ + %if (%length(&dir) eq 1) %then %do; + /* one single slash - root location is assumed to exist */ + %return; + %end; + %else %do; + /* strip last slash */ + %let dir = %substr(&dir, 1, %length(&dir)-1); + %end; + %end; + + %if (%sysfunc(fileexist(%bquote(&dir))) = 0) %then %do; + /* directory does not exist so prepare to create */ + /* first get the childmost directory */ + %let child = %scan(&dir, -1, %str(/\:)); + + %if (%length(&dir) gt %length(&child)) %then %do; + %let parent = %substr(&dir, 1, %length(&dir)-%length(&child)); + %mf_mkdir(&parent) + %end; + + %let dname = %sysfunc(dcreate(&child, &parent)); + %if (%bquote(&dname) eq ) %then %do; + %put ERROR: could not create &parent + &child; + %abort cancel; + %end; + %else %do; + %put Directory created: &dir; + %end; + %end; + /* exit quietly if directory did exist.*/ +%mend; + +%put NOTE: mf_mkdir target /tmp exists before call = %sysfunc(fileexist(/tmp)); +%mf_mkdir(/tmp) +%put NOTE: mf_mkdir target /tmp exists after call = %sysfunc(fileexist(/tmp)); +%put NOTE: mf_mkdir(/tmp) returned to open code - existing path handled.