lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Ben Sunshine-Hill wrote:

> Edit: heh, just realized the problem with that. nevermind. 
> 
> > function trace(x)
> >    print(debug.getlocal(1, 1), x)
> > end

I'm curious what you thought was wrong. This works:

function AssertEqual(comparator, comparahend, kvetch)

    local comparatorValue  = nil
    local comparahendValue = nil
    local idx = 1
    
    while true do
        local name, value = debug.getlocal(2, idx)
        if not name then break end
        if name == comparator  then comparatorValue  = value end
        if name == comparahend then comparahendValue = value end
        idx = idx + 1
    end

    if comparatorValue ~= comparahendValue then
        DebugOutput( "TESTER: Test " .. testnum .. 
                     "--Failure! " .. kvetch ..
                     ". " .. comparator ..
                     "{" .. comparatorValue ..
                     "} ~= " .. comparahend .. 
                     "{" .. comparahendValue .. "}" )
    else
        success_()
    end

end

Of course, as a TDD zealot, I want to have _expressions_ in the
arguments, but local variables names, in strings are a happy
alternative:

    local foo = "bar"
    local bar = "foo"
    AssertEqual("foo", "bar", "Polyphonic Spree throw\' down")

That emits this:

    TESTER: Test 1--Failure! Polyphonic Spree throw\' down. foo{bar} ~=
bar{foo}

--
  Phlip