This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19 #include "execute.h"
20
21 #include <stdbool.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
25
26 #include "read-file.h"
27 #include "macros.h"
28
29 #define DATA_FILENAME "test-execute-script.tmp"
30
31 int
32 main ()
33 {
34 unlink (DATA_FILENAME);
35
36
37
38
39
40
41
42
43
44
45
46
47 FILE *fp = freopen (DATA_FILENAME, "w", stdout);
48 ASSERT (fp != NULL);
49
50 {
51 size_t i;
52
53 for (i = 0; i < 2; i++)
54 {
55 const char *progname =
56 (i == 0 ? "executable-script" : "executable-script.sh");
57 const char *prog_path =
58 (i == 0 ? SRCDIR "executable-script" : SRCDIR "executable-script.sh");
59 const char *prog_argv[2] = { prog_path, NULL };
60
61 int ret = execute (progname, prog_argv[0], prog_argv, NULL,
62 false, false, false, false, true, false, NULL);
63 ASSERT (ret == 127);
64 }
65 }
66
67 #if defined _WIN32 && !defined __CYGWIN__
68
69
70 ASSERT (fclose (fp) == 0);
71 ASSERT (unlink (DATA_FILENAME) == 0);
72 fprintf (stderr, "Skipping test: scripts are not executable on this platform.\n");
73 return 77;
74 #else
75 {
76 const char *progname = "executable-shell-script";
77 const char *prog_path = SRCDIR "executable-shell-script";
78 const char *prog_argv[2] = { prog_path, NULL };
79
80 int ret = execute (progname, prog_argv[0], prog_argv, NULL,
81 false, false, false, false, true, false, NULL);
82 ASSERT (ret == 0);
83
84 ASSERT (fclose (fp) == 0);
85
86 size_t length;
87 char *contents = read_file (DATA_FILENAME, 0, &length);
88 ASSERT (length == 11 && memcmp (contents, "Halle Potta", 11) == 0);
89 }
90
91 ASSERT (unlink (DATA_FILENAME) == 0);
92
93 return 0;
94 #endif
95 }