Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
853 B

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include "minunit.h"
  6. #include "getline.h"
  7. #define STRING_LENGTH 14
  8. int tests_run = 0;
  9. // unit test function for trim()
  10. static char *test_trim() {
  11. char *foo = malloc(STRING_LENGTH + 1 * sizeof(*foo));
  12. int wurst = snprintf(foo, STRING_LENGTH + 1, "%s", " hallo welt");
  13. assertf(wurst <= STRING_LENGTH, "buffer overflow");
  14. mu_assert("error", !(strcmp(trim(foo), "hallo welt")));
  15. return 0;
  16. }
  17. // function to run all tests
  18. static char *all_tests() {
  19. mu_run_test(test_trim);
  20. return 0;
  21. }
  22. int main(void) {
  23. char *result = all_tests();
  24. if (result != 0) {
  25. printf("%s\n", result);
  26. } else {
  27. printf("ALL TESTS PASSED\n");
  28. }
  29. printf("Tests run: %d\n", tests_run);
  30. return result != 0;
  31. }