tests: TEST_SKIP: Allow use of regexp patterns
[libquvi-scripts.git] / tests / lib / env.c
blobb8b2a10ae45b59cf00e75644b703b1198269154c
1 /* libquvi-scripts
2 * Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
20 #include "config.h"
22 #include <string.h>
23 #include <glib.h>
24 #include <quvi.h>
25 #include <curl/curl.h>
27 #include "tests.h"
29 gboolean chk_env(const gchar *w, const gchar *m)
31 const gchar *s = g_getenv(w);
32 if (s == NULL || strlen(s) == 0)
34 if (m != NULL)
35 g_test_message("%s", m);
36 return (FALSE);
38 return (TRUE);
41 gboolean chk_nsfw()
43 return (chk_env("TEST_NSFW", "SKIP: Set TEST_NSFW to enable"));
46 gboolean chk_fixme()
48 return (chk_env("TEST_FIXME", "SKIP: Set TEST_FIXME to enable"));
51 void chk_verbose(quvi_t q)
53 g_assert(q != NULL);
54 if (chk_env("TEST_VERBOSE", NULL) == TRUE)
56 CURL *c = NULL;
57 quvi_get(q, QUVI_INFO_CURL_HANDLE, &c);
58 curl_easy_setopt(c, CURLOPT_VERBOSE, 1L);
62 static gboolean chk_level(const gchar *s)
64 const gchar *e = g_getenv("TEST_LEVEL");
66 if (e == NULL || strlen(e) == 0)
67 return (FALSE);
69 return ((g_strcmp0(e, s) == 0) ? TRUE:FALSE);
72 gboolean chk_complete()
74 return (chk_level("complete"));
77 gboolean chk_skip(const gchar *test)
79 const gchar *e = g_getenv("TEST_SKIP");
80 gboolean r = FALSE;
82 if (e == NULL || strlen(e) == 0)
83 return (FALSE);
85 gchar **s = g_strsplit(e, ",", 0);
86 gint i = -1;
88 while (s != NULL && s[++i] != NULL)
90 if (match(test, s[i]) == TRUE)
92 g_test_message("SKIP: Remove '%s' from TEST_SKIP to enable",
93 test);
94 r = TRUE;
95 break;
98 g_strfreev(s);
99 s = NULL;
101 return (r);
104 /* vim: set ts=2 sw=2 tw=72 expandtab: */