aboutsummaryrefslogtreecommitdiffstats
path: root/meson/test cases/native/8 external program shebang parsing
diff options
context:
space:
mode:
Diffstat (limited to 'meson/test cases/native/8 external program shebang parsing')
-rw-r--r--meson/test cases/native/8 external program shebang parsing/input.txt1
-rw-r--r--meson/test cases/native/8 external program shebang parsing/main.c72
-rw-r--r--meson/test cases/native/8 external program shebang parsing/meson.build21
-rw-r--r--meson/test cases/native/8 external program shebang parsing/script.int.in2
4 files changed, 96 insertions, 0 deletions
diff --git a/meson/test cases/native/8 external program shebang parsing/input.txt b/meson/test cases/native/8 external program shebang parsing/input.txt
new file mode 100644
index 000000000..40e30d4b2
--- /dev/null
+++ b/meson/test cases/native/8 external program shebang parsing/input.txt
@@ -0,0 +1 @@
+some stuff here
diff --git a/meson/test cases/native/8 external program shebang parsing/main.c b/meson/test cases/native/8 external program shebang parsing/main.c
new file mode 100644
index 000000000..48b080e1f
--- /dev/null
+++ b/meson/test cases/native/8 external program shebang parsing/main.c
@@ -0,0 +1,72 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+
+#ifdef _WIN32
+ #include <io.h>
+ #include <windows.h>
+#else
+ #include <unistd.h>
+#endif
+
+/* Who cares about stack sizes in test programs anyway */
+#define LINE_LENGTH 4096
+
+static int
+intrp_copyfile (char * src, char * dest)
+{
+#ifdef _WIN32
+ if (!CopyFile (src, dest, FALSE))
+ return 1;
+ return 0;
+#else
+ return execlp ("cp", "cp", src, dest, NULL);
+#endif
+}
+
+static void
+parser_get_line (FILE * f, char line[LINE_LENGTH])
+{
+ if (!fgets (line, LINE_LENGTH, f))
+ fprintf (stderr, "%s\n", strerror (errno));
+}
+
+int
+main (int argc, char * argv[])
+{
+ FILE *f = NULL;
+ char line[LINE_LENGTH];
+
+ if (argc != 4) {
+ fprintf (stderr, "Invalid number of arguments: %i\n", argc);
+ goto err;
+ }
+
+ if ((f = fopen (argv[1], "r")) == NULL) {
+ fprintf (stderr, "%s\n", strerror (errno));
+ goto err;
+ }
+
+ parser_get_line (f, line);
+
+ if (!line || line[0] != '#' || line[1] != '!') {
+ fprintf (stderr, "Invalid script\n");
+ goto err;
+ }
+
+ parser_get_line (f, line);
+
+ if (!line || strncmp (line, "copy", 4) != 0) {
+ fprintf (stderr, "Syntax error: %s\n", line);
+ goto err;
+ }
+
+ return intrp_copyfile (argv[2], argv[3]);
+
+err:
+ fclose (f);
+ return 1;
+}
diff --git a/meson/test cases/native/8 external program shebang parsing/meson.build b/meson/test cases/native/8 external program shebang parsing/meson.build
new file mode 100644
index 000000000..c1cc5af9d
--- /dev/null
+++ b/meson/test cases/native/8 external program shebang parsing/meson.build
@@ -0,0 +1,21 @@
+project('shebang parsing', 'c')
+
+interpreter = executable('aninterp', 'main.c', native : true)
+
+cdata = configuration_data()
+cdata.set('INTRP', interpreter.full_path())
+
+f = configure_file(input : 'script.int.in',
+ output : 'script.int',
+ configuration : cdata)
+
+# Test that parsing a shebang with spaces works properly. See `man execve`,
+# specifically the section on "Interpreter scripts" and the one under "NOTES".
+script = find_program(f)
+
+custom_target('interpthis',
+ input : 'input.txt',
+ output : 'output.txt',
+ depends : interpreter,
+ command : [script, '@INPUT@', '@OUTPUT@'],
+ build_by_default : true)
diff --git a/meson/test cases/native/8 external program shebang parsing/script.int.in b/meson/test cases/native/8 external program shebang parsing/script.int.in
new file mode 100644
index 000000000..77ff90907
--- /dev/null
+++ b/meson/test cases/native/8 external program shebang parsing/script.int.in
@@ -0,0 +1,2 @@
+#!/usr/bin/env @INTRP@
+copy