Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/unit-tests/clar/test/suites/combined.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / unit-tests / clar / test / suites / combined.c` 148 lines ยท 3213 bytes Raw Blame History 1 #include 2 3 #include "clar.h" 4 5 static int file_size(const char *filename) 6 { 7 struct stat st; 8 9 if (stat(filename, &st) == 0) 10 return (int)st.st_size; 11 return -1; 12 } 13 14 void test_combined__cleanup(void) 15 { 16 cl_fixture_cleanup("test"); 17 18 cl_assert(file_size("test/file") == -1); 19 } 20 21 void test_combined__1(void) 22 { 23 cl_assert(1); 24 cl_must_pass(0); /* 0 == success */ 25 cl_must_fail(-1); /* <0 == failure */ 26 cl_must_pass(-1); /* demonstrate a failing call */ 27 } 28 29 void test_combined__2(void) 30 { 31 cl_fixture_sandbox("test"); 32 33 cl_assert(file_size("test/nonexistent") == -1); 34 cl_assert(file_size("test/file") > 0); 35 cl_assert(100 == 101); 36 } 37 38 void test_combined__strings(void) 39 { 40 const char *actual = "expected"; 41 cl_assert_equal_s("expected", actual); 42 cl_assert_equal_s_("expected", actual, "second try with annotation"); 43 cl_assert_equal_s_("mismatched", actual, "this one fails"); 44 } 45 46 void test_combined__strings_with_length(void) 47 { 48 const char *actual = "expected"; 49 cl_assert_equal_strn("expected_", actual, 8); 50 cl_assert_equal_strn("exactly", actual, 2); 51 cl_assert_equal_strn_("expected_", actual, 8, "with annotation"); 52 cl_assert_equal_strn_("exactly", actual, 3, "this one fails"); 53 } 54 55 void test_combined__int(void) 56 { 57 int value = 100; 58 cl_assert_equal_i(101, value); 59 } 60 61 void test_combined__int_note(void) 62 { 63 int value = 100; 64 cl_assert_equal_i_(101, value, "extra note on failing test"); 65 } 66 67 void test_combined__int_fmt(void) 68 { 69 int value = 100; 70 cl_assert_equal_i_fmt(022, value, "%04o"); 71 } 72 73 void test_combined__bool(void) 74 { 75 int value = 100; 76 cl_assert_equal_b(1, value); /* test equality as booleans */ 77 cl_assert_equal_b(0, value); 78 } 79 80 void test_combined__multiline_description(void) 81 { 82 cl_must_pass_(-1, "description line 1\ndescription line 2"); 83 } 84 85 void test_combined__null_string(void) 86 { 87 const char *actual = NULL; 88 cl_assert_equal_s(actual, actual); 89 cl_assert_equal_s_("expected", actual, "this one fails"); 90 } 91 92 void test_combined__failf(void) 93 { 94 cl_failf("some reason: %s", "foo"); 95 } 96 97 void test_combined__compare_i(void) 98 { 99 int one = 1, two = 2; 100 101 cl_assert_equal_i(one, 1); 102 cl_assert_equal_i(one, 1); 103 cl_assert_equal_i_(one, 1, "format"); 104 cl_assert_lt_i(one, 2); 105 cl_assert_lt_i_(one, 2, "format"); 106 cl_assert_le_i(one, 2); 107 cl_assert_le_i(two, 2); 108 cl_assert_le_i_(two, 2, "format"); 109 cl_assert_gt_i(two, 1); 110 cl_assert_gt_i_(two, 1, "format"); 111 cl_assert_ge_i(two, 2); 112 cl_assert_ge_i(3, two); 113 cl_assert_ge_i_(3, two, "format"); 114 115 cl_assert_lt_i(two, 1); /* this one fails */ 116 } 117 118 void test_combined__compare_i_with_format(void) 119 { 120 int two = 2; 121 cl_assert_lt_i_(two, 1, "foo: %s", "bar"); 122 } 123 124 void test_combined__compare_u(void) 125 { 126 unsigned one = 1, two = 2; 127 128 cl_assert_equal_u(one, 1); 129 cl_assert_equal_u_(one, 1, "format"); 130 cl_assert_lt_u(one, 2); 131 cl_assert_lt_u_(one, 2, "format"); 132 cl_assert_le_u(one, 2); 133 cl_assert_le_u(two, 2); 134 cl_assert_le_u_(two, 2, "format"); 135 cl_assert_gt_u(two, 1); 136 cl_assert_gt_u_(two, 1, "format"); 137 cl_assert_ge_u(two, 2); 138 cl_assert_ge_u(3, two); 139 cl_assert_ge_u_(3, two, "format"); 140 141 cl_assert_lt_u(two, 1); /* this one fails */ 142 } 143 144 void test_combined__compare_u_with_format(void) 145 { 146 unsigned two = 2; 147 cl_assert_lt_u_(two, 1, "foo: %s", "bar"); 148 }