1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-07 01:20:05 +00:00

Compare commits

...

11 Commits

Author SHA1 Message Date
Allan Bowe
d254870439 Merge pull request #164 from sasjs/mf_verify
fix: updating mm_x macros following fix to mf_verifymacvars
2022-02-06 20:58:55 +02:00
munja
303225cb85 fix: updating mm_x macros following fix to mf_verifymacvars 2022-02-06 19:57:52 +01:00
Allan Bowe
90de167643 Merge pull request #163 from sasjs/mf_verfiy
fix: updating mf_abort param in mf_verifymacvars, also fixing return …
2022-02-06 17:16:54 +02:00
munja
8ee997de8e fix: updating mf_abort param in mf_verifymacvars, also fixing return code as per documentation, adding a test, and updating the header info 2022-02-06 16:11:18 +01:00
Allan Bowe
e27f6ac716 Merge pull request #162 from sasjs/mf_getapploc
fix: adding support for testsetup and testteardown in mf_getapploc.sas
2022-02-05 22:56:10 +02:00
munja
ec4de95fcf fix: reset syscc for testterm syscc check 2022-02-05 21:55:50 +01:00
munja
df0fa95519 fix: adding sasjs/core dependency - see: https://github.com/sasjs/cli/issues/1113 2022-02-05 21:29:03 +01:00
munja
2fe7fba79b fix: adding support for testsetup and testteardown in mf_getapploc.sas 2022-02-05 21:19:26 +01:00
Allan Bowe
e40234ee29 Merge pull request #160 from sasjs/allanbowe-patch-1
chore(docs): Update README.md to clarify LUA prefixes
2022-02-04 20:56:51 +02:00
Allan Bowe
a287cc27a7 Update README.md 2022-02-04 18:56:19 +00:00
munja
921186eb74 fix: adding images to mp_streamfile.sas 2022-02-03 20:17:43 +01:00
14 changed files with 165 additions and 39 deletions

View File

