From 5e78edf6e09373938a796cf44fb38d2309d04b4d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 27 Jun 2022 12:59:34 -0400 Subject: Switch to meson build system --- test/meson.build | 198 +++++++++++++++++++++++++++++++++++++++++++++++ test/test_quiet.py | 23 ++++++ test/test_stdin.py | 38 +++++++++ test/test_write_error.py | 31 ++++++++ 4 files changed, 290 insertions(+) create mode 100644 test/meson.build create mode 100755 test/test_quiet.py create mode 100755 test/test_stdin.py create mode 100755 test/test_write_error.py (limited to 'test') diff --git a/test/meson.build b/test/meson.build new file mode 100644 index 00000000..b38cee42 --- /dev/null +++ b/test/meson.build @@ -0,0 +1,198 @@ +# Copyright 2021-2022 David Robillard +# SPDX-License-Identifier: CC0-1.0 OR ISC + +autoship = find_program('autoship', required: false) +run_test_suite = files('run_test_suite.py') + +wrapper = meson.get_external_property('exe_wrapper', '') + +#################### +# Project Metadata # +#################### + +if autoship.found() + test('autoship', autoship, args: ['test', serd_src_root], suite: 'data') +endif + +############## +# Unit Tests # +############## + +unit_tests = [ + 'env', + 'free_null', + 'node', + 'read_chunk', + 'reader_writer', + 'string', + 'uri', + 'writer', +] + +foreach unit : unit_tests + test( + unit, + executable( + 'test_@0@'.format(unit), + files('test_@0@.c'.format(unit)), + c_args: c_suppressions, + dependencies: serd_dep, + ), + suite: 'unit', + ) +endforeach + +################ +# System Tests # +################ + +if not get_option('tools').disabled() + if wrapper != '' + script_args = ['--wrapper', wrapper, '--serdi', serdi.full_path()] + else + script_args = ['--serdi', serdi.full_path()] + endif + + serd_ttl = files('../serd.ttl')[0] + + test('serd.ttl', serdi, args: [serd_ttl], suite: 'data') + + # Command line options + + good_args = [ + ['-v'], + ['-h'], + ['-s', ' a .'], + ] + + foreach args : good_args + test(args[0], serdi, args: args, suite: ['serdi', 'options']) + endforeach + + bad_args = [ + ['/no/such/file'], + ['ftp://unsupported.org'], + ['-c'], + ['-i', 'unknown'], + ['-i', 'turtle'], + ['-i'], + ['-fi'], + ['-o', 'unknown'], + ['-o'], + ['-p'], + ['-r'], + ['-z'], + ['-s', ' a .'], + ] + + foreach args : bad_args + name = ' '.join(args).underscorify() + test(name, serdi, + args: args, + should_fail: true, + suite: ['serdi', 'options']) + endforeach + + test('none', serdi, should_fail: true, suite: ['serdi', 'options']) + + test('quiet', files('test_quiet.py'), + args: script_args + files('bad/bad-base.ttl'), + suite: ['serdi', 'options']) + + # Inputs + + test('stdin', files('test_stdin.py'), + args: script_args, + suite: ['serdi', 'input']) + + test('string', serdi, + args: ['-s', ' a .'], + should_fail: true, + suite: ['serdi', 'input']) + + test('missing', serdi, + args: ['-i', 'turtle'], + should_fail: true, + suite: ['serdi', 'input']) + + test('no_such_file', serdi, + args: ['no_such_file'], + should_fail: true, + suite: ['serdi', 'input']) + + test('remote', serdi, + args: ['ftp://example.org/unsupported.ttl'], + should_fail: true, + suite: ['serdi', 'input']) + + # IO errors + + test('read_dir', serdi, + args: ['-e', 'file://@0@/'.format(serd_src_root)], + should_fail: true, + suite: 'io_errors') + + test('bulk_read_dir', serdi, + args: ['file://@0@/'.format(serd_src_root)], + should_fail: true, + suite: 'io_errors') + + test('write_error', files('test_write_error.py'), + args: script_args + [serd_ttl], + suite: 'io_errors') + + # RDF test suites + + ## Serd-specific test suites + + serd_suites = ['good', 'bad'] + serd_base = 'http://drobilla.net/sw/serd/test/' + + ### Run all suites with no special arguments + foreach name : serd_suites + manifest = files(name / 'manifest.ttl') + base_uri = serd_base + name + '/' + test(name, run_test_suite, + args: script_args + [manifest, base_uri], + suite: ['rdf', 'serd'], + timeout: 240) + endforeach + + ### The lax suite is special because it is run twice... + lax_manifest = files('lax/manifest.ttl') + lax_base_uri = serd_base + name + '/' + + ### ... once with strict parsing to test the hard errors + test('lax.strict', run_test_suite, + args: script_args + [lax_manifest, lax_base_uri], + is_parallel: false, + suite: ['rdf', 'serd'], + timeout: 240) + + ### ... and once with lax parsing to tolerate them + test('lax.lax', run_test_suite, + args: script_args + [lax_manifest, lax_base_uri, '--', '-l'], + is_parallel: false, + suite: ['rdf', 'serd'], + timeout: 240) + + ## Standard W3C test suites + + w3c_suites = ['Turtle', 'NTriples', 'NQuads', 'TriG'] + w3c_base = 'http://www.w3.org/2013/' + + foreach syntax : w3c_suites + manifest = files(syntax + 'Tests' / 'manifest.ttl') + base_uri = w3c_base + syntax + 'Tests/' + + args = ['--syntax', syntax, manifest, base_uri] + if syntax == 'TriG' + args += ['--', '-a'] + endif + + test(syntax, run_test_suite, + args: script_args + args, + suite: ['rdf', 'w3c'], + timeout: 240) + endforeach +endif diff --git a/test/test_quiet.py b/test/test_quiet.py new file mode 100755 index 00000000..f1d4e739 --- /dev/null +++ b/test/test_quiet.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +"""Test serdi quiet option.""" + +import argparse +import sys +import shlex +import subprocess + +parser = argparse.ArgumentParser(description=__doc__) + +parser.add_argument("--serdi", default="./serdi", help="path to serdi") +parser.add_argument("--wrapper", default="", help="executable wrapper") +parser.add_argument("input", help="invalid input file") + +args = parser.parse_args(sys.argv[1:]) +command = shlex.split(args.wrapper) + [args.serdi, "-q", args.input] +proc = subprocess.run( + command, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE +) + +assert proc.returncode != 0 +assert args.wrapper or len(proc.stderr) == 0 diff --git a/test/test_stdin.py b/test/test_stdin.py new file mode 100755 index 00000000..84b6a8b2 --- /dev/null +++ b/test/test_stdin.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 + +"""Test reading from stdin with serdi.""" + +import argparse +import sys +import shlex +import subprocess +import tempfile + +parser = argparse.ArgumentParser(description=__doc__) + +parser.add_argument("--serdi", default="./serdi", help="path to serdi") +parser.add_argument("--wrapper", default="", help="executable wrapper") + +args = parser.parse_args(sys.argv[1:]) +command = shlex.split(args.wrapper) + [args.serdi, "-"] + +DOCUMENT = "<{0}s> <{0}p> <{0}o> .".format("http://example.org/") + +with tempfile.TemporaryFile() as out: + proc = subprocess.run( + command, + check=False, + encoding="utf-8", + input=DOCUMENT, + stdout=out, + stderr=subprocess.PIPE, + ) + + assert proc.returncode == 0 + assert args.wrapper or len(proc.stderr) == 0 + + out.seek(0) + lines = out.readlines() + + assert len(lines) == 1 + assert lines[0].decode("utf-8").strip() == DOCUMENT diff --git a/test/test_write_error.py b/test/test_write_error.py new file mode 100755 index 00000000..35b4693b --- /dev/null +++ b/test/test_write_error.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +"""Test errors writing to a file.""" + +import argparse +import sys +import shlex +import subprocess +import os + +parser = argparse.ArgumentParser(description=__doc__) + +parser.add_argument("--serdi", default="./serdi", help="path to serdi") +parser.add_argument("--wrapper", default="", help="executable wrapper") +parser.add_argument("input", help="valid input file") + +args = parser.parse_args(sys.argv[1:]) +command = shlex.split(args.wrapper) + [args.serdi, args.input] + +if os.path.exists("/dev/full"): + + with open("/dev/full", "w") as out: + proc = subprocess.run( + command, check=False, stdout=out, stderr=subprocess.PIPE + ) + + assert proc.returncode != 0 + assert "error" in proc.stderr.decode("utf-8") + +else: + sys.stderr.write("warning: /dev/full not present, skipping test") -- cgit v1.2.1