0 | |
From f903a360a0b8194a84c7848735f7353ca7c70f95 Mon Sep 17 00:00:00 2001
|
1 | |
From: yangfl <yangfl@users.noreply.github.com>
|
2 | |
Date: Mon, 1 Jun 2020 10:23:34 +0800
|
3 | |
Subject: [PATCH] Avoid (some) hard-coded pathes in tests
|
4 | |
|
5 | |
---
|
6 | |
tests/.gitignore | 42 +++++++++++++++---------------
|
7 | |
tests/Makefile.am | 11 +++++++-
|
8 | |
tests/data/fexist/broken-link | 1 +
|
9 | |
tests/data/fexist/dir/.placeholder | 0
|
10 | |
tests/data/fexist/executable | 0
|
11 | |
tests/data/fexist/link | 1 +
|
12 | |
tests/data/fexist/regular | 0
|
13 | |
tests/data/lfile/fstab | 3 +++
|
14 | |
tests/data/lfile/group | 1 +
|
15 | |
tests/data/lfile/passwd | 1 +
|
16 | |
tests/data/lfile/protocols | 1 +
|
17 | |
tests/data/lfile/services | 2 ++
|
18 | |
tests/data/which/executable | 0
|
19 | |
tests/data/which/executable-link | 1 +
|
20 | |
tests/data/which/regular | 0
|
21 | |
tests/fexist.c | 11 +++++---
|
22 | |
tests/lfile.c | 10 +++----
|
23 | |
tests/which.c | 15 +++++------
|
24 | |
18 files changed, 61 insertions(+), 39 deletions(-)
|
25 | |
create mode 120000 tests/data/fexist/broken-link
|
26 | |
create mode 100644 tests/data/fexist/dir/.placeholder
|
27 | |
create mode 100755 tests/data/fexist/executable
|
28 | |
create mode 120000 tests/data/fexist/link
|
29 | |
create mode 100644 tests/data/fexist/regular
|
30 | |
create mode 100644 tests/data/lfile/fstab
|
31 | |
create mode 100644 tests/data/lfile/group
|
32 | |
create mode 100644 tests/data/lfile/passwd
|
33 | |
create mode 100644 tests/data/lfile/protocols
|
34 | |
create mode 100644 tests/data/lfile/services
|
35 | |
create mode 100755 tests/data/which/executable
|
36 | |
create mode 120000 tests/data/which/executable-link
|
37 | |
create mode 100644 tests/data/which/regular
|
38 | |
|
39 | |
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
40 | |
index 032dd3c..4baefae 100644
|
41 | |
--- a/tests/Makefile.am
|
42 | |
+++ b/tests/Makefile.am
|
43 | |
@@ -1,6 +1,15 @@
|
44 | |
-EXTRA_DIST = check.h
|
45 | |
+EXTRA_DIST = check.h \
|
46 | |
+ data/fexist/dir/.placeholder data/fexist/executable data/fexist/link \
|
47 | |
+ data/fexist/regular data/lfile/fstab data/lfile/group data/lfile/passwd \
|
48 | |
+ data/lfile/protocols data/lfile/services data/which/executable \
|
49 | |
+ data/which/executable-link data/which/regular
|
50 | |
CLEANFILES = *~ *.trs *.log
|
51 | |
|
52 | |
+TESTS_ENVIRONMENT = ([ -d data ] || ln -sf $(srcdir)/data) &&
|
53 | |
+
|
54 | |
+clean-local:
|
55 | |
+ -find -type l -name data -exec rm {} \;
|
56 | |
+
|
57 | |
TESTS =
|
58 | |
TESTS += chomp
|
59 | |
TESTS += copyfile
|
60 | |
diff --git a/tests/data/fexist/broken-link b/tests/data/fexist/broken-link
|
61 | |
new file mode 120000
|
62 | |
index 0000000..09315f2
|
63 | |
--- /dev/null
|
64 | |
+++ b/tests/data/fexist/broken-link
|
65 | |
@@ -0,0 +1 @@
|
66 | |
+nonexistence
|
67 | |
\ No newline at end of file
|
68 | |
diff --git a/tests/data/fexist/dir/.placeholder b/tests/data/fexist/dir/.placeholder
|
69 | |
new file mode 100644
|
70 | |
index 0000000..e69de29
|
71 | |
diff --git a/tests/data/fexist/executable b/tests/data/fexist/executable
|
72 | |
new file mode 100755
|
73 | |
index 0000000..e69de29
|
74 | |
diff --git a/tests/data/fexist/link b/tests/data/fexist/link
|
75 | |
new file mode 120000
|
76 | |
index 0000000..1d89e5a
|
77 | |
--- /dev/null
|
78 | |
+++ b/tests/data/fexist/link
|
79 | |
@@ -0,0 +1 @@
|
80 | |
+regular
|
81 | |
\ No newline at end of file
|
82 | |
diff --git a/tests/data/fexist/regular b/tests/data/fexist/regular
|
83 | |
new file mode 100644
|
84 | |
index 0000000..e69de29
|
85 | |
diff --git a/tests/data/lfile/fstab b/tests/data/lfile/fstab
|
86 | |
new file mode 100644
|
87 | |
index 0000000..f809e76
|
88 | |
--- /dev/null
|
89 | |
+++ b/tests/data/lfile/fstab
|
90 | |
@@ -0,0 +1,3 @@
|
91 | |
+UUID=xxxxxxxxxx / xfs defaults 0 1
|
92 | |
+/dev/sda1 /boot/efi vfat umask=0077 0 1
|
93 | |
+/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
|
94 | |
diff --git a/tests/data/lfile/group b/tests/data/lfile/group
|
95 | |
new file mode 100644
|
96 | |
index 0000000..557fb2c
|
97 | |
--- /dev/null
|
98 | |
+++ b/tests/data/lfile/group
|
99 | |
@@ -0,0 +1 @@
|
100 | |
+utmp:x:43:
|
101 | |
diff --git a/tests/data/lfile/passwd b/tests/data/lfile/passwd
|
102 | |
new file mode 100644
|
103 | |
index 0000000..6bb6b7e
|
104 | |
--- /dev/null
|
105 | |
+++ b/tests/data/lfile/passwd
|
106 | |
@@ -0,0 +1 @@
|
107 | |
+nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
|
108 | |
diff --git a/tests/data/lfile/protocols b/tests/data/lfile/protocols
|
109 | |
new file mode 100644
|
110 | |
index 0000000..0f62e42
|
111 | |
--- /dev/null
|
112 | |
+++ b/tests/data/lfile/protocols
|
113 | |
@@ -0,0 +1 @@
|
114 | |
+udp 17 UDP
|
115 | |
diff --git a/tests/data/lfile/services b/tests/data/lfile/services
|
116 | |
new file mode 100644
|
117 | |
index 0000000..cf25247
|
118 | |
--- /dev/null
|
119 | |
+++ b/tests/data/lfile/services
|
120 | |
@@ -0,0 +1,2 @@
|
121 | |
+ftp-data 20/tcp
|
122 | |
+ftp 21/tcp
|
123 | |
diff --git a/tests/data/which/executable b/tests/data/which/executable
|
124 | |
new file mode 100755
|
125 | |
index 0000000..e69de29
|
126 | |
diff --git a/tests/data/which/executable-link b/tests/data/which/executable-link
|
127 | |
new file mode 120000
|
128 | |
index 0000000..9268d74
|
129 | |
--- /dev/null
|
130 | |
+++ b/tests/data/which/executable-link
|
131 | |
@@ -0,0 +1 @@
|
132 | |
+executable
|
133 | |
\ No newline at end of file
|
134 | |
diff --git a/tests/data/which/regular b/tests/data/which/regular
|
135 | |
new file mode 100644
|
136 | |
index 0000000..e69de29
|
137 | |
diff --git a/tests/fexist.c b/tests/fexist.c
|
138 | |
index 39e2daf..1cff56f 100644
|
139 | |
--- a/tests/fexist.c
|
140 | |
+++ b/tests/fexist.c
|
141 | |
@@ -5,10 +5,13 @@ int main(void)
|
142 | |
{
|
143 | |
size_t i = 0;
|
144 | |
struct { char *file; int exist; } arr[] = {
|
145 | |
- { "/etc/passwd", 1 },
|
146 | |
- { "/etc/kalle", 0 },
|
147 | |
- { "/sbin/init", 1 },
|
148 | |
- { "/dev/null", 1 },
|
149 | |
+ { "data/fexist/regular", 1 },
|
150 | |
+ { "data/fexist/executable", 1 },
|
151 | |
+ { "data/fexist/link", 1 },
|
152 | |
+ { "data/fexist/nonexistence", 0 },
|
153 | |
+ { "data/fexist/broken-link", 0 },
|
154 | |
+ { "data/fexist/dir", 1 },
|
155 | |
+ { "/dev/null", 1 },
|
156 | |
{ NULL, 0 },
|
157 | |
};
|
158 | |
|
159 | |
diff --git a/tests/lfile.c b/tests/lfile.c
|
160 | |
index 42ea8c3..19ba6e4 100644
|
161 | |
--- a/tests/lfile.c
|
162 | |
+++ b/tests/lfile.c
|
163 | |
@@ -1,7 +1,7 @@
|
164 | |
#include <stdio.h>
|
165 | |
#include "check.h"
|
166 | |
|
167 | |
-#define FSTAB "/etc/fstab"
|
168 | |
+#define FSTAB "data/lfile/fstab"
|
169 | |
|
170 | |
static int fstab(void)
|
171 | |
{
|
172 | |
@@ -42,28 +42,28 @@ int main(void)
|
173 | |
{
|
174 | |
int val;
|
175 | |
|
176 | |
- val = fgetint("/etc/protocols", " \n\t", "udp");
|
177 | |
+ val = fgetint("data/lfile/protocols", " \n\t", "udp");
|
178 | |
if (val == -1) {
|
179 | |
perror("Failed locating 'udp' protocol");
|
180 | |
return 1;
|
181 | |
}
|
182 | |
printf("udp has proto %d\n", val);
|
183 | |
|
184 | |
- val = fgetint("/etc/services", " /\n\t", "ftp");
|
185 | |
+ val = fgetint("data/lfile/services", " /\n\t", "ftp");
|
186 | |
if (val == -1) {
|
187 | |
perror("Failed locating 'ftp' service");
|
188 | |
return 1;
|
189 | |
}
|
190 | |
printf("ftp is inet port %d\n", val);
|
191 | |
|
192 | |
- val = fgetint("/etc/group", "x:\n", "utmp");
|
193 | |
+ val = fgetint("data/lfile/group", "x:\n", "utmp");
|
194 | |
if (val == -1) {
|
195 | |
perror("Failed locating group 'utmp'");
|
196 | |
return 1;
|
197 | |
}
|
198 | |
printf("utmp is gid %d\n", val);
|
199 | |
|
200 | |
- val = fgetint("/etc/passwd", "x:\n", "nobody");
|
201 | |
+ val = fgetint("data/lfile/passwd", "x:\n", "nobody");
|
202 | |
if (val == -1) {
|
203 | |
perror("Failed locating user 'nobody'");
|
204 | |
return 1;
|
205 | |
diff --git a/tests/which.c b/tests/which.c
|
206 | |
index 3e74867..a610844 100644
|
207 | |
--- a/tests/which.c
|
208 | |
+++ b/tests/which.c
|
209 | |
@@ -11,17 +11,16 @@ int main(void)
|
210 | |
int result = 0;
|
211 | |
size_t i;
|
212 | |
struct tc test[] = {
|
213 | |
- { "ls", 1 },
|
214 | |
- { "free", 1 },
|
215 | |
- { "modinfo", 1 },
|
216 | |
- { "useradd", 1 },
|
217 | |
- { "/usr/bin/which", 1 },
|
218 | |
- { "/bin/ps aux", 1 },
|
219 | |
- { "/etc/passwd", 0 },
|
220 | |
+ { "executable", 1 },
|
221 | |
+ { "executable -h", 1 },
|
222 | |
+ { "executable-link", 1 },
|
223 | |
+ { "regular", 0 },
|
224 | |
+ { "ls", 1 },
|
225 | |
+ { "/usr/bin/which", 1 },
|
226 | |
{ NULL, 0 }
|
227 | |
};
|
228 | |
|
229 | |
- setenv("PATH", "/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin", 1);
|
230 | |
+ setenv("PATH", "data/which:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin", 1);
|
231 | |
for (i = 0; test[i].cmd; i++) {
|
232 | |
char *path;
|
233 | |
|
234 | |
--
|
235 | |
2.26.2
|
236 | |
|