How might you implement mocking (for unit testing) in a generic Forth? #99
Replies: 4 comments
-
You could redefine the words you want in a testing harness and make your
test cases use (e.g. include) the harness.
Test cases would then reference mocked words, and all references would be
resolved at compile time instead of run time.
Le jeu. 27 mai 2021 à 19:38, Rick Carlino ***@***.***> a
écrit :
… One idea I have had is to do vectored execution for all words that trigger
side effects.
For example, if you need to write to STDOUT (a side effect), you would
wrap the ." word in a second word that contains the XT of .". Under
normal execution, your wrapper word would call the XT of .". In your test
suite, you would change the value of the XT to point to a "dummy" version
of ." that does not actually write to STDOUT. That way, your test suite
can run tests without actually performing the side effect.
Are there other ways to accomplish this?
NOTE: This is a cross post of my discussion on /r/Forth (Reddit)
<https://www.reddit.com/r/Forth/comments/nm71ac/how_might_you_implement_mocking_for_unit_testing/>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#99>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB5UKXHRDUHYFU3C5WWRR2TTPZ7RFANCNFSM45UYXM4A>
.
|
Beta Was this translation helpful? Give feedback.
-
There's a lot of difficulties in making something like this work in a "generic" Forth (whatever that means... maybe 200x?). For example: : ." ... ;
: some-word ." foo" ;
' ." defer ." is ."
: test-."
['] dummy-." is ." some-word
; When |
Beta Was this translation helpful? Give feedback.
-
Most Forth systems I know already feature a vectored I/O. The easiest approach is to vector Gforth : xtype nip 0 ?do [char] x emit loop ; redefined xtype ok
' xtype is type or if no side effect is wanted: ' 2drop is type
' drop is emit You can always check the current state of a deferred word with action-of, that way you can make an VFX Mecrisp |
Beta Was this translation helpful? Give feedback.
-
I know you should know that ." puts a return value for a completion of
it's function FVN (Forth Virtual Machine state) on the return stacke, vs
the data stack.
In my figgish I reset HERE to where it was before that word's compilation
bombed.
In forth you tend to your messes.
…On Thu, May 27, 2021 at 1:13 PM Jeffrey Massung ***@***.***> wrote:
There's a lot of difficulties in making something like this work in a
"generic" Forth (whatever that means... maybe 200x?). For example:
: ." ... ;
: some-word ." foo" ;
' ." defer ." is ."
: test-."
['] dummy-." is ." some-word
;
When test-." is executed, some-word is still going to execute the
original version of ." on most (generic) Forths. In order for this to
actually meet the intended goals, I'd think a Forth would need to have some
version of Common Lisp's dynamically-scoped variables or at least the
concept of an "output destination", be able to save/restore destinations as
easily as it does input sources, and then side-effect words would need to
written at the core to use them.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#99 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABILVRKSUM54IWLWJVHRQHDTP2DUVANCNFSM45UYXM4A>
.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
One idea I have had is to do vectored execution for all words that trigger side effects.
For example, if you need to write to STDOUT (a side effect), you would wrap the
."
word in a second word that contains the XT of."
. Under normal execution, your wrapper word would call the XT of."
. In your test suite, you would change the value of the XT to point to a "dummy" version of."
that does not actually write to STDOUT. That way, your test suite can run tests without actually performing the side effect.Are there other ways to accomplish this?
NOTE: This is a cross post of my discussion on /r/Forth (Reddit)
Beta Was this translation helpful? Give feedback.
All reactions