I'll see what I can do to make my %Include.r script do this...
Also, I'll try to make these tests a simple object method call.
Andrew Martin
Delving in the unknown...
ICQ: 26227169
[EMAIL PROTECTED]
http://members.xoom.com/AndrewMartin/
-><-
----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, 21 January 2000 6:14 PM
Subject: [REBOL] How do I encapsulate a library fn and provide test cases
in python it is pretty simple
to make a script that can tell if it has
been included in another script.
when called as a unit on their own, these scripts
simply exercise some regression tests and stop.
in rebol tho?
I saw a preliminary for this in
do-example.r by Thomas Jensen
in the rebol.org library.
now I am hungry for more.
I would like an example I can replicate
all over my projects that meets the following:
- if called via some include.r type thing
my library fn or obj becomes part of the loaded environment.
as quietly as possible or appropriate
- if simply loaded via 'do
in the interactive command line or standalone
as the file named as arg2 to rebol.exe (or rebol on unixen)
my library fn can do some set of regression tests,
and then wait for more (back to normal behavior).
it is ok for 'do to call me again to rerun the tests.
'include of my fn followed by do of my fn should be quiet
the first time and regression the second cause the second
was not via an 'include.
- my library fn might load other library functions
via include and these should not run regression tests
unless loaded via 'do vs 'include like my own.
I am hopeful that include.r takes care
to protect _itself_ from being included multiple times.
if not, I try not to re-run it.
maybe there is a way for include.r to
let my library fn know it is at the top level
and then my lib fn can decide what to do.
a sketch: (feel free to edit in your replies)
REBOL [
Date: 4/February/2000
Author: "Bobr"
Rights: "Copyright © 2000, nic: br334"
File: %"cabbage-soup.r"
Title: "recipie for soup on cabbage diet"
Usage: {Include %cabbage-soup.r | do %cabbage-soup.r}
Purpose: {
actually to demonstrate usage of
regression test capability
}
Category: 'General
Example: {
print "running- Regression test..."
soup/regression
}
]
if ( not value? 'include ) [ do %include.r ]
if ( not value? 'soup ) [ ; prevent multiple inclusion/re'do
soup: make object! [
cabbage: 3 ; small heads
onions: 6 ; eew!
broth: 1 ; cans
carrots: 4 ; chopped or sliced
ratios: 3.6.1.4
regression: func [] [
print "testing ratios..."
if ratios = to-tuple [ cabbage onions broth carrots ]
[ print "ratios ok" ]
]
] ; object
] ; end-if-not-already defined (dont make the object prototype twice)
; this part is rerun as many times as 'do or 'include is called
if farblesnarz [ ; farblesnarz is a "technical" term
; but what -is- it?
; I need to see if I am NOT being included here
include do-example.r
doex: %cabbage-soup.r
]
{-----}
[EMAIL PROTECTED]