0

This one is causing grief; I'd like to get to grips with CUnit.

Have installed it using the following instructions: http://macappstore.org/cunit/

I am using the following at command line: gcc myprog.c -Wall -Wfloat-equal -Wextra -O2 -pedantic -ansi -lm -lcunit -o myprog

It compiles without errors and i proceed with the following: ./myprog

I have the following sitting inside my code:

#include <stdio.h>
#include <math.h>
#include <CUnit/CUnit.h>

int maxi(int i1, int i2);
void test_maxi(void);
struct code{
   char words[5][5];
   int cnt; /* Current Word Counter*/
};
typedef struct code Code;

int main(void){
  test_maxi();   

   return 0;
}

int maxi(int i1, int i2){
   return (i1 > i2) ? i1 : i2;
}

void test_maxi(void){
   CU_ASSERT(maxi(0,2) == 2);
   CU_ASSERT(maxi(0,-2) == 0);
   CU_ASSERT(maxi(2,2) == 2);
}

My assumption is that this should generate some kind of .txt or alternative file within the same directory. Is this assumption incorrect? What should i be looking for instead?

Update: I am currently getting the following on command line; "Assertion failed: (NULL != f_pCurSuite), function CU_assertImplementation, file TestRun.c, line 162. Abort trap: 6"

(Full Disclosure: New to programming....so be gentle :P )

  • You're not calling `test_maxi` in `main()` so it just exists as a function, but it is not being run. You need to run it in `main`. – Eli Sadoff Dec 20 '16 at 20:41
  • Thanks @EliSadoff. That was helpful. I just added a single line to main i.e. " test_maxi(); ". On the command line i get the following: Assertion failed: (NULL != f_pCurSuite), function CU_assertImplementation, file TestRun.c, line 162. Abort trap: 6 Would you be able to elaborate?( I apologise if i come off as a bit slow, a bit new to all of this) –  Dec 20 '16 at 20:47
  • Please add your actual code ***to the question***, which as posted `int main(void) { return 0; }` does nothing. – Weather Vane Dec 20 '16 at 20:51
  • Yes that was silly of me. I have updated it accordingly :) –  Dec 20 '16 at 20:56
  • You need to create a test suite as explained [here](http://stackoverflow.com/questions/38183974/cunit-assertion-assertion-void-0-f-pcursuite-failed). – pbn Dec 20 '16 at 21:35
  • @pbn, that was crazy useful! Fixed my immediate problem (i.e. getting CUnit to work), so thank you. I am going to now play with this for a while, because i am fairly certain i dont fully appreciate why to use CUnit in the first instance :) –  Dec 21 '16 at 09:39

1 Answers1

0

You're not calling test_maxi in main() so it just exists as a function, but it is not being run. You need to run it in main. – Eli Sadoff

You need to create a test suite as explained here. – pbn

Armali
  • 18,255
  • 14
  • 57
  • 171