diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/.clang-tidy | 2 | ||||
-rw-r--r-- | test/headers/test_headers.c | 3 | ||||
-rw-r--r-- | test/meson.build | 252 | ||||
-rw-r--r-- | test/serd_test_util/__init__.py | 29 | ||||
-rw-r--r-- | test/test_env.c | 4 | ||||
-rw-r--r-- | test/test_node.c | 6 | ||||
-rwxr-xr-x | test/test_quiet.py | 12 | ||||
-rw-r--r-- | test/test_reader.c | 110 | ||||
-rw-r--r-- | test/test_reader_writer.c | 24 | ||||
-rwxr-xr-x | test/test_stdin.py | 37 | ||||
-rw-r--r-- | test/test_string.c | 3 | ||||
-rw-r--r-- | test/test_uri.c | 107 | ||||
-rwxr-xr-x | test/test_write_error.py | 9 | ||||
-rw-r--r-- | test/test_writer.c | 1 |
14 files changed, 306 insertions, 293 deletions
diff --git a/test/.clang-tidy b/test/.clang-tidy index 457abcaf..99a3264a 100644 --- a/test/.clang-tidy +++ b/test/.clang-tidy @@ -8,9 +8,11 @@ Checks: > -bugprone-easily-swappable-parameters, -cert-err33-c, -clang-analyzer-nullability.NullableDereferenced, + -clang-analyzer-optin.core.EnumCastOutOfRange, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, -concurrency-mt-unsafe, -hicpp-signed-bitwise, + -readability-redundant-casting, CheckOptions: - key: readability-function-cognitive-complexity.IgnoreMacros value: 'true' diff --git a/test/headers/test_headers.c b/test/headers/test_headers.c index c855c103..62be0976 100644 --- a/test/headers/test_headers.c +++ b/test/headers/test_headers.c @@ -3,8 +3,7 @@ #include "serd/serd.h" // IWYU pragma: keep -SERD_CONST_FUNC -int +SERD_CONST_FUNC int main(void) { return 0; diff --git a/test/meson.build b/test/meson.build index 33f86dfb..4d770304 100644 --- a/test/meson.build +++ b/test/meson.build @@ -4,109 +4,6 @@ run_suite = find_program('run_suite.py') wrapper = meson.get_external_property('exe_wrapper', '') -######################## -# Scripts and Metadata # -######################## - -plot_script_paths = [ - '../scripts/serd_bench.py', -] - -simple_script_paths = [ - '../scripts/check_formatting.py', - 'serd_test_util/__init__.py', - 'run_suite.py', - 'test_quiet.py', - 'test_stdin.py', - 'test_write_error.py', -] - -ttl_metadata_file_paths = [ - '../serd.ttl', - 'extra/abbreviate/manifest.ttl', - 'extra/bad/manifest.ttl', - 'extra/big/manifest.ttl', - 'extra/full/manifest.ttl', - 'extra/good/manifest.ttl', - 'extra/lax/manifest.ttl', - 'extra/perfect/manifest.ttl', - 'extra/prefix/manifest.ttl', - 'extra/pretty/manifest.ttl', - 'extra/qualify/manifest.ttl', - 'extra/root/manifest.ttl', -] - -plot_scripts = files(plot_script_paths) -simple_scripts = files(simple_script_paths) -python_script_paths = simple_script_paths + plot_script_paths -python_scripts = plot_scripts + simple_scripts - -if get_option('lint') - # Check release metadata - if not meson.is_subproject() - autoship = find_program('autoship', required: false) - if autoship.found() - test('autoship', autoship, args: ['test', serd_src_root], suite: 'data') - endif - endif - - # Check licensing metadata - reuse = find_program('reuse', required: false) - if reuse.found() - test( - 'REUSE', - reuse, - args: ['--root', serd_src_root, 'lint'], - suite: 'data', - ) - endif - - # Check script formatting - black = find_program('black', required: false) - if black.found() - black_opts = ['--check', '-q', '-l', '79'] - foreach script_path : python_script_paths - script = files(script_path) - name = script_path.underscorify() - test(name, black, args: black_opts + [script], suite: 'scripts') - endforeach - endif - - # Check scripts for errors with flake8 - flake8 = find_program('flake8', required: false) - if flake8.found() - test('flake8', flake8, args: python_scripts, suite: 'scripts') - endif - - # Check scripts for errors with pylint - pylint = find_program('pylint', required: false) - if pylint.found() - pymod = import('python') - plot_py = pymod.find_installation( - 'python3', - modules: ['matplotlib'], - required: false, - ) - - pylint_args = ['--disable', 'bad-option-value'] + simple_scripts - if plot_py.found() - pylint_args += plot_scripts - endif - - test('pylint', pylint, args: pylint_args, suite: 'scripts') - endif - - # Check Turtle formatting with serdi - foreach ttl_file_path : ttl_metadata_file_paths - test( - ttl_file_path.underscorify(), - check_formatting_py, - args: [files(ttl_file_path), serdi, '-o', 'turtle'], - suite: 'data', - ) - endforeach -endif - ################### # Header Warnings # ################### @@ -117,7 +14,7 @@ subdir('headers') # Unit Tests # ############## -unit_tests = [ +unit_test_names = [ 'env', 'free_null', 'node', @@ -128,12 +25,16 @@ unit_tests = [ 'writer', ] -foreach unit : unit_tests +unit_test_sources = files('headers/test_headers.c') + +foreach name : unit_test_names + source = files('test_@0@.c'.format(name)) + unit_test_sources += source test( - unit, + name, executable( - 'test_@0@'.format(unit), - files('test_@0@.c'.format(unit)), + 'test_@0@'.format(name), + source, c_args: c_suppressions, dependencies: serd_dep, ), @@ -392,3 +293,138 @@ if is_variable('serdi') ) endforeach endif + +######## +# Lint # +######## + +plot_script_paths = [ + '../scripts/serd_bench.py', +] + +simple_script_paths = [ + '../scripts/check_formatting.py', + 'serd_test_util/__init__.py', + 'run_suite.py', + 'test_quiet.py', + 'test_stdin.py', + 'test_write_error.py', +] + +ttl_metadata_file_paths = [ + '../serd.ttl', + 'extra/abbreviate/manifest.ttl', + 'extra/bad/manifest.ttl', + 'extra/big/manifest.ttl', + 'extra/full/manifest.ttl', + 'extra/good/manifest.ttl', + 'extra/lax/manifest.ttl', + 'extra/perfect/manifest.ttl', + 'extra/prefix/manifest.ttl', + 'extra/pretty/manifest.ttl', + 'extra/qualify/manifest.ttl', + 'extra/root/manifest.ttl', +] + +plot_scripts = files(plot_script_paths) +simple_scripts = files(simple_script_paths) +python_script_paths = simple_script_paths + plot_script_paths +python_scripts = plot_scripts + simple_scripts + +if get_option('lint') + all_sources = sources + unit_test_sources + files('../src/serdi.c') + + if not meson.is_subproject() + # Check release metadata + autoship = find_program('autoship', required: false) + if autoship.found() + test('autoship', autoship, args: ['test', serd_src_root], suite: 'data') + endif + + # Check code with cppcheck + cppcheck = find_program('cppcheck', required: false) + if cppcheck.found() + compdb_path = join_paths(serd_build_root, 'compile_commands.json') + suppress_path = join_paths(serd_src_root, '.suppress.cppcheck') + test( + 'cppcheck', + cppcheck, + args: [ + '--enable=warning,style,performance,portability', + '--error-exitcode=1', + '--project=' + compdb_path, + '--suppressions-list=' + suppress_path, + '-q', + ], + suite: 'code', + ) + endif + endif + + # Check licensing metadata + reuse = find_program('reuse', required: false) + if reuse.found() + test( + 'REUSE', + reuse, + args: ['--root', serd_src_root, 'lint'], + suite: 'data', + ) + endif + + # Check code formatting + clang_format = find_program('clang-format', required: false) + if clang_format.found() + test( + 'format', + clang_format, + args: ['--Werror', '--dry-run'] + c_headers + all_sources, + suite: 'code', + ) + endif + + # Check script formatting + black = find_program('black', required: false) + if black.found() + black_opts = ['--check', '-q', '-l', '79'] + foreach script_path : python_script_paths + script = files(script_path) + name = script_path.underscorify() + test(name, black, args: black_opts + [script], suite: 'scripts') + endforeach + endif + + # Check scripts for errors with flake8 + flake8 = find_program('flake8', required: false) + if flake8.found() + test('flake8', flake8, args: python_scripts, suite: 'scripts') + endif + + # Check scripts for errors with pylint + pylint = find_program('pylint', required: false) + if pylint.found() + pymod = import('python') + plot_py = pymod.find_installation( + 'python3', + modules: ['matplotlib'], + required: false, + ) + + pylint_args = ['--disable', 'bad-option-value'] + simple_scripts + if plot_py.found() + pylint_args += plot_scripts + endif + + test('pylint', pylint, args: pylint_args, suite: 'scripts') + endif + + # Check Turtle formatting with serdi + foreach ttl_file_path : ttl_metadata_file_paths + test( + ttl_file_path.underscorify(), + check_formatting_py, + args: [files(ttl_file_path), serdi, '-o', 'turtle'], + suite: 'data', + ) + endforeach +endif diff --git a/test/serd_test_util/__init__.py b/test/serd_test_util/__init__.py index 8027462b..ad417762 100644 --- a/test/serd_test_util/__init__.py +++ b/test/serd_test_util/__init__.py @@ -8,10 +8,12 @@ # pylint: disable=consider-using-f-string # pylint: disable=invalid-name +import argparse import datetime import difflib import os import re +import shlex import subprocess import sys import urllib.parse @@ -51,6 +53,33 @@ def error(message): sys.stderr.write("\n") +def wrapper_args(description, with_input=False): + """Return the command line arguments for a wrapped test.""" + + parser = argparse.ArgumentParser(description) + parser.add_argument("--serdi", default="./serdi", help="serdi executable") + parser.add_argument("--wrapper", default="", help="executable wrapper") + if with_input: + parser.add_argument("input", help="input file") + + return parser.parse_args(sys.argv[1:]) + + +def command_output(wrapper, command, stdin=None): + """Run a command and check that stdout matches the expected output.""" + + proc = subprocess.run( + shlex.split(wrapper) + command, + capture_output=True, + check=True, + encoding="utf-8", + input=stdin, + ) + + assert wrapper or not proc.stderr + return proc.stdout + + def print_result_summary(results): """Print test result summary to stdout or stderr as appropriate.""" diff --git a/test/test_env.c b/test/test_env.c index d51e0595..903ae3f2 100644 --- a/test/test_env.c +++ b/test/test_env.c @@ -13,7 +13,9 @@ #define USTR(s) ((const uint8_t*)(s)) static SerdStatus -count_prefixes(void* handle, const SerdNode* name, const SerdNode* uri) +count_prefixes(void* const handle, + const SerdNode* const name, + const SerdNode* const uri) { (void)name; (void)uri; diff --git a/test/test_node.c b/test/test_node.c index af14171b..28db00ea 100644 --- a/test/test_node.c +++ b/test/test_node.c @@ -24,7 +24,7 @@ #endif static void -test_strtod(double dbl, double max_delta) +check_strtod(const double dbl, const double max_delta) { char buf[1024]; snprintf(buf, sizeof(buf), "%f", dbl); @@ -56,7 +56,7 @@ test_string_to_double(void) const double delta = fabs(num - expt_test_nums[i]); assert(delta <= DBL_EPSILON); - test_strtod(expt_test_nums[i], DBL_EPSILON); + check_strtod(expt_test_nums[i], DBL_EPSILON); } } @@ -285,7 +285,5 @@ main(void) test_node_from_string(); test_node_from_substring(); test_uri_node_from_node(); - - printf("Success\n"); return 0; } diff --git a/test/test_quiet.py b/test/test_quiet.py index 42d05785..676284bb 100755 --- a/test/test_quiet.py +++ b/test/test_quiet.py @@ -3,20 +3,14 @@ # Copyright 2022 David Robillard <d@drobilla.net> # SPDX-License-Identifier: ISC -"""Test serdi quiet option.""" +"""Test quiet command-line option.""" -import argparse -import sys import shlex import subprocess -parser = argparse.ArgumentParser(description=__doc__) +import serd_test_util as util -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:]) +args = util.wrapper_args(__doc__, True) command = shlex.split(args.wrapper) + [args.serdi, "-q", args.input] proc = subprocess.run( command, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE diff --git a/test/test_reader.c b/test/test_reader.c index b102f8a6..e185b915 100644 --- a/test/test_reader.c +++ b/test/test_reader.c @@ -26,7 +26,7 @@ typedef struct { } ReaderTest; static SerdStatus -test_base_sink(void* const handle, const SerdNode* const uri) +base_sink(void* const handle, const SerdNode* const uri) { (void)uri; @@ -36,9 +36,9 @@ test_base_sink(void* const handle, const SerdNode* const uri) } static SerdStatus -test_prefix_sink(void* const handle, - const SerdNode* const name, - const SerdNode* const uri) +prefix_sink(void* const handle, + const SerdNode* const name, + const SerdNode* const uri) { (void)name; (void)uri; @@ -49,14 +49,14 @@ test_prefix_sink(void* const handle, } static SerdStatus -test_statement_sink(void* const handle, - SerdStatementFlags flags, - const SerdNode* const graph, - const SerdNode* const subject, - const SerdNode* const predicate, - const SerdNode* const object, - const SerdNode* const object_datatype, - const SerdNode* const object_lang) +statement_sink(void* const handle, + SerdStatementFlags flags, + const SerdNode* const graph, + const SerdNode* const subject, + const SerdNode* const predicate, + const SerdNode* const object, + const SerdNode* const object_datatype, + const SerdNode* const object_lang) { (void)flags; (void)graph; @@ -72,7 +72,7 @@ test_statement_sink(void* const handle, } static SerdStatus -test_end_sink(void* const handle, const SerdNode* const node) +end_sink(void* const handle, const SerdNode* const node) { (void)node; @@ -85,13 +85,8 @@ static void test_read_string(void) { ReaderTest rt = {0, 0, 0, 0}; - SerdReader* const reader = serd_reader_new(SERD_TURTLE, - &rt, - NULL, - test_base_sink, - test_prefix_sink, - test_statement_sink, - test_end_sink); + SerdReader* const reader = serd_reader_new( + SERD_TURTLE, &rt, NULL, base_sink, prefix_sink, statement_sink, end_sink); assert(reader); assert(serd_reader_get_handle(reader) == &rt); @@ -113,7 +108,10 @@ test_read_string(void) /// Reads a null byte after a statement, then succeeds again (like a socket) static size_t -eof_test_read(void* buf, size_t size, size_t nmemb, void* stream) +eof_test_read(void* const buf, + const size_t size, + const size_t nmemb, + void* const stream) { assert(size == 1); assert(nmemb == 1); @@ -149,15 +147,15 @@ eof_test_read(void* buf, size_t size, size_t nmemb, void* stream) } static int -eof_test_error(void* stream) +eof_test_error(void* const stream) { (void)stream; return 0; } -/// A read of a big page hits EOF then fails to read chunks immediately +/// A read of a file stream hits EOF then fails to read chunks immediately static void -test_read_eof_by_page(const char* const path) +test_read_eof_file(const char* const path) { FILE* const f = fopen(path, "w+b"); assert(f); @@ -167,21 +165,23 @@ test_read_eof_by_page(const char* const path) fseek(f, 0L, SEEK_SET); ReaderTest rt = {0, 0, 0, 0}; - SerdReader* const reader = serd_reader_new(SERD_TURTLE, - &rt, - NULL, - test_base_sink, - test_prefix_sink, - test_statement_sink, - test_end_sink); + SerdReader* const reader = serd_reader_new( + SERD_TURTLE, &rt, NULL, base_sink, prefix_sink, statement_sink, end_sink); + fseek(f, 0L, SEEK_SET); serd_reader_start_stream(reader, f, (const uint8_t*)"test", true); - assert(serd_reader_read_chunk(reader) == SERD_SUCCESS); assert(serd_reader_read_chunk(reader) == SERD_FAILURE); assert(serd_reader_read_chunk(reader) == SERD_FAILURE); + serd_reader_end_stream(reader); + fseek(f, 0L, SEEK_SET); + serd_reader_start_stream(reader, f, (const uint8_t*)"test", false); + assert(serd_reader_read_chunk(reader) == SERD_SUCCESS); + assert(serd_reader_read_chunk(reader) == SERD_FAILURE); + assert(serd_reader_read_chunk(reader) == SERD_FAILURE); serd_reader_end_stream(reader); + serd_reader_free(reader); fclose(f); } @@ -191,13 +191,8 @@ static void test_read_eof_by_byte(void) { ReaderTest rt = {0, 0, 0, 0}; - SerdReader* const reader = serd_reader_new(SERD_TURTLE, - &rt, - NULL, - test_base_sink, - test_prefix_sink, - test_statement_sink, - test_end_sink); + SerdReader* const reader = serd_reader_new( + SERD_TURTLE, &rt, NULL, base_sink, prefix_sink, statement_sink, end_sink); size_t n_reads = 0U; serd_reader_start_source_stream(reader, @@ -212,6 +207,7 @@ test_read_eof_by_byte(void) assert(serd_reader_read_chunk(reader) == SERD_SUCCESS); assert(serd_reader_read_chunk(reader) == SERD_FAILURE); + serd_reader_end_stream(reader); serd_reader_free(reader); } @@ -236,24 +232,21 @@ test_read_nquads_chunks(const char* const path) fprintf(f, "<http://example.org/s> <http://example.org/p3> " - "<http://example.org/o3> .\n"); + "<http://example.org/o3> ."); fseek(f, 0, SEEK_SET); ReaderTest rt = {0, 0, 0, 0}; - SerdReader* const reader = serd_reader_new(SERD_NQUADS, - &rt, - NULL, - test_base_sink, - test_prefix_sink, - test_statement_sink, - test_end_sink); + SerdReader* const reader = serd_reader_new( + SERD_NQUADS, &rt, NULL, base_sink, prefix_sink, statement_sink, end_sink); assert(reader); assert(serd_reader_get_handle(reader) == &rt); assert(f); - SerdStatus st = serd_reader_start_stream(reader, f, NULL, false); + SerdStatus st = serd_reader_start_source_stream( + reader, (SerdSource)fread, (SerdStreamErrorFunc)ferror, f, NULL, 32U); + assert(st == SERD_SUCCESS); // Read first statement @@ -297,7 +290,7 @@ test_read_nquads_chunks(const char* const path) assert(rt.n_end == 0); assert(serd_reader_read_chunk(reader) == SERD_FAILURE); - + serd_reader_end_stream(reader); serd_reader_free(reader); fclose(f); remove(path); @@ -316,24 +309,19 @@ test_read_turtle_chunks(const char* const path) fprintf(f, "eg:s eg:p1 eg:o1 ;\n"); fprintf(f, " eg:p2 eg:o2 .\n"); fwrite(&null, sizeof(null), 1, f); - fprintf(f, "eg:s eg:p [ eg:sp eg:so ] .\n"); - fwrite(&null, sizeof(null), 1, f); + fprintf(f, "eg:s eg:p [ eg:sp eg:so ] ."); fseek(f, 0, SEEK_SET); ReaderTest rt = {0, 0, 0, 0}; - SerdReader* const reader = serd_reader_new(SERD_TURTLE, - &rt, - NULL, - test_base_sink, - test_prefix_sink, - test_statement_sink, - test_end_sink); + SerdReader* const reader = serd_reader_new( + SERD_TURTLE, &rt, NULL, base_sink, prefix_sink, statement_sink, end_sink); assert(reader); assert(serd_reader_get_handle(reader) == &rt); assert(f); - SerdStatus st = serd_reader_start_stream(reader, f, NULL, false); + SerdStatus st = serd_reader_start_source_stream( + reader, (SerdSource)fread, (SerdStreamErrorFunc)ferror, f, NULL, 32U); assert(st == SERD_SUCCESS); // Read base @@ -393,7 +381,7 @@ test_read_turtle_chunks(const char* const path) assert(rt.n_end == 1); assert(serd_reader_read_chunk(reader) == SERD_FAILURE); - + serd_reader_end_stream(reader); serd_reader_free(reader); fclose(f); remove(path); @@ -428,7 +416,7 @@ main(void) test_read_turtle_chunks(path); test_read_string(); - test_read_eof_by_page(path); + test_read_eof_file(path); test_read_eof_by_byte(); assert(!remove(path)); diff --git a/test/test_reader_writer.c b/test/test_reader_writer.c index c229d1c5..515d5e5b 100644 --- a/test/test_reader_writer.c +++ b/test/test_reader_writer.c @@ -54,14 +54,14 @@ static const char* const doc_string = "( eg:o ) eg:t eg:u .\n"; static SerdStatus -test_statement_sink(void* handle, - SerdStatementFlags flags, - const SerdNode* graph, - const SerdNode* subject, - const SerdNode* predicate, - const SerdNode* object, - const SerdNode* object_datatype, - const SerdNode* object_lang) +test_statement_sink(void* const handle, + const SerdStatementFlags flags, + const SerdNode* const graph, + const SerdNode* const subject, + const SerdNode* const predicate, + const SerdNode* const object, + const SerdNode* const object_datatype, + const SerdNode* const object_lang) { (void)flags; (void)subject; @@ -164,8 +164,9 @@ test_writer(const char* const path) assert(serd_writer_end_anon(writer, NULL)); assert(serd_writer_get_env(writer) == env); - uint8_t buf[] = {0x80, 0, 0, 0, 0}; - SerdNode s = serd_node_from_string(SERD_URI, USTR("")); + const uint8_t buf[] = {0x80, 0, 0, 0, 0}; + + SerdNode s = serd_node_from_string(SERD_URI, USTR("")); SerdNode p = serd_node_from_string(SERD_URI, USTR("http://example.org/pred")); SerdNode o = serd_node_from_string(SERD_LITERAL, buf); @@ -264,7 +265,7 @@ test_writer(const char* const path) } static void -test_reader(const char* path) +test_reader(const char* const path) { ReaderTest* rt = (ReaderTest*)calloc(1, sizeof(ReaderTest)); SerdReader* reader = serd_reader_new( @@ -332,6 +333,5 @@ main(void) assert(!remove(path)); free(path); - printf("Success\n"); return 0; } diff --git a/test/test_stdin.py b/test/test_stdin.py index f976ca52..fb01f4ee 100755 --- a/test/test_stdin.py +++ b/test/test_stdin.py @@ -7,37 +7,14 @@ # pylint: disable=consider-using-f-string -import argparse -import sys -import shlex -import subprocess -import tempfile +import serd_test_util as util -parser = argparse.ArgumentParser(description=__doc__) +args = util.wrapper_args(__doc__) +command = [args.serdi, "-i", "ntriples", "-", "http://example.org"] -parser.add_argument("--serdi", default="./serdi", help="path to serdi") -parser.add_argument("--wrapper", default="", help="executable wrapper") +DOC = "<{0}s> <{0}p> <{0}o> .".format("http://example.org/") -args = parser.parse_args(sys.argv[1:]) -command = shlex.split(args.wrapper) + [args.serdi, "-"] +lines = util.command_output(args.wrapper, command, DOC).splitlines(True) -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 +assert len(lines) == 1 +assert lines[0].strip() == DOC diff --git a/test/test_string.c b/test/test_string.c index 23835ca9..1af3f45a 100644 --- a/test/test_string.c +++ b/test/test_string.c @@ -7,7 +7,6 @@ #include <assert.h> #include <stdint.h> -#include <stdio.h> #include <string.h> static void @@ -57,7 +56,5 @@ main(void) { test_strlen(); test_strerror(); - - printf("Success\n"); return 0; } diff --git a/test/test_uri.c b/test/test_uri.c index fc5eab71..7315a0fc 100644 --- a/test/test_uri.c +++ b/test/test_uri.c @@ -8,7 +8,6 @@ #include <assert.h> #include <stdbool.h> #include <stdint.h> -#include <stdio.h> #include <string.h> #define USTR(s) ((const uint8_t*)(s)) @@ -37,11 +36,11 @@ test_uri_string_has_scheme(void) } static void -test_file_uri(const char* const hostname, - const char* const path, - const bool escape, - const char* const expected_uri, - const char* expected_path) +check_file_uri(const char* const hostname, + const char* const path, + const bool escape, + const char* const expected_uri, + const char* expected_path) { if (!expected_path) { expected_path = path; @@ -112,62 +111,62 @@ test_uri_to_path(void) static void test_uri_parsing(void) { - test_file_uri(NULL, "C:/My 100%", true, "file:///C:/My%20100%%", NULL); - test_file_uri(NULL, "/foo/bar", true, "file:///foo/bar", NULL); - test_file_uri("bhost", "/foo/bar", true, "file://bhost/foo/bar", NULL); - test_file_uri(NULL, "a/relative path", false, "a/relative path", NULL); - test_file_uri( + check_file_uri(NULL, "C:/My 100%", true, "file:///C:/My%20100%%", NULL); + check_file_uri(NULL, "/foo/bar", true, "file:///foo/bar", NULL); + check_file_uri("bhost", "/foo/bar", true, "file://bhost/foo/bar", NULL); + check_file_uri(NULL, "a/relative path", false, "a/relative path", NULL); + check_file_uri( NULL, "a/relative <path>", true, "a/relative%20%3Cpath%3E", NULL); #ifdef _WIN32 - test_file_uri( + check_file_uri( NULL, "C:\\My 100%", true, "file:///C:/My%20100%%", "C:/My 100%"); - test_file_uri(NULL, - "\\drive\\relative", - true, - "file:///drive/relative", - "/drive/relative"); - - test_file_uri(NULL, - "C:\\Program Files\\Serd", - true, - "file:///C:/Program%20Files/Serd", - "C:/Program Files/Serd"); - - test_file_uri("ahost", - "C:\\Pointless Space", - true, - "file://ahost/C:/Pointless%20Space", - "C:/Pointless Space"); + check_file_uri(NULL, + "\\drive\\relative", + true, + "file:///drive/relative", + "/drive/relative"); + + check_file_uri(NULL, + "C:\\Program Files\\Serd", + true, + "file:///C:/Program%20Files/Serd", + "C:/Program Files/Serd"); + + check_file_uri("ahost", + "C:\\Pointless Space", + true, + "file://ahost/C:/Pointless%20Space", + "C:/Pointless Space"); #else /* What happens with Windows paths on other platforms is a bit weird, but more or less unavoidable. It doesn't work to interpret backslashes as path separators on any other platform. */ - test_file_uri("ahost", - "C:\\Pointless Space", - true, - "file://ahost/C:%5CPointless%20Space", - "/C:\\Pointless Space"); - - test_file_uri(NULL, - "\\drive\\relative", - true, - "%5Cdrive%5Crelative", - "\\drive\\relative"); - - test_file_uri(NULL, - "C:\\Program Files\\Serd", - true, - "file:///C:%5CProgram%20Files%5CSerd", - "/C:\\Program Files\\Serd"); - - test_file_uri("ahost", - "C:\\Pointless Space", - true, - "file://ahost/C:%5CPointless%20Space", - "/C:\\Pointless Space"); + check_file_uri("ahost", + "C:\\Pointless Space", + true, + "file://ahost/C:%5CPointless%20Space", + "/C:\\Pointless Space"); + + check_file_uri(NULL, + "\\drive\\relative", + true, + "%5Cdrive%5Crelative", + "\\drive\\relative"); + + check_file_uri(NULL, + "C:\\Program Files\\Serd", + true, + "file:///C:%5CProgram%20Files%5CSerd", + "/C:\\Program Files\\Serd"); + + check_file_uri("ahost", + "C:\\Pointless Space", + true, + "file://ahost/C:%5CPointless%20Space", + "/C:\\Pointless Space"); #endif // Test tolerance of NULL hostname parameter @@ -208,7 +207,7 @@ test_uri_from_string(void) } static inline bool -chunk_equals(const SerdChunk* a, const SerdChunk* b) +chunk_equals(const SerdChunk* const a, const SerdChunk* const b) { return (!a->len && !b->len && !a->buf && !b->buf) || (a->len && b->len && a->buf && b->buf && @@ -382,7 +381,5 @@ main(void) test_uri_parsing(); test_uri_from_string(); test_relative_uri(); - - printf("Success\n"); return 0; } diff --git a/test/test_write_error.py b/test/test_write_error.py index 35fde232..b62f981a 100755 --- a/test/test_write_error.py +++ b/test/test_write_error.py @@ -5,19 +5,14 @@ """Test errors writing to a file.""" -import argparse import sys import shlex import subprocess import os -parser = argparse.ArgumentParser(description=__doc__) +import serd_test_util as util -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:]) +args = util.wrapper_args(__doc__, True) command = shlex.split(args.wrapper) + [args.serdi, args.input] if os.path.exists("/dev/full"): diff --git a/test/test_writer.c b/test/test_writer.c index 6c765148..9e94e139 100644 --- a/test/test_writer.c +++ b/test/test_writer.c @@ -112,7 +112,6 @@ test_write_nested_anon(void) "\t\t<http://example.org/p4> <http://example.org/o4>\n" "\t] .\n"; - fprintf(stderr, "%s\n", out); assert(!strcmp((char*)out, expected)); serd_free(out); } |