summaryrefslogtreecommitdiffstats
path: root/test cases/common/41 test args
diff options
context:
space:
mode:
Diffstat (limited to 'test cases/common/41 test args')
-rw-r--r--test cases/common/41 test args/cmd_args.c18
-rw-r--r--test cases/common/41 test args/copyfile.py6
-rw-r--r--test cases/common/41 test args/env2vars.c23
-rw-r--r--test cases/common/41 test args/envvars.c23
-rw-r--r--test cases/common/41 test args/meson.build35
-rw-r--r--test cases/common/41 test args/tester.c34
-rwxr-xr-xtest cases/common/41 test args/tester.py11
-rw-r--r--test cases/common/41 test args/testfile.txt1
8 files changed, 151 insertions, 0 deletions
diff --git a/test cases/common/41 test args/cmd_args.c b/test cases/common/41 test args/cmd_args.c
new file mode 100644
index 0000000..545b795
--- /dev/null
+++ b/test cases/common/41 test args/cmd_args.c
@@ -0,0 +1,18 @@
+#include<stdio.h>
+#include<string.h>
+
+int main(int argc, char **argv) {
+ if(argc != 3) {
+ fprintf(stderr, "Incorrect number of arguments.\n");
+ return 1;
+ }
+ if(strcmp(argv[1], "first") != 0) {
+ fprintf(stderr, "First argument is wrong.\n");
+ return 1;
+ }
+ if(strcmp(argv[2], "second") != 0) {
+ fprintf(stderr, "Second argument is wrong.\n");
+ return 1;
+ }
+ return 0;
+}
diff --git a/test cases/common/41 test args/copyfile.py b/test cases/common/41 test args/copyfile.py
new file mode 100644
index 0000000..ff42ac3
--- /dev/null
+++ b/test cases/common/41 test args/copyfile.py
@@ -0,0 +1,6 @@
+#!/usr/bin/env python3
+
+import sys
+import shutil
+
+shutil.copyfile(sys.argv[1], sys.argv[2])
diff --git a/test cases/common/41 test args/env2vars.c b/test cases/common/41 test args/env2vars.c
new file mode 100644
index 0000000..e940c9a
--- /dev/null
+++ b/test cases/common/41 test args/env2vars.c
@@ -0,0 +1,23 @@
+#include<stdio.h>
+#include<string.h>
+#include<stdlib.h>
+
+int main(void) {
+ if(strcmp(getenv("first"), "something-else") != 0) {
+ fprintf(stderr, "First envvar is wrong. %s\n", getenv("first"));
+ return 1;
+ }
+ if(strcmp(getenv("second"), "val2") != 0) {
+ fprintf(stderr, "Second envvar is wrong.\n");
+ return 1;
+ }
+ if(strcmp(getenv("third"), "val3:and_more") != 0) {
+ fprintf(stderr, "Third envvar is wrong.\n");
+ return 1;
+ }
+ if(strstr(getenv("PATH"), "fakepath:") != NULL) {
+ fprintf(stderr, "Third envvar is wrong.\n");
+ return 1;
+ }
+ return 0;
+}
diff --git a/test cases/common/41 test args/envvars.c b/test cases/common/41 test args/envvars.c
new file mode 100644
index 0000000..086b0be
--- /dev/null
+++ b/test cases/common/41 test args/envvars.c
@@ -0,0 +1,23 @@
+#include<stdio.h>
+#include<string.h>
+#include<stdlib.h>
+
+int main(void) {
+ if(strcmp(getenv("first"), "val1") != 0) {
+ fprintf(stderr, "First envvar is wrong. %s\n", getenv("first"));
+ return 1;
+ }
+ if(strcmp(getenv("second"), "val2") != 0) {
+ fprintf(stderr, "Second envvar is wrong.\n");
+ return 1;
+ }
+ if(strcmp(getenv("third"), "val3:and_more") != 0) {
+ fprintf(stderr, "Third envvar is wrong.\n");
+ return 1;
+ }
+ if(strstr(getenv("PATH"), "fakepath:") != NULL) {
+ fprintf(stderr, "Third envvar is wrong.\n");
+ return 1;
+ }
+ return 0;
+}
diff --git a/test cases/common/41 test args/meson.build b/test cases/common/41 test args/meson.build
new file mode 100644
index 0000000..b21f1ad
--- /dev/null
+++ b/test cases/common/41 test args/meson.build
@@ -0,0 +1,35 @@
+project('test features', 'c')
+
+e1 = executable('cmd_args', 'cmd_args.c')
+e2 = executable('envvars', 'envvars.c')
+e3 = executable('env2vars', 'env2vars.c')
+
+env = environment()
+env.set('first', 'val1')
+env.set('second', 'val2')
+env.set('third', 'val3', 'and_more', separator: ':')
+env.append('PATH', 'fakepath', separator: ':')
+
+# Make sure environment objects are copied on assignment and we can
+# change the copy without affecting the original environment object.
+env2 = env
+env2.set('first', 'something-else')
+
+test('command line arguments', e1, args : ['first', 'second'])
+test('environment variables', e2, env : env)
+test('environment variables 2', e3, env : env2)
+
+# https://github.com/mesonbuild/meson/issues/2211#issuecomment-327741571
+env_array = ['MESONTESTING=picklerror']
+testfile = files('testfile.txt')
+testerpy = find_program('tester.py')
+test('file arg', testerpy, args : testfile, env : [env_array, 'TEST_LIST_FLATTENING=1'])
+
+copy = find_program('copyfile.py')
+tester = executable('tester', 'tester.c')
+testfilect = custom_target('testfile',
+ input : testfile,
+ output : 'outfile.txt',
+ build_by_default : true,
+ command : [copy, '@INPUT@', '@OUTPUT@'])
+test('custom target arg', tester, args : testfilect, env : env_array)
diff --git a/test cases/common/41 test args/tester.c b/test cases/common/41 test args/tester.c
new file mode 100644
index 0000000..419277e
--- /dev/null
+++ b/test cases/common/41 test args/tester.c
@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#ifndef _MSC_VER
+#include <unistd.h>
+#endif
+
+int main(int argc, char **argv) {
+ char data[10];
+ int fd, size;
+
+ if (argc != 2) {
+ fprintf(stderr, "Incorrect number of arguments, got %i\n", argc);
+ return 1;
+ }
+ fd = open(argv[1], O_RDONLY);
+ if (fd < 0) {
+ fprintf(stderr, "First argument is wrong.\n");
+ return 1;
+ }
+
+ size = read(fd, data, 8);
+ if (size < 0) {
+ fprintf(stderr, "Failed to read: %s\n", strerror(errno));
+ return 1;
+ }
+ if (strncmp(data, "contents", 8) != 0) {
+ fprintf(stderr, "Contents don't match, got %s\n", data);
+ return 1;
+ }
+ return 0;
+}
diff --git a/test cases/common/41 test args/tester.py b/test cases/common/41 test args/tester.py
new file mode 100755
index 0000000..b5884cc
--- /dev/null
+++ b/test cases/common/41 test args/tester.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python3
+
+import sys
+import os
+
+assert os.environ['MESONTESTING'] == 'picklerror'
+assert os.environ['TEST_LIST_FLATTENING'] == '1'
+
+with open(sys.argv[1]) as f:
+ if f.read() != 'contents\n':
+ sys.exit(1)
diff --git a/test cases/common/41 test args/testfile.txt b/test cases/common/41 test args/testfile.txt
new file mode 100644
index 0000000..12f00e9
--- /dev/null
+++ b/test cases/common/41 test args/testfile.txt
@@ -0,0 +1 @@
+contents