[plt-scheme] check-expect not allowed in expression position?
Consider using schemeunit instead of check-expect. That's the
full-language test suite utility we expect to spend development effort
on in the future.
Robby
On Wed, Mar 31, 2010 at 12:03 AM, Carl Eastlund <cce at ccs.neu.edu> wrote:
> On Wed, Mar 31, 2010 at 1:41 AM, Danny Yoo <dyoo at cs.wpi.edu> wrote:
>> I was trying to use test-engine's check-expect to write a test case,
>> and I found myself wanting to use it in an expression position. I
>> came across the error:
>>
>> check-expect: found a test that is not at the top level
>>
>> I understand that, as a mechanism, all the test cases are
>> syntactically re-adjusted so that they're valid even if they're
>> referring to definitions defined after the tests. However, I thought
>> I might try to work around the limitation with the following macro.
>> The idea of my macro is to rearrange things enough to make
>> check-expect happy, but it doesn't work:
>>
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>> (define-syntax (check-expect* stx)
>> (syntax-case stx ()
>> [(_ observed expected)
>> (with-syntax ([observed-thunk
>> (syntax-local-lift-expression #'#f)]
>> [expected-thunk
>> (syntax-local-lift-expression #'#f)])
>> (begin
>> (syntax-local-lift-module-end-declaration
>> (syntax/loc stx
>> (check-expect (observed-thunk) (expected-thunk))))
>> (syntax/loc stx
>> (begin
>> (set! observed-thunk (lambda () observed))
>> (set! expected-thunk (lambda () expected))
>> (void)))))]))
>> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>>
>>
>> After seeing the error, I now understand that I misused
>> syntax-local-lift-module-end-declaration, which says that, in the way
>> I'm using it, eventually the thing being lifted will be expanded in
>> expression context. Of course, this isn't what I want: I want to lift
>> a syntax up to the module or top-level context. I can't find the
>> right primitive that does this. Am I missing something obvious?
>
> Danny,
>
> I resolved the issue of check-expect's context in Dracula by basically
> reimplementing the logic of check-expect. Mine works in any
> definition context (internal as well as top-level and module), but
> could easily be adapted to expressions as well. You can find the
> source code at:
>
> http://planet.plt-scheme.org/package-source/cce/dracula.plt/8/10/teachpacks/testing.ss
>
> --Carl
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>