mirror of
https://github.com/sasjs/core.git
synced 2026-07-23 15:35:29 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e5c6e8f8d | |||
| 619fedd49d | |||
| 3d52ec7ef5 | |||
| ebb00f458b | |||
| e24ef4c6fc | |||
| e104f0722d | |||
| 05e892619a | |||
| 444ffac0f3 |
@@ -0,0 +1,59 @@
|
||||
# Testing in @sasjs/core
|
||||
|
||||
## Overview
|
||||
|
||||
Tests are executed on a real SAS server using the SASjs CLI (`sasjs test`), not locally. Each test is a self-contained `.sas` file that is submitted to the server, and results are collected in the `sasjsresults` folder.
|
||||
|
||||
## Running Tests
|
||||
|
||||
```bash
|
||||
npm test # runs: npx @sasjs/cli test -t server
|
||||
```
|
||||
|
||||
The `-t server` flag selects the target (server type) from `sasjs/sasjsconfig.json`.
|
||||
|
||||
## Test Structure
|
||||
|
||||
Test files live under `tests/` in subfolders by platform applicability:
|
||||
|
||||
- `tests/base` — run on all platforms (SAS 9 and Viya)
|
||||
- `tests/sas9only` — SAS 9 only (metadata server macros)
|
||||
- `tests/viyaonly` — Viya only
|
||||
- `tests/serveronly` — SASjs Server only
|
||||
- `tests/x-platform` — cross-platform (both SAS 9 and Viya)
|
||||
- `tests/ddlonly` — DDL-related tests
|
||||
|
||||
Naming convention: `<macroname>.test.sas`, with numbered variants (`<macroname>.test.1.sas`, `.test.2.sas`, ...) for multiple tests of the same macro. File names are lowercase, matching the lint rules.
|
||||
|
||||
## Test Flow
|
||||
|
||||
1. **Init**: `tests/testinit.sas` runs before every test (configured in `sasjsconfig.json` under `testConfig.initProgram`). It sets up a unique app location (`mcTestAppLoc`), the compute context, calls `%mp_init()`, and enables debug options when `_debug` is set.
|
||||
2. **Test body**: the test file itself runs. It should use `%mp_assert()` to record results into `work.test_results`:
|
||||
|
||||
```sas
|
||||
%mp_assert(
|
||||
iftrue=(&syscc=0),
|
||||
desc=Checking for error condition,
|
||||
outds=work.test_results
|
||||
)
|
||||
```
|
||||
|
||||
3. **Term**: `tests/testterm.sas` runs after every test (`testConfig.termProgram`). It adds a final assertion that `&syscc=0`, then writes the results as JSON via `%webout(OPEN) / %webout(OBJ,TEST_RESULTS) / %webout(CLOSE)`.
|
||||
|
||||
## Results
|
||||
|
||||
After a test run, check the `sasjsresults` folder:
|
||||
|
||||
- `testResults.json` / `testResults.xml` / `testResults.csv` — per-test PASS/FAIL with descriptions and comments
|
||||
- `logs/<testname>.log` — the full SAS log for each test; check here first when a test fails
|
||||
- `coverage.lcov` — coverage data
|
||||
|
||||
## Writing Tests — Things to Know
|
||||
|
||||
- Tests follow the same Doxygen header and lint standards as regular macros (`@file`, `@brief`, `<h4> SAS Macros </h4>` listing macros used).
|
||||
- Macro *calls* are not terminated with semicolons: use `%mp_assert(...)` not `%mp_assert(...);`.
|
||||
- Use `%mp_assert(iftrue=(...), desc=..., outds=work.test_results)` for every check — always append to `work.test_results`.
|
||||
- When comparing datasets after a round trip (eg through JSON), do not assert `proc compare` SYSINFO=0 directly — SYSINFO is a bitmask that includes attribute differences (length, format, label) which round trips legitimately change. Mask it to data-related bits only (64=missing obs in compare, 128=extra obs in compare, 4096=unequal values, 32768=obs count differs). Note `SYSINFO` is a read-only automatic macro variable, so store the masked value in a new variable.
|
||||
- Be careful with character data round trips: `cats()` and the plain `$` informat strip leading blanks; use `trim()` and `$char` where leading blanks must be preserved.
|
||||
- After any change, run `npx sasjs lint`.
|
||||
- Do not edit generated copies under `sasjsbuild/` — they are refreshed by the CI build.
|
||||
@@ -8,3 +8,4 @@ sasjs/
|
||||
make_singlefile.sh
|
||||
*.md
|
||||
.all-contributorsrc
|
||||
.agents
|
||||
@@ -25,6 +25,12 @@ This repo is the SASjs Macro Core library — a collection of MIT-licensed, prod
|
||||
- Macro variables must always be local, to prevent scope leakage.
|
||||
|
||||
|
||||
## Testing
|
||||
- Read `.agents/docs/tests.md` for details on how the testing process works (how to run tests, structure, assertions, and where to find logs/results).
|
||||
|
||||
## Markdown Files
|
||||
- Markdown files must not use word-wrap: never insert carriage returns mid-sentence. Each sentence/paragraph stays on one line.
|
||||
|
||||
## Build / Generated Files
|
||||
- Do not run the build script locally; it is executed in the CI/CD pipeline.
|
||||
- Generated files, including the consolidated `all.sas`, the per-folder `mc_*.sas` files, and the LUA macro wrappers in the `lua` folder, can generally be ignored unless the pipeline requires an update. Do not edit generated files by hand.
|
||||
|
||||
@@ -2621,9 +2621,12 @@ Usage:
|
||||
@brief Returns words that are in both string 1 and string 2
|
||||
@details Compares two space separated strings and returns the words that are
|
||||
in both.
|
||||
|
||||
If either string is empty, nothing is returned.
|
||||
|
||||
Usage:
|
||||
|
||||
%put %mf_wordsInStr1andStr2(
|
||||
%put %mf_wordsinstr1andstr2(
|
||||
Str1=blah sss blaaah brah bram boo
|
||||
,Str2= blah blaaah brah ssss
|
||||
);
|
||||
@@ -2641,34 +2644,26 @@ Usage:
|
||||
|
||||
**/
|
||||
|
||||
%macro mf_wordsInStr1andStr2(
|
||||
%macro mf_wordsinstr1andstr2(
|
||||
Str1= /* string containing words to extract */
|
||||
,Str2= /* used to compare with the extract string */
|
||||
)/*/STORE SOURCE*/;
|
||||
|
||||
%local count_base count_extr i i2 extr_word base_word match outvar;
|
||||
%local count_extr i extr_word outvar;
|
||||
%if %length(&str1)=0 or %length(&str2)=0 %then %do;
|
||||
%put base string (str1)= &str1;
|
||||
%put compare string (str2) = &str2;
|
||||
%put &sysmacroname: empty input string, nothing to compare;
|
||||
%return;
|
||||
%end;
|
||||
%let count_base=%sysfunc(countw(&Str2));
|
||||
%let count_extr=%sysfunc(countw(&Str1));
|
||||
|
||||
%do i=1 %to &count_extr;
|
||||
%let extr_word=%scan(&Str1,&i,%str( ));
|
||||
%let match=0;
|
||||
%do i2=1 %to &count_base;
|
||||
%let base_word=%scan(&Str2,&i2,%str( ));
|
||||
%if &extr_word=&base_word %then %let match=1;
|
||||
%end;
|
||||
%if &match=1 %then %let outvar=&outvar &extr_word;
|
||||
%if %sysfunc(indexw(%superq(str2),%superq(extr_word)))>0 %then
|
||||
%let outvar=&outvar &extr_word;
|
||||
%end;
|
||||
|
||||
&outvar
|
||||
|
||||
%mend mf_wordsInStr1andStr2;
|
||||
|
||||
/* send out the result without any surrounding whitespace */
|
||||
%do;&outvar%end;
|
||||
%mend mf_wordsinstr1andstr2;
|
||||
/**
|
||||
@file
|
||||
@brief Returns words that are in string 1 but not in string 2
|
||||
@@ -2677,9 +2672,12 @@ Usage:
|
||||
|
||||
Note - case sensitive!
|
||||
|
||||
If str1 is empty, nothing is returned. If str2 is empty, all the words in
|
||||
str1 are returned.
|
||||
|
||||
Usage:
|
||||
|
||||
%let x= %mf_wordsInStr1ButNotStr2(
|
||||
%let x= %mf_wordsinstr1butnotstr2(
|
||||
Str1=blah sss blaaah brah bram boo
|
||||
,Str2= blah blaaah brah ssss
|
||||
);
|
||||
@@ -2695,34 +2693,26 @@ Usage:
|
||||
|
||||
**/
|
||||
|
||||
%macro mf_wordsInStr1ButNotStr2(
|
||||
%macro mf_wordsinstr1butnotstr2(
|
||||
Str1= /* string containing words to extract */
|
||||
,Str2= /* used to compare with the extract string */
|
||||
)/*/STORE SOURCE*/;
|
||||
|
||||
%local count_base count_extr i i2 extr_word base_word match outvar;
|
||||
%if %length(&str1)=0 or %length(&str2)=0 %then %do;
|
||||
%put base string (str1)= &str1;
|
||||
%put compare string (str2) = &str2;
|
||||
%local count_extr i extr_word outvar;
|
||||
%if %length(&str1)=0 %then %do;
|
||||
%put &sysmacroname: str1 is empty, nothing to compare;
|
||||
%return;
|
||||
%end;
|
||||
%let count_base=%sysfunc(countw(&Str2));
|
||||
%let count_extr=%sysfunc(countw(&Str1));
|
||||
|
||||
%do i=1 %to &count_extr;
|
||||
%let extr_word=%scan(&Str1,&i,%str( ));
|
||||
%let match=0;
|
||||
%do i2=1 %to &count_base;
|
||||
%let base_word=%scan(&Str2,&i2,%str( ));
|
||||
%if &extr_word=&base_word %then %let match=1;
|
||||
%end;
|
||||
%if &match=0 %then %let outvar=&outvar &extr_word;
|
||||
%if %sysfunc(indexw(%superq(str2),%superq(extr_word)))=0 %then
|
||||
%let outvar=&outvar &extr_word;
|
||||
%end;
|
||||
|
||||
&outvar
|
||||
|
||||
%mend mf_wordsInStr1ButNotStr2;
|
||||
|
||||
/* send out the result without any surrounding whitespace */
|
||||
%do;&outvar%end;
|
||||
%mend mf_wordsinstr1butnotstr2;
|
||||
/**
|
||||
@file
|
||||
@brief Creates a text file using pure macro
|
||||
@@ -10474,7 +10464,8 @@ options
|
||||
prxchange('s/\\/\\\\/',-1,&&name&i)
|
||||
)))))))))))))!!'"';
|
||||
end;
|
||||
else &&name&i=quote(cats(&&name&i));
|
||||
/* trim (not cats) so leading blanks are retained */
|
||||
else &&name&i='"'!!trim(&&name&i)!!'"';
|
||||
%end;
|
||||
%end;
|
||||
run;
|
||||
@@ -17557,7 +17548,8 @@ data _null_;
|
||||
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
||||
put ' )))))))))))))!!''"''; ';
|
||||
put ' end; ';
|
||||
put ' else &&name&i=quote(cats(&&name&i)); ';
|
||||
put ' /* trim (not cats) so leading blanks are retained */ ';
|
||||
put ' else &&name&i=''"''!!trim(&&name&i)!!''"''; ';
|
||||
put ' %end; ';
|
||||
put ' %end; ';
|
||||
put ' run; ';
|
||||
@@ -17676,7 +17668,10 @@ data _null_;
|
||||
put ' data _null_; ';
|
||||
put ' infile &&_webin_fileref&i termstr=crlf; ';
|
||||
put ' input; ';
|
||||
put ' call symputx(''input_statement'',_infile_); ';
|
||||
put ' /* a plain $ informat strips leading blanks - use $char instead */ ';
|
||||
put ' call symputx(''input_statement'' ';
|
||||
put ' ,prxchange(''s/:\$(?=[0-9 ])/:\$char/i'',-1,_infile_) ';
|
||||
put ' ); ';
|
||||
put ' putlog "&&_webin_name&i input statement: " _infile_; ';
|
||||
put ' stop; ';
|
||||
put ' data &&_webin_name&i; ';
|
||||
@@ -21375,7 +21370,10 @@ run;
|
||||
data _null_;
|
||||
infile &&_webin_fileref&i termstr=crlf;
|
||||
input;
|
||||
call symputx('input_statement',_infile_);
|
||||
/* a plain $ informat strips leading blanks - use $char instead */
|
||||
call symputx('input_statement'
|
||||
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||
);
|
||||
putlog "&&_webin_name&i input statement: " _infile_;
|
||||
stop;
|
||||
data &&_webin_name&i;
|
||||
@@ -22669,7 +22667,8 @@ data _null_;
|
||||
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
||||
put ' )))))))))))))!!''"''; ';
|
||||
put ' end; ';
|
||||
put ' else &&name&i=quote(cats(&&name&i)); ';
|
||||
put ' /* trim (not cats) so leading blanks are retained */ ';
|
||||
put ' else &&name&i=''"''!!trim(&&name&i)!!''"''; ';
|
||||
put ' %end; ';
|
||||
put ' %end; ';
|
||||
put ' run; ';
|
||||
@@ -22786,7 +22785,10 @@ data _null_;
|
||||
put ' data _null_; ';
|
||||
put ' infile &&_webin_fileref&i termstr=crlf lrecl=32767; ';
|
||||
put ' input; ';
|
||||
put ' call symputx(''input_statement'',_infile_); ';
|
||||
put ' /* a plain $ informat strips leading blanks - use $char instead */ ';
|
||||
put ' call symputx(''input_statement'' ';
|
||||
put ' ,prxchange(''s/:\$(?=[0-9 ])/:\$char/i'',-1,_infile_) ';
|
||||
put ' ); ';
|
||||
put ' putlog "&&_webin_name&i input statement: " _infile_; ';
|
||||
put ' stop; ';
|
||||
put ' data &&_webin_name&i; ';
|
||||
@@ -24055,7 +24057,10 @@ run;
|
||||
data _null_;
|
||||
infile &&_webin_fileref&i termstr=crlf lrecl=32767;
|
||||
input;
|
||||
call symputx('input_statement',_infile_);
|
||||
/* a plain $ informat strips leading blanks - use $char instead */
|
||||
call symputx('input_statement'
|
||||
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||
);
|
||||
putlog "&&_webin_name&i input statement: " _infile_;
|
||||
stop;
|
||||
data &&_webin_name&i;
|
||||
@@ -26320,7 +26325,8 @@ data _null_;
|
||||
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
||||
put ' )))))))))))))!!''"''; ';
|
||||
put ' end; ';
|
||||
put ' else &&name&i=quote(cats(&&name&i)); ';
|
||||
put ' /* trim (not cats) so leading blanks are retained */ ';
|
||||
put ' else &&name&i=''"''!!trim(&&name&i)!!''"''; ';
|
||||
put ' %end; ';
|
||||
put ' %end; ';
|
||||
put ' run; ';
|
||||
@@ -26466,7 +26472,10 @@ data _null_;
|
||||
put ' data _null_; ';
|
||||
put ' infile "%sysfunc(pathname(work))/&table..csv" termstr=crlf ; ';
|
||||
put ' input; ';
|
||||
put ' if _n_=1 then call symputx(''input_statement'',_infile_); ';
|
||||
put ' /* a plain $ informat strips leading blanks - use $char instead */ ';
|
||||
put ' if _n_=1 then call symputx(''input_statement'' ';
|
||||
put ' ,prxchange(''s/:\$(?=[0-9 ])/:\$char/i'',-1,_infile_) ';
|
||||
put ' ); ';
|
||||
put ' list; ';
|
||||
put ' data work.&table; ';
|
||||
put ' infile "%sysfunc(pathname(work))/&table..csv" firstobs=2 dsd ';
|
||||
@@ -26486,7 +26495,10 @@ data _null_;
|
||||
put ' data _null_; ';
|
||||
put ' infile indata termstr=crlf lrecl=32767; ';
|
||||
put ' input; ';
|
||||
put ' if _n_=1 then call symputx(''input_statement'',_infile_); ';
|
||||
put ' /* a plain $ informat strips leading blanks - use $char instead */ ';
|
||||
put ' if _n_=1 then call symputx(''input_statement'' ';
|
||||
put ' ,prxchange(''s/:\$(?=[0-9 ])/:\$char/i'',-1,_infile_) ';
|
||||
put ' ); ';
|
||||
put ' %if %str(&_debug) ge 128 %then %do; ';
|
||||
put ' if _n_<20 then putlog _infile_; ';
|
||||
put ' else stop; ';
|
||||
@@ -30612,7 +30624,10 @@ filename &fref1 clear;
|
||||
data _null_;
|
||||
infile "%sysfunc(pathname(work))/&table..csv" termstr=crlf ;
|
||||
input;
|
||||
if _n_=1 then call symputx('input_statement',_infile_);
|
||||
/* a plain $ informat strips leading blanks - use $char instead */
|
||||
if _n_=1 then call symputx('input_statement'
|
||||
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||
);
|
||||
list;
|
||||
data work.&table;
|
||||
infile "%sysfunc(pathname(work))/&table..csv" firstobs=2 dsd
|
||||
@@ -30632,7 +30647,10 @@ filename &fref1 clear;
|
||||
data _null_;
|
||||
infile indata termstr=crlf lrecl=32767;
|
||||
input;
|
||||
if _n_=1 then call symputx('input_statement',_infile_);
|
||||
/* a plain $ informat strips leading blanks - use $char instead */
|
||||
if _n_=1 then call symputx('input_statement'
|
||||
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||
);
|
||||
%if %str(&_debug) ge 128 %then %do;
|
||||
if _n_<20 then putlog _infile_;
|
||||
else stop;
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
@brief Returns words that are in both string 1 and string 2
|
||||
@details Compares two space separated strings and returns the words that are
|
||||
in both.
|
||||
|
||||
If either string is empty, nothing is returned.
|
||||
|
||||
Usage:
|
||||
|
||||
%put %mf_wordsInStr1andStr2(
|
||||
%put %mf_wordsinstr1andstr2(
|
||||
Str1=blah sss blaaah brah bram boo
|
||||
,Str2= blah blaaah brah ssss
|
||||
);
|
||||
@@ -23,31 +26,23 @@
|
||||
|
||||
**/
|
||||
|
||||
%macro mf_wordsInStr1andStr2(
|
||||
%macro mf_wordsinstr1andstr2(
|
||||
Str1= /* string containing words to extract */
|
||||
,Str2= /* used to compare with the extract string */
|
||||
)/*/STORE SOURCE*/;
|
||||
|
||||
%local count_base count_extr i i2 extr_word base_word match outvar;
|
||||
%local count_extr i extr_word outvar;
|
||||
%if %length(&str1)=0 or %length(&str2)=0 %then %do;
|
||||
%put base string (str1)= &str1;
|
||||
%put compare string (str2) = &str2;
|
||||
%put &sysmacroname: empty input string, nothing to compare;
|
||||
%return;
|
||||
%end;
|
||||
%let count_base=%sysfunc(countw(&Str2));
|
||||
%let count_extr=%sysfunc(countw(&Str1));
|
||||
|
||||
%do i=1 %to &count_extr;
|
||||
%let extr_word=%scan(&Str1,&i,%str( ));
|
||||
%let match=0;
|
||||
%do i2=1 %to &count_base;
|
||||
%let base_word=%scan(&Str2,&i2,%str( ));
|
||||
%if &extr_word=&base_word %then %let match=1;
|
||||
%end;
|
||||
%if &match=1 %then %let outvar=&outvar &extr_word;
|
||||
%if %sysfunc(indexw(%superq(str2),%superq(extr_word)))>0 %then
|
||||
%let outvar=&outvar &extr_word;
|
||||
%end;
|
||||
|
||||
&outvar
|
||||
|
||||
%mend mf_wordsInStr1andStr2;
|
||||
|
||||
/* send out the result without any surrounding whitespace */
|
||||
%do;&outvar%end;
|
||||
%mend mf_wordsinstr1andstr2;
|
||||
|
||||
@@ -6,9 +6,12 @@
|
||||
|
||||
Note - case sensitive!
|
||||
|
||||
If str1 is empty, nothing is returned. If str2 is empty, all the words in
|
||||
str1 are returned.
|
||||
|
||||
Usage:
|
||||
|
||||
%let x= %mf_wordsInStr1ButNotStr2(
|
||||
%let x= %mf_wordsinstr1butnotstr2(
|
||||
Str1=blah sss blaaah brah bram boo
|
||||
,Str2= blah blaaah brah ssss
|
||||
);
|
||||
@@ -24,31 +27,23 @@
|
||||
|
||||
**/
|
||||
|
||||
%macro mf_wordsInStr1ButNotStr2(
|
||||
%macro mf_wordsinstr1butnotstr2(
|
||||
Str1= /* string containing words to extract */
|
||||
,Str2= /* used to compare with the extract string */
|
||||
)/*/STORE SOURCE*/;
|
||||
|
||||
%local count_base count_extr i i2 extr_word base_word match outvar;
|
||||
%if %length(&str1)=0 or %length(&str2)=0 %then %do;
|
||||
%put base string (str1)= &str1;
|
||||
%put compare string (str2) = &str2;
|
||||
%local count_extr i extr_word outvar;
|
||||
%if %length(&str1)=0 %then %do;
|
||||
%put &sysmacroname: str1 is empty, nothing to compare;
|
||||
%return;
|
||||
%end;
|
||||
%let count_base=%sysfunc(countw(&Str2));
|
||||
%let count_extr=%sysfunc(countw(&Str1));
|
||||
|
||||
%do i=1 %to &count_extr;
|
||||
%let extr_word=%scan(&Str1,&i,%str( ));
|
||||
%let match=0;
|
||||
%do i2=1 %to &count_base;
|
||||
%let base_word=%scan(&Str2,&i2,%str( ));
|
||||
%if &extr_word=&base_word %then %let match=1;
|
||||
%end;
|
||||
%if &match=0 %then %let outvar=&outvar &extr_word;
|
||||
%if %sysfunc(indexw(%superq(str2),%superq(extr_word)))=0 %then
|
||||
%let outvar=&outvar &extr_word;
|
||||
%end;
|
||||
|
||||
&outvar
|
||||
|
||||
%mend mf_wordsInStr1ButNotStr2;
|
||||
|
||||
/* send out the result without any surrounding whitespace */
|
||||
%do;&outvar%end;
|
||||
%mend mf_wordsinstr1butnotstr2;
|
||||
|
||||
+2
-1
@@ -331,7 +331,8 @@
|
||||
prxchange('s/\\/\\\\/',-1,&&name&i)
|
||||
)))))))))))))!!'"';
|
||||
end;
|
||||
else &&name&i=quote(cats(&&name&i));
|
||||
/* trim (not cats) so leading blanks are retained */
|
||||
else &&name&i='"'!!trim(&&name&i)!!'"';
|
||||
%end;
|
||||
%end;
|
||||
run;
|
||||
|
||||
@@ -355,7 +355,8 @@ data _null_;
|
||||
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
||||
put ' )))))))))))))!!''"''; ';
|
||||
put ' end; ';
|
||||
put ' else &&name&i=quote(cats(&&name&i)); ';
|
||||
put ' /* trim (not cats) so leading blanks are retained */ ';
|
||||
put ' else &&name&i=''"''!!trim(&&name&i)!!''"''; ';
|
||||
put ' %end; ';
|
||||
put ' %end; ';
|
||||
put ' run; ';
|
||||
@@ -474,7 +475,10 @@ data _null_;
|
||||
put ' data _null_; ';
|
||||
put ' infile &&_webin_fileref&i termstr=crlf; ';
|
||||
put ' input; ';
|
||||
put ' call symputx(''input_statement'',_infile_); ';
|
||||
put ' /* a plain $ informat strips leading blanks - use $char instead */ ';
|
||||
put ' call symputx(''input_statement'' ';
|
||||
put ' ,prxchange(''s/:\$(?=[0-9 ])/:\$char/i'',-1,_infile_) ';
|
||||
put ' ); ';
|
||||
put ' putlog "&&_webin_name&i input statement: " _infile_; ';
|
||||
put ' stop; ';
|
||||
put ' data &&_webin_name&i; ';
|
||||
|
||||
+4
-1
@@ -77,7 +77,10 @@
|
||||
data _null_;
|
||||
infile &&_webin_fileref&i termstr=crlf;
|
||||
input;
|
||||
call symputx('input_statement',_infile_);
|
||||
/* a plain $ informat strips leading blanks - use $char instead */
|
||||
call symputx('input_statement'
|
||||
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||
);
|
||||
putlog "&&_webin_name&i input statement: " _infile_;
|
||||
stop;
|
||||
data &&_webin_name&i;
|
||||
|
||||
@@ -355,7 +355,8 @@ data _null_;
|
||||
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
||||
put ' )))))))))))))!!''"''; ';
|
||||
put ' end; ';
|
||||
put ' else &&name&i=quote(cats(&&name&i)); ';
|
||||
put ' /* trim (not cats) so leading blanks are retained */ ';
|
||||
put ' else &&name&i=''"''!!trim(&&name&i)!!''"''; ';
|
||||
put ' %end; ';
|
||||
put ' %end; ';
|
||||
put ' run; ';
|
||||
@@ -472,7 +473,10 @@ data _null_;
|
||||
put ' data _null_; ';
|
||||
put ' infile &&_webin_fileref&i termstr=crlf lrecl=32767; ';
|
||||
put ' input; ';
|
||||
put ' call symputx(''input_statement'',_infile_); ';
|
||||
put ' /* a plain $ informat strips leading blanks - use $char instead */ ';
|
||||
put ' call symputx(''input_statement'' ';
|
||||
put ' ,prxchange(''s/:\$(?=[0-9 ])/:\$char/i'',-1,_infile_) ';
|
||||
put ' ); ';
|
||||
put ' putlog "&&_webin_name&i input statement: " _infile_; ';
|
||||
put ' stop; ';
|
||||
put ' data &&_webin_name&i; ';
|
||||
|
||||
@@ -74,7 +74,10 @@
|
||||
data _null_;
|
||||
infile &&_webin_fileref&i termstr=crlf lrecl=32767;
|
||||
input;
|
||||
call symputx('input_statement',_infile_);
|
||||
/* a plain $ informat strips leading blanks - use $char instead */
|
||||
call symputx('input_statement'
|
||||
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||
);
|
||||
putlog "&&_webin_name&i input statement: " _infile_;
|
||||
stop;
|
||||
data &&_webin_name&i;
|
||||
|
||||
@@ -5,12 +5,17 @@
|
||||
<h4> SAS Macros </h4>
|
||||
@li mf_wordsinstr1andstr2.sas
|
||||
@li mp_assert.sas
|
||||
@li mp_assertscope.sas
|
||||
|
||||
**/
|
||||
|
||||
/* basic test, with scope check */
|
||||
%mp_assertscope(SNAPSHOT)
|
||||
%let x=%mf_wordsinstr1andstr2(str1=xx DOLLAR x $CHAR xxx W MONNAME
|
||||
,str2=DOLLAR $CHAR W MONNAME xxxxxx
|
||||
);
|
||||
%mp_assertscope(COMPARE,ignorelist=x)
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"&x"="DOLLAR $CHAR W MONNAME"
|
||||
@@ -18,3 +23,92 @@
|
||||
desc=Checking basic string,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* word boundary - var should not match var1 or var10 */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1andstr2(str1=var1 var10,str2=var var1)"="var1"
|
||||
),
|
||||
desc=Checking word boundaries,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* case sensitivity - dollar does not match DOLLAR */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1andstr2(str1=DOLLAR dollar,str2=DOLLAR)"="DOLLAR"
|
||||
),
|
||||
desc=Checking case sensitivity,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* duplicate words in str1 are preserved */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1andstr2(str1=a a b,str2=a)"="a a"
|
||||
),
|
||||
desc=Checking duplicate words,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* when no words match, nothing is returned */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1andstr2(str1=a b,str2=c d)"=""
|
||||
),
|
||||
desc=Checking empty result,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* when str1 is empty, nothing is returned */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1andstr2(str1=,str2=a b)"=""
|
||||
),
|
||||
desc=Checking empty str1,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* when str2 is empty, nothing is returned */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1andstr2(str1=a b,str2=)"=""
|
||||
),
|
||||
desc=Checking empty str2,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* build strings containing 1000 variables */
|
||||
/* str2 is kept to 100 words to avoid excessive macro iterations */
|
||||
data _null_;
|
||||
length str1 str2 $32767;
|
||||
do i=1 to 1000;
|
||||
word=cats('var',i);
|
||||
str1=catx(' ',str1,word);
|
||||
if mod(i,10)=0 then str2=catx(' ',str2,word);
|
||||
end;
|
||||
call symputx('str1',str1);
|
||||
call symputx('str2',str2);
|
||||
run;
|
||||
|
||||
%mp_assertscope(SNAPSHOT)
|
||||
%let result=%mf_wordsinstr1andstr2(str1=&str1,str2=&str2);
|
||||
%mp_assertscope(COMPARE,ignorelist=result)
|
||||
|
||||
%let count=%sysfunc(countw(&result));
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"&count"="100"
|
||||
),
|
||||
desc=Checking 1000 variable string returns 100 words,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"&result"="&str2"
|
||||
),
|
||||
desc=Checking 1000 variable string content,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
@@ -5,12 +5,17 @@
|
||||
<h4> SAS Macros </h4>
|
||||
@li mf_wordsinstr1butnotstr2.sas
|
||||
@li mp_assert.sas
|
||||
@li mp_assertscope.sas
|
||||
|
||||
**/
|
||||
|
||||
/* basic test, with scope check */
|
||||
%mp_assertscope(SNAPSHOT)
|
||||
%let x=%mf_wordsinstr1butnotstr2(str1=xx DOLLAR x $CHAR xxx W MONNAME
|
||||
,str2=ff xx x xxx xxxxxx
|
||||
);
|
||||
%mp_assertscope(COMPARE,ignorelist=x)
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"&x"="DOLLAR $CHAR W MONNAME"
|
||||
@@ -18,3 +23,95 @@
|
||||
desc=Checking basic string,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* word boundary - var1 should not match var10 or var100 */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1butnotstr2(str1=var1 var10 var100,str2=var1)"
|
||||
="var10 var100"
|
||||
),
|
||||
desc=Checking word boundaries,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* case sensitivity - dollar does not match DOLLAR */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1butnotstr2(str1=DOLLAR dollar,str2=DOLLAR)"="dollar"
|
||||
),
|
||||
desc=Checking case sensitivity,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* duplicate words in str1 are preserved */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1butnotstr2(str1=a a b a,str2=b)"="a a a"
|
||||
),
|
||||
desc=Checking duplicate words,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* when all words match, nothing is returned */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1butnotstr2(str1=a b,str2=b a)"=""
|
||||
),
|
||||
desc=Checking empty result,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* when str1 is empty, nothing is returned */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1butnotstr2(str1=,str2=a b)"=""
|
||||
),
|
||||
desc=Checking empty str1,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* when str2 is empty, all of str1 is returned */
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"%mf_wordsinstr1butnotstr2(str1=a b c,str2=)"="a b c"
|
||||
),
|
||||
desc=Checking empty str2 returns all words,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
/* build strings containing 1000 variables */
|
||||
/* str2 is kept to 100 words to avoid excessive macro iterations */
|
||||
data _null_;
|
||||
length str1 str2 expected $32767;
|
||||
do i=1 to 1000;
|
||||
word=cats('var',i);
|
||||
str1=catx(' ',str1,word);
|
||||
if mod(i,10)=0 then str2=catx(' ',str2,word);
|
||||
else expected=catx(' ',expected,word);
|
||||
end;
|
||||
call symputx('str1',str1);
|
||||
call symputx('str2',str2);
|
||||
call symputx('expected',expected);
|
||||
run;
|
||||
|
||||
%mp_assertscope(SNAPSHOT)
|
||||
%let result=%mf_wordsinstr1butnotstr2(str1=&str1,str2=&str2);
|
||||
%mp_assertscope(COMPARE,ignorelist=result)
|
||||
|
||||
%let count=%sysfunc(countw(&result));
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"&count"="900"
|
||||
),
|
||||
desc=Checking 1000 variable string returns 900 words,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(
|
||||
"&result"="&expected"
|
||||
),
|
||||
desc=Checking 1000 variable string content,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
@@ -11,9 +11,20 @@
|
||||
filename webref temp;
|
||||
|
||||
data demo;
|
||||
length x $100;
|
||||
do x='"','0A'x,'0D'x,'09'x,'00'x,'0E'x,'0F'x,'01'x,'02'x,'10'x,'11'x,'\';
|
||||
output;
|
||||
end;
|
||||
/* embedded quote variants */
|
||||
x='say "hi" there'; output;
|
||||
x='"fully quoted"'; output;
|
||||
x='back\slash'; output;
|
||||
x='quote and back\"slash'; output;
|
||||
/* leading / trailing blank variants */
|
||||
x=' leading blanks'; output;
|
||||
x=' "leading blanks and quotes"'; output;
|
||||
x='trailing blanks '; output;
|
||||
x=' both '; output;
|
||||
run;
|
||||
%mp_jsonout(OPEN,jref=webref)
|
||||
%mp_jsonout(OBJ,demo,jref=webref)
|
||||
@@ -46,8 +57,19 @@ describe table web.demo;
|
||||
proc compare base=work.demo compare=web.demo(keep=x);
|
||||
quit;
|
||||
|
||||
/* sysinfo is a bitmask - keep only data-related bits, ie:
|
||||
64 Base data set has observation not in comparison
|
||||
128 Comparison data set has observation not in base
|
||||
4096 A value comparison was unequal
|
||||
32768 Number of observations differ
|
||||
Attribute diffs (eg 16 - variable length) are ignored, as a JSON
|
||||
round trip will not preserve lengths/formats/labels.
|
||||
*/
|
||||
/* SYSINFO is read only, so store the masked value in a new variable */
|
||||
%let sysinfo_masked=%sysfunc(band(&sysinfo, 64+128+4096+32768));
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(&sysinfo=0),
|
||||
iftrue=(&sysinfo_masked=0),
|
||||
desc=Returned json is identical to input table for all special chars,
|
||||
outds=work.test_results
|
||||
)
|
||||
|
||||
@@ -32,4 +32,55 @@ run;
|
||||
%mp_assert(
|
||||
iftrue=(%str(&checkval)=%str(&sysvlong)),
|
||||
desc=Check if the sysvlong value was created
|
||||
)
|
||||
|
||||
/*
|
||||
Test that ms_webout(FETCH) retains leading blanks in character values
|
||||
(simulates the CSV format generated by the sasjs adapter, ie an input
|
||||
statement in the first row followed by unquoted data)
|
||||
*/
|
||||
%let fref2=%mf_getuniquefileref();
|
||||
data _null_;
|
||||
file &fref2 lrecl=32767 termstr=crlf;
|
||||
put 'col1:$char10. col2:best.';
|
||||
put ' padded,1';
|
||||
run;
|
||||
%global _webin_fileref _webin_name;
|
||||
%let _webin_fileref=&fref2;
|
||||
%let _webin_name=leadblank;
|
||||
%let _webin_file_count=1;
|
||||
%ms_webout(FETCH)
|
||||
|
||||
data _null_;
|
||||
set leadblank;
|
||||
if col1=' padded' then call symputx('checkblank','PASS');
|
||||
else call symputx('checkblank',cats('FAIL:',col1));
|
||||
run;
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(&checkblank=PASS),
|
||||
desc=ms_webout FETCH retains leading blanks with $char informat
|
||||
)
|
||||
|
||||
/* same test, but with a plain $ informat (as sent by some clients) */
|
||||
%let fref3=%mf_getuniquefileref();
|
||||
data _null_;
|
||||
file &fref3 lrecl=32767 termstr=crlf;
|
||||
put 'col1:$10. col2:best.';
|
||||
put ' padded,1';
|
||||
run;
|
||||
%let _webin_fileref=&fref3;
|
||||
%let _webin_name=leadblank2;
|
||||
%let _webin_file_count=1;
|
||||
%ms_webout(FETCH)
|
||||
|
||||
data _null_;
|
||||
set leadblank2;
|
||||
if col1=' padded' then call symputx('checkblank2','PASS');
|
||||
else call symputx('checkblank2',cats('FAIL:',col1));
|
||||
run;
|
||||
|
||||
%mp_assert(
|
||||
iftrue=(&checkblank2=PASS),
|
||||
desc=ms_webout FETCH retains leading blanks with $ informat
|
||||
)
|
||||
@@ -44,6 +44,7 @@ data work.somedata1 work.somedata2;
|
||||
x=1;
|
||||
y=' t"w"o';
|
||||
z=.z;
|
||||
y2=' two';
|
||||
label x='x factor';
|
||||
output;
|
||||
run;
|
||||
@@ -58,14 +59,14 @@ run;
|
||||
%let test1=FAIL;
|
||||
data _null_;
|
||||
set testlib1.somedata1;
|
||||
if x=1 and y=' t"w"o' and z="Z" then call symputx('test1','PASS');
|
||||
if x=1 and y=' t"w"o' and z="Z" and y2=' two' then call symputx('test1','PASS');
|
||||
putlog (_all_)(=);
|
||||
run;
|
||||
|
||||
%let test2=FAIL;
|
||||
data _null_;
|
||||
set testlib1.somedata2;
|
||||
if x=1 and y=' t"w"o' and z="Z" then call symputx('test2','PASS');
|
||||
if x=1 and y=' t"w"o' and z="Z" and y2=' two' then call symputx('test2','PASS');
|
||||
putlog (_all_)(=);
|
||||
run;
|
||||
|
||||
|
||||
@@ -497,7 +497,8 @@ data _null_;
|
||||
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
||||
put ' )))))))))))))!!''"''; ';
|
||||
put ' end; ';
|
||||
put ' else &&name&i=quote(cats(&&name&i)); ';
|
||||
put ' /* trim (not cats) so leading blanks are retained */ ';
|
||||
put ' else &&name&i=''"''!!trim(&&name&i)!!''"''; ';
|
||||
put ' %end; ';
|
||||
put ' %end; ';
|
||||
put ' run; ';
|
||||
@@ -643,7 +644,10 @@ data _null_;
|
||||
put ' data _null_; ';
|
||||
put ' infile "%sysfunc(pathname(work))/&table..csv" termstr=crlf ; ';
|
||||
put ' input; ';
|
||||
put ' if _n_=1 then call symputx(''input_statement'',_infile_); ';
|
||||
put ' /* a plain $ informat strips leading blanks - use $char instead */ ';
|
||||
put ' if _n_=1 then call symputx(''input_statement'' ';
|
||||
put ' ,prxchange(''s/:\$(?=[0-9 ])/:\$char/i'',-1,_infile_) ';
|
||||
put ' ); ';
|
||||
put ' list; ';
|
||||
put ' data work.&table; ';
|
||||
put ' infile "%sysfunc(pathname(work))/&table..csv" firstobs=2 dsd ';
|
||||
@@ -663,7 +667,10 @@ data _null_;
|
||||
put ' data _null_; ';
|
||||
put ' infile indata termstr=crlf lrecl=32767; ';
|
||||
put ' input; ';
|
||||
put ' if _n_=1 then call symputx(''input_statement'',_infile_); ';
|
||||
put ' /* a plain $ informat strips leading blanks - use $char instead */ ';
|
||||
put ' if _n_=1 then call symputx(''input_statement'' ';
|
||||
put ' ,prxchange(''s/:\$(?=[0-9 ])/:\$char/i'',-1,_infile_) ';
|
||||
put ' ); ';
|
||||
put ' %if %str(&_debug) ge 128 %then %do; ';
|
||||
put ' if _n_<20 then putlog _infile_; ';
|
||||
put ' else stop; ';
|
||||
|
||||
+8
-2
@@ -104,7 +104,10 @@
|
||||
data _null_;
|
||||
infile "%sysfunc(pathname(work))/&table..csv" termstr=crlf ;
|
||||
input;
|
||||
if _n_=1 then call symputx('input_statement',_infile_);
|
||||
/* a plain $ informat strips leading blanks - use $char instead */
|
||||
if _n_=1 then call symputx('input_statement'
|
||||
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||
);
|
||||
list;
|
||||
data work.&table;
|
||||
infile "%sysfunc(pathname(work))/&table..csv" firstobs=2 dsd
|
||||
@@ -124,7 +127,10 @@
|
||||
data _null_;
|
||||
infile indata termstr=crlf lrecl=32767;
|
||||
input;
|
||||
if _n_=1 then call symputx('input_statement',_infile_);
|
||||
/* a plain $ informat strips leading blanks - use $char instead */
|
||||
if _n_=1 then call symputx('input_statement'
|
||||
,prxchange('s/:\$(?=[0-9 ])/:\$char/i',-1,_infile_)
|
||||
);
|
||||
%if %str(&_debug) ge 128 %then %do;
|
||||
if _n_<20 then putlog _infile_;
|
||||
else stop;
|
||||
|
||||
Reference in New Issue
Block a user