Csound Csound-dev Csound-tekno Search About

[Csnd-dev] Unit Testing

Date2024-02-19 20:48
FromSteven Yi
Subject[Csnd-dev] Unit Testing
Hi All,

While doing the pass-by-ref work, I experimented with writing some
assert UDOs. I found this worked out well, and suggest we spend a
little time to create a unit-testing .orc library to support our
unit-testing needs for orc code. Here are two example UDOs I put
together:

opcode assert(condition:b, message:S):void
    if(!condition) then
        prints(message)
        exitnow(-1)
    endif
endop

opcode assertEquals(ival, iexpected):void
    if(ival != iexpected) then
        prints("Error: ival was %g, expected %g\n", ival, iexpected)
        exitnow(-1)
    endif
endop

I suspect this would be good not-only as part of our tests but more
broadly for Csound users developing their own code. We could look at
having a separate repo for this and add it as a git submodule, or
perhaps some other approach. (Ideas welcome here.)

Cheers!
Steven

Date2024-02-20 12:22
FromHlöðver Sigurðsson
SubjectRe: [Csnd-dev] Unit Testing
I made a similar PR for a built-in approach
https://github.com/csound/csound/pull/1663

On Mon, 19 Feb 2024 at 21:48, Steven Yi <stevenyi@gmail.com> wrote:
Hi All,

While doing the pass-by-ref work, I experimented with writing some
assert UDOs. I found this worked out well, and suggest we spend a
little time to create a unit-testing .orc library to support our
unit-testing needs for orc code. Here are two example UDOs I put
together:

opcode assert(condition:b, message:S):void
    if(!condition) then
        prints(message)
        exitnow(-1)
    endif
endop

opcode assertEquals(ival, iexpected):void
    if(ival != iexpected) then
        prints("Error: ival was %g, expected %g\n", ival, iexpected)
        exitnow(-1)
    endif
endop

I suspect this would be good not-only as part of our tests but more
broadly for Csound users developing their own code. We could look at
having a separate repo for this and add it as a git submodule, or
perhaps some other approach. (Ideas welcome here.)

Cheers!
Steven