1- /* *
1+ /*
22 * @file
33 */
4+ #include " color.h"
45#include " fetch.h"
56
7+ /* *
8+ * Tests that want and got are equal.
9+ * Fails with the supplied failure message, file and line then halt.
10+ * @param want
11+ * @param got
12+ * @param msg
13+ * @param file
14+ * @param line
15+ */
16+ template <typename T>
17+ void expect1 (const T &want, const T &got, const string &msg, const char *file,
18+ int line)
19+ {
20+ if (want == got)
21+ return ;
22+
23+ if (msg.length () != 0 )
24+ cout << file << " :" s << line << " : Error: " s << msg << " want (" s
25+ << want << " ), but got (" s << got << " )" s << endl;
26+ else
27+ cout << file << " :" s << line << " : Error: want (" s << want
28+ << " ), but got (" s << got << " )" s << endl;
29+
30+ exit (1 );
31+ }
32+ #define expect (want, got, msg ) expect1(want, got, msg, __FILE__, __LINE__)
33+
34+ /*
35+ * .---------------------------------------------.
36+ * | FETCH TESTS |
37+ * '---------------------------------------------'
38+ */
39+ static void test_getuser ()
40+ {
41+ expect (string (getenv (" USER" )), getuser (), " getuser" s);
42+ }
43+
44+ /*
45+ * Test fetch functions
46+ */
47+ static void test_fetch ()
48+ {
49+ test_getuser ();
50+ }
51+
52+ /*
53+ * .---------------------------------------------.
54+ * | UTILS TESTS |
55+ * '---------------------------------------------'
56+ */
57+
658static void test_Command ()
759{
860 auto c = Command::exec (" ls Makefile" s);
@@ -176,20 +228,6 @@ static void test_Options_full()
176228 testhelper_Options (" full" , argc, argv, expect, 6 ); // remains last "arg"
177229}
178230
179- static void test_Options_test ()
180- {
181- int argc = 2 ;
182- const char *argv[] = {" procfetch" , " -t" , NULL };
183-
184- Options expect;
185- expect.mode = Mode::EXEC_TEST;
186- expect.color_name = " def" s;
187- expect.distro_name = " def" s;
188- expect.show_battery = false ;
189-
190- testhelper_Options (" test" , argc, argv, expect, 2 );
191- }
192-
193231static void test_Options_version ()
194232{
195233 int argc = 2 ;
@@ -208,7 +246,6 @@ static void test_Options()
208246{
209247 test_Options_default ();
210248 test_Options_full ();
211- test_Options_test ();
212249 test_Options_version ();
213250}
214251
@@ -217,7 +254,7 @@ static void test_Options()
217254 * * class Path
218255 * * class Command
219256 */
220- void test_util ()
257+ static void test_util ()
221258{
222259 test_Path ();
223260 test_Command ();
@@ -228,3 +265,13 @@ void test_util()
228265 test_Crayon ();
229266 test_Options ();
230267}
268+
269+ int main ()
270+ {
271+ test_fetch ();
272+ test_util ();
273+
274+ cout << Crayon{}.green ().text (" All unit tests passed." s) << endl;
275+
276+ return 0 ;
277+ }
0 commit comments