diff options
| author | Jussi Pakkanen <jpakkane@gmail.com> | 2021-04-26 16:52:13 +0300 |
|---|---|---|
| committer | Jussi Pakkanen <jpakkane@gmail.com> | 2021-04-26 23:39:15 +0100 |
| commit | e75e3976facda7de244fbb9a02eebf0d043ea1c8 (patch) | |
| tree | dab22f95b5c837a70b1b4164d97ff351a49ffd81 /test cases/common/41 test args | |
| parent | 53fe7c2f0a51697cd57628753852dd3f8711becf (diff) | |
| download | meson-e75e3976facda7de244fbb9a02eebf0d043ea1c8.tar.gz | |
Condense test directory names.
Diffstat (limited to 'test cases/common/41 test args')
| -rw-r--r-- | test cases/common/41 test args/cmd_args.c | 18 | ||||
| -rw-r--r-- | test cases/common/41 test args/copyfile.py | 6 | ||||
| -rw-r--r-- | test cases/common/41 test args/env2vars.c | 23 | ||||
| -rw-r--r-- | test cases/common/41 test args/envvars.c | 23 | ||||
| -rw-r--r-- | test cases/common/41 test args/meson.build | 35 | ||||
| -rw-r--r-- | test cases/common/41 test args/tester.c | 34 | ||||
| -rwxr-xr-x | test cases/common/41 test args/tester.py | 7 | ||||
| -rw-r--r-- | test cases/common/41 test args/testfile.txt | 1 |
8 files changed, 147 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 000000000..545b795c5 --- /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 000000000..ff42ac359 --- /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 000000000..e940c9a8c --- /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 000000000..086b0be34 --- /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 000000000..81d34915a --- /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) + +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 000000000..419277e5b --- /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 000000000..0b4010ab9 --- /dev/null +++ b/test cases/common/41 test args/tester.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 + +import sys + +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 000000000..12f00e90b --- /dev/null +++ b/test cases/common/41 test args/testfile.txt @@ -0,0 +1 @@ +contents |
