Testing Packages (Enhancement to CleanSlate)
- To: mathgroup at smc.vnet.net
 - Subject: [mg17059] Testing Packages (Enhancement to CleanSlate)
 - From: hanssen at zeiss.de
 - Date: Fri, 23 Apr 1999 02:32:04 -0400
 - Sender: owner-wri-mathgroup at wolfram.com
 
Hi, MathGroup,
When writing an testing packages, one often has to load the
package to be tested. There is a package CleanSlate, which helps
a lot. Using it, you frequently see yourself typing 
    CleanSlate["mypackage`"];
    Needs["mypackage`];
This is a little inconvenient, because you have to enclose
your context name in quotes and also you have to add the
context-mark character (the accent-grave). To overcome
this inconvenience, I have modified the CleanSlate package.
I always load the modified CleanSlate-package through Needs
from init.m:
The beginning of CleanSlate now reads
BeginPackage["CleanSlate`"];
Unprotect[Again,CleanSlate,CleanSlateExcept,ClearInOut];  (* add Again *)
Again::usage= 
"Again[context] is the same as (CleanSlate[context]; Needs[context];) - \n
Instead of a context-name enclosed in quotes it also accepts the  \n
context-name without the quotes and the context-mark at the end.";
Add the following to the body of the package CleanSlate, i.e. after
Begin["`Private`"];
(***************    Again    **************)
Again[context_] := 
Module[{aa}
      ,(If[Head[context]===Symbol
          ,CleanSlate[aa=ToString[context]<>"`"]; 
           Needs[aa]
          ,CleanSlate[context]; Needs[context]
          ];
       )
      ];		(* Again *)
The statement at the very end just before EndPackage[] now reads:
Protect[Again, ClearInOut, CleanSlate, CleanSlateExcept];  (* add Again *)
With these modifications, one can easily modify a package under test 
with a standard editor (e.g. PFE), reload and test it. This is done by
calling Again[mypackage] (provided mypackage is just a symbol
which has not been assigned a value).
If you have syntactical errors in the package (e.g. unbalanced comments, 
unbalanced quotes etc), then you have to "execute" the statement
EndPackage[];
in the notebook, where test your package, before calling 
Again[context].
kind regards
Dipl.-Math. Adelbert Hanszen