CUnit Query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gamename

    CUnit Query

    Hi,

    Is there some way to have cunit do a printf() when an assertion
    evaluates to false?

    Example:

    rc = foo()

    CU_ASSERT( rc == 0, printf("ERROR: foo returned %d", rc);

    The printf() doesn't necessariliy need to be associated in this way.
    The aim is to trigger a diagnostic printout when an assertion "fires".

    Thanks,
    -T

  • Roland Pibinger

    #2
    Re: CUnit Query

    On 25 Mar 2007 13:28:45 -0700, "gamename" wrote:
    >Is there some way to have cunit do a printf() when an assertion
    >evaluates to false?
    >
    >Example:
    >
    >rc = foo()
    >
    >CU_ASSERT( rc == 0, printf("ERROR: foo returned %d", rc);
    Don't know CUnit ...

    CU_ASSERT((rc == 0) ? 1 : (printf("ERROR: foo returned %d", rc), 0));

    .... which is not particularly elegant.
    >The printf() doesn't necessariliy need to be associated in this way.
    >The aim is to trigger a diagnostic printout when an assertion "fires".
    The problem is that the argument type (e.g. rc) is different for each
    CU_ASSERT so it is difficult to create a universal macro.

    Good luck,
    Roland Pibinger

    Comment

    • Flash Gordon

      #3
      Re: CUnit Query

      gamename wrote, On 25/03/07 21:28:
      Hi,
      >
      Is there some way to have cunit do a printf() when an assertion
      evaluates to false?
      You would be best asking in a group or mailing list where cunit is
      topical. There might be a "proper" way of doing it.
      Example:
      >
      rc = foo()
      >
      CU_ASSERT( rc == 0, printf("ERROR: foo returned %d", rc);
      >
      The printf() doesn't necessariliy need to be associated in this way.
      The aim is to trigger a diagnostic printout when an assertion "fires".
      In terms of C you would probably have to get clever with the conditional
      operator, but simple stuff with an if would be more readable.
      --
      Flash Gordon

      Comment

      • Keith Thompson

        #4
        Re: CUnit Query

        "gamename" <namesagame-usenet@yahoo.co mwrites:
        Is there some way to have cunit do a printf() when an assertion
        evaluates to false?
        >
        Example:
        >
        rc = foo()
        >
        CU_ASSERT( rc == 0, printf("ERROR: foo returned %d", rc);
        >
        The printf() doesn't necessariliy need to be associated in this way.
        The aim is to trigger a diagnostic printout when an assertion "fires".
        This is a question about CUnit, not about the C programming language,
        which is what we discuss here. Consult the CUnit documentation;
        failing that, try a forum that discusses CUnit. (The CUnit home page
        is <http://cunit.sourcefor ge.net/>; public forums are at
        <http://sourceforge.net/forum/?group_id=32992 >, but traffic is light.)

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
        San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
        "We must do something. This is something. Therefore, we must do this."
        -- Antony Jay and Jonathan Lynn, "Yes Minister"

        Comment

        • gamename

          #5
          Re: CUnit Query

          On Mar 25, 3:39 pm, Keith Thompson <k...@mib.orgwr ote:
          "gamename" <namesagame-use...@yahoo.co mwrites:
          Is there some way to have cunit do a printf() when an assertion
          evaluates to false?
          >
          Example:
          >
          rc = foo()
          >
          CU_ASSERT( rc == 0, printf("ERROR: foo returned %d", rc);
          >
          The printf() doesn't necessariliy need to be associated in this way.
          The aim is to trigger a diagnostic printout when an assertion "fires".
          >
          This is a question about CUnit, not about the C programming language,
          which is what we discuss here. Consult the CUnit documentation;
          Fair enough.
          failing that, try a forum that discusses CUnit. (The CUnit home page
          is <http://cunit.sourcefor ge.net/>; public forums are at
          <http://sourceforge.net/forum/?group_id=32992 >, but traffic is light.)
          Yeah, I noticed. The thing seems to be used all over the place. But
          there isn't an obvious forum to discuss it. There are a few mentions
          of it here in the archives, so I went that route.

          Thanks anyway.
          -T
          >
          --
          Keith Thompson (The_Other_Keit h) k...@mib.org <http://www.ghoti.net/~kst>
          San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
          "We must do something. This is something. Therefore, we must do this."
          -- Antony Jay and Jonathan Lynn, "Yes Minister"

          Comment

          • Flash Gordon

            #6
            Re: CUnit Query

            gamename wrote, On 26/03/07 19:12:

            <snip>
            Yeah, I noticed. The thing seems to be used all over the place. But
            there isn't an obvious forum to discuss it. There are a few mentions
            of it here in the archives, so I went that route.
            There are a few mentions of Islam in the archives of this group as well,
            it does not make this the correct place to discus it.
            Thanks anyway.
            -T
            >
            >--
            >Keith Thompson (The_Other_Keit h) k...@mib.org <http://www.ghoti.net/~kst>
            >San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
            >"We must do something. This is something. Therefore, we must do this."
            > -- Antony Jay and Jonathan Lynn, "Yes Minister"
            Please don't quote peoples signatures, i.e. the bit just above this,
            unless you are commenting on them.
            --
            Flash Gordon

            Comment

            Working...