diff options
author | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
---|---|---|
committer | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /meson/test cases/common/41 test args | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'meson/test cases/common/41 test args')
-rw-r--r-- | meson/test cases/common/41 test args/cmd_args.c | 18 | ||||
-rw-r--r-- | meson/test cases/common/41 test args/copyfile.py | 6 | ||||
-rw-r--r-- | meson/test cases/common/41 test args/env2vars.c | 23 | ||||
-rw-r--r-- | meson/test cases/common/41 test args/envvars.c | 23 | ||||
-rw-r--r-- | meson/test cases/common/41 test args/meson.build | 35 | ||||
-rw-r--r-- | meson/test cases/common/41 test args/tester.c | 34 | ||||
-rwxr-xr-x | meson/test cases/common/41 test args/tester.py | 11 | ||||
-rw-r--r-- | meson/test cases/common/41 test args/testfile.txt | 1 |
8 files changed, 151 insertions, 0 deletions
diff --git a/meson/test cases/common/41 test args/cmd_args.c b/meson/test cases/common/41 test args/cmd_args.c new file mode 100644 index 000000000..545b795c5 --- /dev/null +++ b/meson/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/meson/test cases/common/41 test args/copyfile.py b/meson/test cases/common/41 test args/copyfile.py new file mode 100644 index 000000000..ff42ac359 --- /dev/null +++ b/meson/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/meson/test cases/common/41 test args/env2vars.c b/meson/test cases/common/41 test args/env2vars.c new file mode 100644 index 000000000..e940c9a8c --- /dev/null +++ b/meson/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/meson/test cases/common/41 test args/envvars.c b/meson/test cases/common/41 test args/envvars.c new file mode 100644 index 000000000..086b0be34 --- /dev/null +++ b/meson/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/meson/test cases/common/41 test args/meson.build b/meson/test cases/common/41 test args/meson.build new file mode 100644 index 000000000..b21f1ad00 --- /dev/null +++ b/meson/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/meson/test cases/common/41 test args/tester.c b/meson/test cases/common/41 test args/tester.c new file mode 100644 index 000000000..419277e5b --- /dev/null +++ b/meson/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/meson/test cases/common/41 test args/tester.py b/meson/test cases/common/41 test args/tester.py new file mode 100755 index 000000000..b5884cc61 --- /dev/null +++ b/meson/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/meson/test cases/common/41 test args/testfile.txt b/meson/test cases/common/41 test args/testfile.txt new file mode 100644 index 000000000..12f00e90b --- /dev/null +++ b/meson/test cases/common/41 test args/testfile.txt @@ -0,0 +1 @@ +contents |