diff options
| author | sanine <sanine.not@pm.me> | 2022-01-16 14:04:00 -0600 | 
|---|---|---|
| committer | sanine <sanine.not@pm.me> | 2022-01-16 14:04:00 -0600 | 
| commit | abe324281121925be29c98f32d19a187a7e3f53f (patch) | |
| tree | f7f1a1c4aed813d762ad93ddfe3e389a3b5b0468 /tests | |
| parent | db8770da7bb9f8763b35480e6e900289aebb45a8 (diff) | |
remove location tests and add lily_assert_int_not_equal test
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/assertions.c | 51 | ||||
| -rw-r--r-- | tests/main.c | 1 | ||||
| -rw-r--r-- | tests/tests.h | 1 | 
3 files changed, 38 insertions, 15 deletions
| diff --git a/tests/assertions.c b/tests/assertions.c index ae72fa6..6471225 100644 --- a/tests/assertions.c +++ b/tests/assertions.c @@ -16,6 +16,7 @@ const char *test_LILY_LOCATION()  } +/* overarching assert function */  const char *test_assert_msg()  {     int val = setjmp(_lily_globals.env); @@ -38,7 +39,7 @@ const char *test_assert_msg()     else {        if (strcmp(_lily_globals.error_msg, "should fail!") != 0)  	 return "false assertion produced incorrect error message!"; -      if (strcmp(_lily_globals.error_location, "tests/assertions.c:35")) +      if (strcmp(_lily_globals.error_location, "tests/assertions.c:36"))  	 return "false assertion produced incorrect error location!";     } @@ -46,6 +47,7 @@ const char *test_assert_msg()  } +/* basic asserts */  const char *test_assert_true()  {     int val = setjmp(_lily_globals.env); @@ -67,8 +69,6 @@ const char *test_assert_true()     else {        if (strcmp(_lily_globals.error_msg, "false is not true") != 0)  	 return "false assertion produced incorrect error message!"; -      if (strcmp(_lily_globals.error_location, "tests/assertions.c:64") != 0) -	 return "false assertion produced incorrect error location!";     }     return 0; @@ -96,14 +96,13 @@ const char *test_assert_false()     else {        if (strcmp(_lily_globals.error_msg, "true is not false") != 0)  	 return "false assertion produced incorrect error message!"; -      if (strcmp(_lily_globals.error_location, "tests/assertions.c:93") != 0) -	 return "false assertion produced incorrect error location!";     }     return 0;  } +/* pointer assertions */  const char *test_assert_not_null()  {     int a = 5; @@ -129,8 +128,6 @@ const char *test_assert_not_null()     else {        if (strcmp(_lily_globals.error_msg, "ptr is NULL") != 0)  	 return "false assertion produced incorrect error message!"; -      if (strcmp(_lily_globals.error_location, "tests/assertions.c:126") != 0) -	 return "false assertion produced incorrect error location!";     }     return 0; @@ -163,8 +160,6 @@ const char *test_assert_null()        sprintf(buf, "&a (%p) is not NULL", &a);        if (strcmp(_lily_globals.error_msg, buf) != 0)  	 return "false assertion produced incorrect error message!"; -      if (strcmp(_lily_globals.error_location, "tests/assertions.c:158") != 0) -	 return "false assertion produced incorrect error location!";     }     return 0; @@ -199,8 +194,6 @@ const char *test_assert_ptr_equal()        sprintf(buf, "&a (%p) is not equal to ptr (%p)", &a, &b);        if (strcmp(_lily_globals.error_msg, buf) != 0)  	 return "false assertion produced incorrect error message!"; -      if (strcmp(_lily_globals.error_location, "tests/assertions.c:194") != 0) -	 return "false assertion produced incorrect error location!";     }     return 0; @@ -235,14 +228,13 @@ const char *test_assert_ptr_not_equal()        sprintf(buf, "&a (%p) is equal to ptr", &a);        if (strcmp(_lily_globals.error_msg, buf) != 0)  	 return "false assertion produced incorrect error message!"; -      if (strcmp(_lily_globals.error_location, "tests/assertions.c:230") != 0) -	 return "false assertion produced incorrect error location!";     }     return 0;  } +/* integer assertions */  const char *test_assert_int_equal()  {     int a = 56; @@ -268,8 +260,37 @@ const char *test_assert_int_equal()     else {        if (strcmp(_lily_globals.error_msg, "a (25) is not equal to b (56)") != 0)  	 return "false assertion produced incorrect error message!"; -      if (strcmp(_lily_globals.error_location, "tests/assertions.c:265") != 0) -	 return "false assertion produced incorrect error location!"; +   } + +   return 0; +} + + +const char *test_assert_int_not_equal() +{ +   int a = 25; +   int b = 26; + +   int val = setjmp(_lily_globals.env); +   if (val != 0) +      return "true assertion failed incorrectly!"; + +   lily_assert_int_not_equal(a, b); + +   int passed_thru = 0; +   _lily_globals.error_msg = NULL; +   _lily_globals.error_location = ""; +   val = setjmp(_lily_globals.env); +   b = 25; + +   if (passed_thru == 0) { +      passed_thru = 1; +      lily_assert_int_not_equal(a, b); +      return "false assertion incorrectly succeeded!"; +   } +   else { +      if (strcmp(_lily_globals.error_msg, "a (25) is equal to b") != 0) +	 return "false assertion produced incorrect error message!";     }     return 0; diff --git a/tests/main.c b/tests/main.c index 9752c34..3c94cf7 100644 --- a/tests/main.c +++ b/tests/main.c @@ -19,6 +19,7 @@ int main()     run_test(test_assert_ptr_equal);     run_test(test_assert_ptr_not_equal);     run_test(test_assert_int_equal); +   run_test(test_assert_int_not_equal);     return 0;  } diff --git a/tests/tests.h b/tests/tests.h index b54534c..995beaf 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -16,4 +16,5 @@ const char* test_assert_null();  const char* test_assert_ptr_equal();  const char* test_assert_ptr_not_equal();  const char* test_assert_int_equal(); +const char* test_assert_int_not_equal();  #endif | 
