https://github.com/akkartik/mu/blob/master/subx/003trace.test.cc
  1 void test_trace_check_compares() {
  2   trace("test layer") << "foo" << end();
  3   CHECK_TRACE_CONTENTS("test layer: foo");
  4 }
  5 
  6 void test_trace_check_ignores_other_layers() {
  7   trace("test layer 1") << "foo" << end();
  8   trace("test layer 2") << "bar" << end();
  9   CHECK_TRACE_CONTENTS("test layer 1: foo");
 10   CHECK_TRACE_DOESNT_CONTAIN("test layer 2: foo");
 11 }
 12 
 13 void test_trace_check_ignores_leading_whitespace() {
 14   trace("test layer 1") << " foo" << end();
 15   CHECK_EQ(trace_count("test layer 1", /*too little whitespace*/"foo"), 1);
 16   CHECK_EQ(trace_count("test layer 1", /*too much whitespace*/"  foo"), 1);
 17 }
 18 
 19 void test_trace_check_ignores_other_lines() {
 20   trace("test layer 1") << "foo" << end();
 21   trace("test layer 1") << "bar" << end();
 22   CHECK_TRACE_CONTENTS("test layer 1: foo");
 23 }
 24 
 25 void test_trace_check_ignores_other_lines2() {
 26   trace("test layer 1") << "foo" << end();
 27   trace("test layer 1") << "bar" << end();
 28   CHECK_TRACE_CONTENTS("test layer 1: bar");
 29 }
 30 
 31 void test_trace_ignores_trailing_whitespace() {
 32   trace("test layer 1") << "foo\n" << end();
 33   CHECK_TRACE_CONTENTS("test layer 1: foo");
 34 }
 35 
 36 void test_trace_ignores_trailing_whitespace2() {
 37   trace("test layer 1") << "foo " << end();
 38   CHECK_TRACE_CONTENTS("test layer 1: foo");
 39 }
 40 
 41 void test_trace_orders_across_layers() {
 42   trace("test layer 1") << "foo" << end();
 43   trace("test layer 2") << "bar" << end();
 44   trace("test layer 1") << "qux" << end();
 45   CHECK_TRACE_CONTENTS("test layer 1: foo\n"
 46                        "test layer 2: bar\n"
 47                        "test layer 1: qux\n");
 48 }
 49 
 50 void test_trace_supports_count() {
 51   trace("test layer 1") << "foo" << end();
 52   trace("test layer 1") << "foo" << end();
 53   CHECK_EQ(trace_count("test layer 1", "foo"), 2);
 54 }
 55 
 56 void test_trace_supports_count2() {
 57   trace("test layer 1") << "foo" << end();
 58   trace("test layer 1") << "bar" << end();
 59   CHECK_EQ(trace_count("test layer 1"), 2);
 60 }
 61 
 62 void test_trace_count_ignores_trailing_whitespace() {
 63   trace("test layer 1") << "foo\n" << end();
 64   CHECK_EQ(trace_count("test layer 1", "foo"), 1);
 65 }
 66 
 67 // pending: DUMP tests
 68 // pending: readable_contents() adds newline if necessary.
 69 // pending: raise also prints to stderr.
 70 // pending: raise doesn't print to stderr if Hide_errors is set.
 71 // pending: warn doesn't print to stderr if Hide_errors is set.
 72 // pending: warn doesn't print to stderr if Hide_warnings is set.
 73 // pending: raise doesn't have to be saved if Hide_errors is set, just printed.
 74 // pending: raise prints to stderr if Trace_stream is NULL.
 75 // pending: raise prints to stderr if Trace_stream is NULL even if Hide_errors is set.
 76 
 77 // can't check trace because trace methods call 'split'
 78 
 79 void test_split_returns_at_least_one_elem() {
 80   vector<string> result = split("", ",");
 81   CHECK_EQ(result.size(), 1);
 82   CHECK_EQ(result.at(0), "");
 83 }
 84 
 85 void test_split_returns_entire_input_when_no_delim() {
 86   vector<string> result = split("abc", ",");
 87   CHECK_EQ(result.size(), 1);
 88   CHECK_EQ(result.at(0), "abc");
 89 }
 90 
 91 void test_split_works() {
 92   vector<string> result = split("abc,def", ",");
 93   CHECK_EQ(result.size(), 2);
 94   CHECK_EQ(result.at(0), "abc");
 95   CHECK_EQ(result.at(1), "def");
 96 }
 97 
 98 void test_split_works2() {
 99   vector<string> result = split("abc,def,ghi", ",");
100   CHECK_EQ(result.size(), 3);
101   CHECK_EQ(result.at(0), "abc");
102   CHECK_EQ(result.at(1), "def");
103   CHECK_EQ(result.at(2), "ghi");
104 }
105 
106 void test_split_handles_multichar_delim() {
107   vector<string> result = split("abc,,def,,ghi", ",,");
108   CHECK_EQ(result.size(), 3);
109   CHECK_EQ(result.at(0), "abc");
110   CHECK_EQ(result.at(1), "def");
111   CHECK_EQ(result.at(2), "ghi");
112 }
113 
114 void test_trim() {
115   CHECK_EQ(trim(""), "");
116   CHECK_EQ(trim(" "), "");
117   CHECK_EQ(trim("  "), "");
118   CHECK_EQ(trim("a"), "a");
119   CHECK_EQ(trim(" a"), "a");
120   CHECK_EQ(trim("  a"), "a");
121   CHECK_EQ(trim("  ab"), "ab");
122   CHECK_EQ(trim("a "), "a");
123   CHECK_EQ(trim("a  "), "a");
124   CHECK_EQ(trim("ab  "), "ab");
125   CHECK_EQ(trim(" a "), "a");
126   CHECK_EQ(trim("  a  "), "a");
127   CHECK_EQ(trim("  ab  "), "ab");
128 }