From: Ana Rey <anarey@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: Ana Rey <anarey@gmail.com>
Subject: [libnftnl PATCH v2 1/2] tests: New tools to uptade xml and json testfiles.
Date: Wed, 9 Apr 2014 17:03:44 +0200 [thread overview]
Message-ID: <b6b20bce9ecf384db04e8d9582a49905bf0fa72c.1397048551.git.anarey@gmail.com> (raw)
In-Reply-To: <cover.1397048551.git.anarey@gmail.com>
In-Reply-To: <cover.1397048551.git.anarey@gmail.com>
New tools to updata testfiles when the structure of xml or json files
are changed.
It adds a new command-line argument in nft-parsing-test.
With nft-parsing-test -u <directory>, you can update test files in
<directory> with a new structure of xml or json file.
Signed-off-by: Ana Rey <anarey@gmail.com>
---
[Changes in v2:]
* Change from fwrite to fprintf functions to add the end of line in the
new files.
tests/nft-parsing-test.c | 42 ++++++++++++++++++++++++++++++++++++------
1 file changed, 36 insertions(+), 6 deletions(-)
diff --git a/tests/nft-parsing-test.c b/tests/nft-parsing-test.c
index a35c064..59c75a6 100644
--- a/tests/nft-parsing-test.c
+++ b/tests/nft-parsing-test.c
@@ -18,6 +18,8 @@ enum {
TEST_JSON_RULESET,
};
+static bool update = false;
+
static void print_detail_error(char *a, char *b)
{
int i;
@@ -80,8 +82,24 @@ static int compare_test(uint32_t type, struct nft_ruleset *rs,
rewind(fp);
fgets(orig, sizeof(orig), fp);
- if (strncmp(orig, out, strlen(out)) == 0)
+ if (strncmp(orig, out, strlen(out)) == 0) {
+ if (update)
+ printf("%s: No changes to update\n", filename);
+ return 0;
+ }
+ if (update) {
+ FILE *fout;
+ printf("%s: Updating test file\n", filename);
+ fout = fopen(filename, "w");
+ if (fout == NULL) {
+ printf("unable to open file %s: %s\n", filename,
+ strerror(errno));
+ return -1;
+ }
+ fprintf(fout, "%s\n", out);
+ fclose(fout);
return 0;
+ }
printf("validating %s: ", filename);
printf("\033[31mFAILED\e[0m\n");
@@ -193,15 +211,21 @@ static int execute_test(const char *dir_name)
if (strcmp(&dent->d_name[len-4], ".xml") == 0) {
if ((ret = test_xml(path, err)) == 0) {
- printf("parsing and validating %s: ", path);
- printf("\033[32mOK\e[0m\n");
+ if (!update) {
+ printf("parsing and validating %s: ",
+ path);
+ printf("\033[32mOK\e[0m\n");
+ }
}
exit_code += ret;
}
if (strcmp(&dent->d_name[len-5], ".json") == 0) {
if ((ret = test_json(path, err)) == 0) {
- printf("parsing and validating %s: ", path);
- printf("\033[32mOK\e[0m\n");
+ if (!update) {
+ printf("parsing and validating %s: ",
+ path);
+ printf("\033[32mOK\e[0m\n");
+ }
}
exit_code += ret;
}
@@ -223,6 +247,7 @@ static void show_help(const char *name)
"\n"
"Options:\n"
" -d/--dir <directory> Check test files from <directory>.\n"
+" -u/--update <directory> Update test files from <directory>.\n"
"\n",
name);
}
@@ -234,6 +259,7 @@ int main(int argc, char *argv[])
int option_index = 0;
static struct option long_options[] = {
{ "dir", required_argument, 0, 'd' },
+ { "update", required_argument, 0, 'u' },
{ 0 }
};
@@ -243,7 +269,7 @@ int main(int argc, char *argv[])
}
while (1) {
- val = getopt_long(argc, argv, "d:", long_options,
+ val = getopt_long(argc, argv, "d:u:", long_options,
&option_index);
if (val == -1)
@@ -253,6 +279,10 @@ int main(int argc, char *argv[])
case 'd':
ret = execute_test(optarg);
break;
+ case 'u':
+ update = true;
+ ret = execute_test(optarg);
+ break;
default:
show_help(argv[0]);
break;
--
1.9.0
next prev parent reply other threads:[~2014-04-09 15:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-09 15:03 [libnftnl PATCH v2 0/2] New features in nft-parsing-test Ana Rey
2014-04-09 15:03 ` Ana Rey [this message]
2014-04-09 15:03 ` [libnftnl PATCH v2 2/2] tests: Add support to check a json or xml testfile Ana Rey
2014-04-14 8:48 ` [libnftnl PATCH v2 0/2] New features in nft-parsing-test Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b6b20bce9ecf384db04e8d9582a49905bf0fa72c.1397048551.git.anarey@gmail.com \
--to=anarey@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).