[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Suggestion: new module link
From: |
Martin Lambers |
Subject: |
Re: [PATCH] Suggestion: new module link |
Date: |
Mon, 19 Jan 2009 21:18:29 +0100 |
User-agent: |
Mutt/1.5.18 (2008-05-17) |
Hello Bruno,
On Sun, 18. Jan 2009, 19:42:11 +0100, Bruno Haible wrote:
> Can you please also provide a unit test for this module?
> The minimal test is probably to
> - create one file,
> - use link() to create a new name for it,
> - then verify that the contents is the same,
> - then modify the contents of the first one,
> - then verify the contents is again the same,
> - then modify the contents of the second one,
> - then verify the contents is again the same,
> - then delete the first one,
> - verify the second one is still there and has the previous contents,
> - then delete the second one.
> I would implement this test as a combination of a .sh script and a .c file
> for actually creating the link.
Below is a unit test that does exactly what you described above. I tried
to resemble the style of existing test modules, but I'm not sure if I
got it right.
I ran the unit test on Debian GNU/Linux, but I cannot currently test on
other systems.
Martin
---
modules/link-tests | 12 ++++++++++++
tests/test-link.c | 41 +++++++++++++++++++++++++++++++++++++++++
tests/test-link.sh | 21 +++++++++++++++++++++
3 files changed, 74 insertions(+), 0 deletions(-)
create mode 100644 modules/link-tests
create mode 100644 tests/test-link.c
create mode 100755 tests/test-link.sh
diff --git a/modules/link-tests b/modules/link-tests
new file mode 100644
index 0000000..383b745
--- /dev/null
+++ b/modules/link-tests
@@ -0,0 +1,12 @@
+Files:
+tests/test-link.c
+tests/test-link.sh
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-link.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@'
+check_PROGRAMS += test-link
diff --git a/tests/test-link.c b/tests/test-link.c
new file mode 100644
index 0000000..479e6bb
--- /dev/null
+++ b/tests/test-link.c
@@ -0,0 +1,41 @@
+/* Test of link() function.
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <unistd.h>
+
+#define ASSERT(expr) \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+ fflush (stderr); \
+ abort (); \
+ } \
+ } \
+ while (0)
+
+int
+main (int argc, char **argv)
+{
+ ASSERT (argc == 3);
+ ASSERT (link (argv[1], argv[2]) == 0);
+
+ return 0;
+}
diff --git a/tests/test-link.sh b/tests/test-link.sh
new file mode 100755
index 0000000..fcc0a1b
--- /dev/null
+++ b/tests/test-link.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+tmpfiles="test-link-a.txt test-link-b.txt test-link-c.txt"
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+echo "hello" > test-link-a.txt || exit 1
+./test-link${EXEEXT} test-link-a.txt test-link-b.txt || exit 1
+cmp test-link-a.txt test-link-b.txt || exit 1
+
+echo "world" >> test-link-a.txt || exit 1
+cmp test-link-a.txt test-link-b.txt || exit 1
+
+echo "some text" >> test-link-b.txt || exit 1
+cmp test-link-a.txt test-link-b.txt || exit 1
+
+cp test-link-a.txt test-link-c.txt || exit 1
+rm test-link-a.txt || exit 1
+cmp test-link-b.txt test-link-c.txt || exit 1
+
+rm -fr $tmpfiles
+exit 0
--
1.5.6.5