diff mbox

[libnftables,3/6] test: use constants for coloured strings

Message ID 20131031123628.32572.32677.stgit@nfdev.cica.es
State Not Applicable
Headers show

Commit Message

Arturo Borrero Oct. 31, 2013, 12:36 p.m. UTC
Use constants for coloured strings, which have a ugly format.

Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
---
 tests/nft-parsing-test.c |   17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Pablo Neira Ayuso Nov. 3, 2013, 9:31 p.m. UTC | #1
On Thu, Oct 31, 2013 at 01:36:29PM +0100, Arturo Borrero Gonzalez wrote:
> Use constants for coloured strings, which have a ugly format.
> 
> Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>
> ---
>  tests/nft-parsing-test.c |   17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/tests/nft-parsing-test.c b/tests/nft-parsing-test.c
> index 5eaaa1e..5333dbd 100644
> --- a/tests/nft-parsing-test.c
> +++ b/tests/nft-parsing-test.c
> @@ -33,6 +33,9 @@ enum {
>  	TEST_JSON_RULESET,
>  };
>  
> +#define FAILED_STR "\033[31mFAILED\e[0m"
> +#define OK_STR "\033[32mOK\e[0m"

I don't like this macro thing, sorry.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/tests/nft-parsing-test.c b/tests/nft-parsing-test.c
index 5eaaa1e..5333dbd 100644
--- a/tests/nft-parsing-test.c
+++ b/tests/nft-parsing-test.c
@@ -33,6 +33,9 @@  enum {
 	TEST_JSON_RULESET,
 };
 
+#define FAILED_STR "\033[31mFAILED\e[0m"
+#define OK_STR "\033[32mOK\e[0m"
+
 #if defined(XML_PARSING) || defined(JSON_PARSING)
 static void print_detail_error(char *a, char *b)
 {
@@ -160,8 +163,7 @@  static int compare_test(uint32_t type, void *input, const char *filename)
 	if (strncmp(orig, out, strlen(out)) == 0)
 		return 0;
 
-	printf("validating %s: ", filename);
-	printf("\033[31mFAILED\e[0m\n");
+	printf("parsing and validating %s: %s\n", filename, FAILED_STR);
 	print_detail_error(orig, out);
 	return -1;
 }
@@ -245,8 +247,7 @@  static int test_json(const char *filename)
 	return ret;
 
 failparsing:
-	printf("parsing %s: ", filename);
-	printf("\033[31mFAILED\e[0m (%s)\n", strerror(errno));
+	printf("parsing %s: %s (%s)\n", filename, FAILED_STR, strerror(errno));
 	free(json);
 	json_decref(root);
 	return -1;
@@ -340,8 +341,8 @@  static int test_xml(const char *filename)
 
 failparsing:
 	mxmlDelete(tree);
-	printf("parsing %s: ", filename);
-	printf("\033[31mFAILED\e[0m (%s)\n", strerror(errno));
+	printf("parsing and validating %s: %s (%s)\n", filename, FAILED_STR,
+	       strerror(errno));
 	return -1;
 #else
 	errno = EOPNOTSUPP;
@@ -379,14 +380,14 @@  int main(int argc, char *argv[])
 		if (strcmp(&dent->d_name[len-4], ".xml") == 0) {
 			if ((ret = test_xml(path)) == 0) {
 				printf("parsing and validating %s: ", path);
-				printf("\033[32mOK\e[0m\n");
+				printf("%s\n", OK_STR);
 			}
 			exit_code += ret;
 		}
 		if (strcmp(&dent->d_name[len-5], ".json") == 0) {
 			if ((ret = test_json(path)) == 0) {
 				printf("parsing and validating %s: ", path);
-				printf("\033[32mOK\e[0m\n");
+				printf("%s\n", OK_STR);
 			}
 			exit_code += ret;
 		}