@@ -81,7 +81,7 @@ Macros used for interfacing with SAS Viya.
Wait - this is a macro library - what is LUA doing here? Well, it is a little known fact that you CAN run LUA within a SAS Macro. It has to be written to a text file with a `.lua` extension, from where you can `%include` it. So, without using the `proc lua` wrapper. Wait - this is a macro library - what is LUA doing here? Well, it is a little known fact that you CAN run LUA within a SAS Macro. It has to be written to a text file with a `.lua` extension, from where you can `%include` it. So, without using the `proc lua` wrapper.
To contribute, simply write your freeform LUA in the LUA folder. Then run the `build.py`, which will convert your LUA into a data step with put statements, and create the macro wrapper with a `ml_` prefix. You can then use your module in any program by running: To contribute, simply write your freeform LUA in the LUA folder. Then run the `build.py`, which will convert all files with a ".lua" extension into a macro wrapper with an `ml_` prefix (embedding the necessary data step put statements). You can then use your module in any program by running:
```sas ```sas
/* compile the lua module */ /* compile the lua module */
@@ -95,8 +95,7 @@ endsubmit;
run; run;
``` ```
- X command enabled - Prefixes: _ml_
- Prefixes: _mmw_,_mmu_,_mmx_
## Installation ## Installation
@@ -129,11 +128,11 @@ filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
- _mf_ for macro functions (can be used in open code). - _mf_ for macro functions (can be used in open code).
- _ml_ for macros that are used to compile LUA modules - _ml_ for macros that are used to compile LUA modules
- _mm_ for metadata macros (interface with the metadata server). - _mm_ for metadata macros (interface with the metadata server).
- _mmx_ for macros that use metadata and are XCMD enabled - _mmx_ for macros that use metadata and are XCMD enabled (working on both windows and unix)
- _mp_ for macro procedures (which generate sas code) - _mp_ for macro procedures (which generate sas code)
- _ms_ for macro procedures that will only work with [@sasjs/server](https://github.com/sasjs/server) - _ms_ for macro procedures that will only work with [@sasjs/server](https://github.com/sasjs/server)
- _mv_ for macro procedures that will only work in Viya - _mv_ for macro procedures that will only work in Viya
- _mx_ for macros that are XCMD enabled - _mx_ for macros that are XCMD enabled (working on both windows and unix)
- follow verb-noun convention - follow verb-noun convention
- unix style line endings (lf) - unix style line endings (lf)
- individual lines should be no more than 80 characters long - individual lines should be no more than 80 characters long

68
all.sas
View File

@@ -352,6 +352,7 @@ https://github.com/yabwon/SAS_PACKAGES/blob/main/packages/baseplus.md#functionex
@li /data @li /data
@li /jobs @li /jobs
@li /services @li /services
@li /tests
@li /tests/jobs @li /tests/jobs
@li /tests/services @li /tests/services
@li /tests/macros @li /tests/macros
@@ -383,9 +384,13 @@ https://github.com/yabwon/SAS_PACKAGES/blob/main/packages/baseplus.md#functionex
/** /**
* First check we are not in the tests/macros folder (which has no subfolders) * First check we are not in the tests/macros folder (which has no subfolders)
* or specifically in the testsetup or testteardown services
*/ */
%if %index(&pgm,/tests/macros/) %then %do; %if %index(&pgm,/tests/macros/)
%let root=%substr(&pgm,1,%index(&pgm,/tests/macros)-1); or %index(&pgm,/tests/testsetup)
or %index(&pgm,/tests/testteardown)
%then %do;
%let root=%substr(&pgm,1,%index(&pgm,/tests)-1);
&root &root
%return; %return;
%end; %end;
@@ -1802,7 +1807,7 @@ Usage:
%mend mf_uid;/** %mend mf_uid;/**
@file @file
@brief Checks if a set of macro variables exist / contain values. @brief Checks if a set of macro variables exist AND contain values.
@details Writes ERROR to log if abortType is SOFT, else will call %mf_abort. @details Writes ERROR to log if abortType is SOFT, else will call %mf_abort.
Usage: Usage:
@@ -1816,10 +1821,11 @@ Usage:
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mf_abort.sas @li mf_abort.sas
@param verifyvars space separated list of macro variable names @param [in] verifyvars Space separated list of macro variable names
@param makeupcase= set to YES to convert all variable VALUES to @param [in] makeupcase= (NO) Set to YES to convert all variable VALUES to
uppercase. uppercase.
@param mAbort= Abort Type. Default is SOFT (writes err to log). @param [in] mAbort= (SOFT) Abort Type. When SOFT, simply writes an err
message to the log.
Set to any other value to call mf_abort (which can be configured to abort in Set to any other value to call mf_abort (which can be configured to abort in
various fashions according to context). various fashions according to context).
@@ -1860,9 +1866,15 @@ Usage:
%goto exit_success; %goto exit_success;
%exit_err: %exit_err:
%if &mAbort=SOFT %then %put %str(ERR)OR: &abortmsg; %put %str(ERR)OR: &abortmsg;
%else %mf_abort(mac=mf_verifymacvars,type=&mabort,msg=&abortmsg); %mf_abort(iftrue=(&mabort ne SOFT),
mac=mf_verifymacvars,
msg=%str(&abortmsg)
)
0
%return;
%exit_success: %exit_success:
1
%mend mf_verifymacvars; %mend mf_verifymacvars;
/** /**
@@ -10869,6 +10881,17 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%end; %end;
%else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do;
%if &platform=SASMETA and &streamweb=1 %then %do;
data _null_;
rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)");
run;
%end;
%else %if &platform=SASVIYA %then %do;
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI"
contenttype="image/%lowcase(&contenttype)";
%end;
%end;
%else %if &contentype=HTML %then %do; %else %if &contentype=HTML %then %do;
%if &platform=SASVIYA %then %do; %if &platform=SASVIYA %then %do;
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json" filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
@@ -12592,7 +12615,10 @@ run;
%&mD.put Executing &sysmacroname..sas; %&mD.put Executing &sysmacroname..sas;
%&mD.put _local_; %&mD.put _local_;
%mf_verifymacvars(tree name) %mp_abort(iftrue= (%mf_verifymacvars(tree name)=0)
,mac=&sysmacroname
,msg=%str(Empty inputs: tree name)
)
/** /**
* check tree exists * check tree exists
@@ -12816,7 +12842,10 @@ run;
%&mD.put Executing &sysmacroname..sas; %&mD.put Executing &sysmacroname..sas;
%&mD.put _local_; %&mD.put _local_;
%mf_verifymacvars(tree name) %mp_abort(iftrue= (%mf_verifymacvars(tree name)=0)
,mac=&sysmacroname
,msg=%str(Empty inputs: tree name)
)
/** /**
* check tree exists * check tree exists
@@ -13185,12 +13214,14 @@ run;
filename &frefin temp; filename &frefin temp;
filename &frefout temp; filename &frefout temp;
%mp_abort(iftrue= (
&engine=BASE & %mf_verifymacvars(libname libref engine servercontext tree)=0
)
,mac=&sysmacroname
,msg=%str(Empty inputs: libname libref engine servercontext tree)
)
%if &engine=BASE %then %do; %if &engine=BASE %then %do;
%mf_verifymacvars(libname libref engine servercontext tree)
/** /**
* Check that the ServerContext exists * Check that the ServerContext exists
*/ */
@@ -13481,7 +13512,12 @@ filename &frefout temp;
%&mD.put Executing mm_CreateSTP.sas; %&mD.put Executing mm_CreateSTP.sas;
%&mD.put _local_; %&mD.put _local_;
%mf_verifymacvars(stpname filename directory tree) %mp_abort(
iftrue=(%mf_verifymacvars(stpname filename directory tree)=0)
,mac=&sysmacroname
,msg=%str(Empty inputs: stpname filename directory tree)
)
%mp_dropmembers(%scan(&outds,2,.)) %mp_dropmembers(%scan(&outds,2,.))
/** /**

View File

@@ -15,6 +15,7 @@
@li /data @li /data
@li /jobs @li /jobs
@li /services @li /services
@li /tests
@li /tests/jobs @li /tests/jobs
@li /tests/services @li /tests/services
@li /tests/macros @li /tests/macros
@@ -46,9 +47,13 @@
/** /**
* First check we are not in the tests/macros folder (which has no subfolders) * First check we are not in the tests/macros folder (which has no subfolders)
* or specifically in the testsetup or testteardown services
*/ */
%if %index(&pgm,/tests/macros/) %then %do; %if %index(&pgm,/tests/macros/)
%let root=%substr(&pgm,1,%index(&pgm,/tests/macros)-1); or %index(&pgm,/tests/testsetup)
or %index(&pgm,/tests/testteardown)
%then %do;
%let root=%substr(&pgm,1,%index(&pgm,/tests)-1);
&root &root
%return; %return;
%end; %end;

View File

@@ -1,6 +1,6 @@
/** /**
@file @file
@brief Checks if a set of macro variables exist / contain values. @brief Checks if a set of macro variables exist AND contain values.
@details Writes ERROR to log if abortType is SOFT, else will call %mf_abort. @details Writes ERROR to log if abortType is SOFT, else will call %mf_abort.
Usage: Usage:
@@ -14,10 +14,11 @@
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mf_abort.sas @li mf_abort.sas
@param verifyvars space separated list of macro variable names @param [in] verifyvars Space separated list of macro variable names
@param makeupcase= set to YES to convert all variable VALUES to @param [in] makeupcase= (NO) Set to YES to convert all variable VALUES to
uppercase. uppercase.
@param mAbort= Abort Type. Default is SOFT (writes err to log). @param [in] mAbort= (SOFT) Abort Type. When SOFT, simply writes an err
message to the log.
Set to any other value to call mf_abort (which can be configured to abort in Set to any other value to call mf_abort (which can be configured to abort in
various fashions according to context). various fashions according to context).
@@ -58,8 +59,14 @@
%goto exit_success; %goto exit_success;
%exit_err: %exit_err:
%if &mAbort=SOFT %then %put %str(ERR)OR: &abortmsg; %put %str(ERR)OR: &abortmsg;
%else %mf_abort(mac=mf_verifymacvars,type=&mabort,msg=&abortmsg); %mf_abort(iftrue=(&mabort ne SOFT),
mac=mf_verifymacvars,
msg=%str(&abortmsg)
)
0
%return;
%exit_success: %exit_success:
1
%mend mf_verifymacvars; %mend mf_verifymacvars;

View File

@@ -81,6 +81,17 @@ run;
contentdisp="attachment; filename=&outname"; contentdisp="attachment; filename=&outname";
%end; %end;
%end; %end;
%else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do;
%if &platform=SASMETA and &streamweb=1 %then %do;
data _null_;
rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)");
run;
%end;
%else %if &platform=SASVIYA %then %do;
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI"
contenttype="image/%lowcase(&contenttype)";
%end;
%end;
%else %if &contentype=HTML %then %do; %else %if &contentype=HTML %then %do;
%if &platform=SASVIYA %then %do; %if &platform=SASVIYA %then %do;
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json" filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"

View File

@@ -59,7 +59,10 @@
%&mD.put Executing &sysmacroname..sas; %&mD.put Executing &sysmacroname..sas;
%&mD.put _local_; %&mD.put _local_;
%mf_verifymacvars(tree name) %mp_abort(iftrue= (%mf_verifymacvars(tree name)=0)
,mac=&sysmacroname
,msg=%str(Empty inputs: tree name)
)
/** /**
* check tree exists * check tree exists

View File

@@ -47,7 +47,10 @@
%&mD.put Executing &sysmacroname..sas; %&mD.put Executing &sysmacroname..sas;
%&mD.put _local_; %&mD.put _local_;
%mf_verifymacvars(tree name) %mp_abort(iftrue= (%mf_verifymacvars(tree name)=0)
,mac=&sysmacroname
,msg=%str(Empty inputs: tree name)
)
/** /**
* check tree exists * check tree exists

View File

@@ -133,12 +133,14 @@ run;
filename &frefin temp; filename &frefin temp;
filename &frefout temp; filename &frefout temp;
%mp_abort(iftrue= (
&engine=BASE & %mf_verifymacvars(libname libref engine servercontext tree)=0
)
,mac=&sysmacroname
,msg=%str(Empty inputs: libname libref engine servercontext tree)
)
%if &engine=BASE %then %do; %if &engine=BASE %then %do;
%mf_verifymacvars(libname libref engine servercontext tree)
/** /**
* Check that the ServerContext exists * Check that the ServerContext exists
*/ */

View File

@@ -108,7 +108,12 @@
%&mD.put Executing mm_CreateSTP.sas; %&mD.put Executing mm_CreateSTP.sas;
%&mD.put _local_; %&mD.put _local_;
%mf_verifymacvars(stpname filename directory tree) %mp_abort(
iftrue=(%mf_verifymacvars(stpname filename directory tree)=0)
,mac=&sysmacroname
,msg=%str(Empty inputs: stpname filename directory tree)
)
%mp_dropmembers(%scan(&outds,2,.)) %mp_dropmembers(%scan(&outds,2,.))
/** /**

15
package-lock.json generated
View File

@@ -7,7 +7,8 @@
"name": "@sasjs/core", "name": "@sasjs/core",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@sasjs/cli": "3.6.0" "@sasjs/cli": "3.6.0",
"@sasjs/core": "4.4.4"
} }
}, },
"node_modules/@sasjs/adapter": { "node_modules/@sasjs/adapter": {
@@ -108,6 +109,12 @@
"valid-url": "^1.0.9" "valid-url": "^1.0.9"
} }
}, },
"node_modules/@sasjs/core": {
"version": "4.4.4",
"resolved": "https://registry.npmjs.org/@sasjs/core/-/core-4.4.4.tgz",
"integrity": "sha512-gN6d0fvhaofp7buemS5KIOo5Bz8lbqhsEQD7SuH5FZ02MQurmfu7A0Zg0lIEi0w2/ptI4M/sZdF4D2DRh1D5xA==",
"dev": true
},
"node_modules/@sasjs/lint": { "node_modules/@sasjs/lint": {
"version": "1.11.2", "version": "1.11.2",
"resolved": "https://registry.npmjs.org/@sasjs/lint/-/lint-1.11.2.tgz", "resolved": "https://registry.npmjs.org/@sasjs/lint/-/lint-1.11.2.tgz",
@@ -2822,6 +2829,12 @@
} }
} }
}, },
"@sasjs/core": {
"version": "4.4.4",
"resolved": "https://registry.npmjs.org/@sasjs/core/-/core-4.4.4.tgz",
"integrity": "sha512-gN6d0fvhaofp7buemS5KIOo5Bz8lbqhsEQD7SuH5FZ02MQurmfu7A0Zg0lIEi0w2/ptI4M/sZdF4D2DRh1D5xA==",
"dev": true
},
"@sasjs/lint": { "@sasjs/lint": {
"version": "1.11.2", "version": "1.11.2",
"resolved": "https://registry.npmjs.org/@sasjs/lint/-/lint-1.11.2.tgz", "resolved": "https://registry.npmjs.org/@sasjs/lint/-/lint-1.11.2.tgz",

View File

@@ -33,6 +33,7 @@
"prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true" "prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true"
}, },
"devDependencies": { "devDependencies": {
"@sasjs/cli": "3.6.0" "@sasjs/cli": "3.6.0",
"@sasjs/core": "4.4.4"
} }
} }

View File

@@ -46,4 +46,20 @@
), ),
desc=Checking tests/macros appLoc matches (which has no subfolder), desc=Checking tests/macros appLoc matches (which has no subfolder),
outds=work.test_results outds=work.test_results
)
%mp_assert(
iftrue=(
"%mf_getapploc(/some/area/tests/testsetup)"="/some/area"
),
desc=Checking tests/testsetup operation,
outds=work.test_results
)
%mp_assert(
iftrue=(
"%mf_getapploc(/some/area/tests/testteardown)"="/some/area"
),
desc=Checking tests/teardown operation,
outds=work.test_results
) )

View File

@@ -0,0 +1,22 @@
/**
@file
@brief Testing mf_verifymacvars macro
<h4> SAS Macros </h4>
@li mf_verifymacvars.sas
@li mp_assert.sas
@li mp_assertscope.sas
**/
%let var1=x;
%let var2=y;
%mp_assertscope(SNAPSHOT)
%mp_assert(
iftrue=(%mf_verifymacvars(var1 var2)=1),
desc=Checking macvars exist,
outds=work.test_results
)
%mp_assertscope(COMPARE)

View File

@@ -76,3 +76,6 @@ run;
iftrue=(&syscc ne 0), iftrue=(&syscc ne 0),
desc=Check that non zero return code is returned if called job fails desc=Check that non zero return code is returned if called job fails
) )
/* set syscc to zero for final check in testterm */
%let syscc=0;