README 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. Unit tests
  2. ==========
  3. The goal is to add tests for *ALL* functions in libcurl. If functions are too
  4. big and complicated, we should split them into smaller and testable ones.
  5. Build Unit Tests
  6. ================
  7. './configure --enable-debug' is required for the unit tests to build. To
  8. enable unit tests, there will be a separate static libcurl built that will be
  9. used exclusively for linking unit test programs. Just build everything as
  10. normal, and then you can run the unit test cases as well.
  11. Run Unit Tests
  12. ==============
  13. Unit tests are run as part of the regular test suite. If you have built
  14. everything to run unit tests, to can do 'make test' at the root level. Or you
  15. can 'cd tests' and 'make' and then invoke individual unit tests with
  16. ./runtests.pl NNNN where NNNN is the specific test number.
  17. Debug Unit Tests
  18. ================
  19. If a specific test fails you will get told. The test case then has output left
  20. in the log/ subdirectory, but most importantly you can re-run the test again
  21. using gdb by doing ./runtests.pl -g NNNN. That is, add a -g to make it start
  22. up gdb and run the same case using that.
  23. Write Unit Tests
  24. ================
  25. We put tests that focus on an area or a specific function into a single C
  26. source file. The source file should be named 'unitNNNN.c' where NNNN is a
  27. number that starts with 1300 and you can pick the next free number.
  28. You also need a separate file called tests/data/testNNNN (using the same
  29. number) that describes your test case. See the test1300 file for inspiration
  30. and the tests/FILEFORMAT documentation.
  31. For the actual C file, here's a very simple example:
  32. ----------------------- start -------------------------------
  33. #include "curlcheck.h"
  34. #include "a libcurl header.h" /* from the lib dir */
  35. static void unit_setup( void )
  36. {
  37. /* whatever you want done first */
  38. }
  39. static void unit_stop( void )
  40. {
  41. /* done before shutting down and exiting */
  42. }
  43. UNITTEST_START
  44. /* here you start doing things and checking that the results are good */
  45. fail_unless( size == 0 , "initial size should be zero" );
  46. fail_if( head == NULL , "head should not be initiated to NULL" );
  47. /* you end the test code like this: */
  48. UNITTEST_STOP
  49. ----------------------- end -------------------------------