aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-10-09 13:44:31 -0400
committerDavid Robillard <d@drobilla.net>2022-01-28 21:57:07 -0500
commitcbf01be4126cbc0f6d80364a7e0b6ad777a7d8ae (patch)
tree20cd2919e0d4c47caa346123c5701daa70a05ac3 /test
parent5ea7c0d763685c23dc6933e273dfa11eec5bec14 (diff)
downloadserd-cbf01be4126cbc0f6d80364a7e0b6ad777a7d8ae.tar.gz
serd-cbf01be4126cbc0f6d80364a7e0b6ad777a7d8ae.tar.bz2
serd-cbf01be4126cbc0f6d80364a7e0b6ad777a7d8ae.zip
Fix handling of deferred write errors that happen when closing
Diffstat (limited to 'test')
-rw-r--r--test/meson.build6
-rw-r--r--test/test_deferred_write_error.py31
-rw-r--r--test/test_model.c4
-rw-r--r--test/test_writer.c15
4 files changed, 48 insertions, 8 deletions
diff --git a/test/meson.build b/test/meson.build
index ae66ba37..a25ac6de 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -52,6 +52,7 @@ if autoship.found()
endif
serd_ttl = files('../serd.ttl')[0]
+small_ttl = files('../test/TurtleTests/turtle-syntax-number-01.ttl')[0]
common_script_options = []
if wrapper != ''
common_script_options = ['--wrapper', wrapper]
@@ -230,6 +231,11 @@ if is_variable('serd_pipe')
env: test_env,
suite: ['tools', 'pipe', 'output'])
+ test('deferred_write_error', files('test_deferred_write_error.py'),
+ args: pipe_test_script_args + [small_ttl],
+ env: test_env,
+ suite: ['tools', 'pipe', 'output'])
+
test('missing_output',
tool,
args: ['-o', '/does/not/exist.ttl', meson.source_root() / 'serd.ttl'],
diff --git a/test/test_deferred_write_error.py b/test/test_deferred_write_error.py
new file mode 100644
index 00000000..4005d570
--- /dev/null
+++ b/test/test_deferred_write_error.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python3
+
+"""Test errors that only really happen when the output file is closed."""
+
+import argparse
+import sys
+import shlex
+import subprocess
+import os
+
+parser = argparse.ArgumentParser(description=__doc__)
+
+parser.add_argument("--tool", default="tools/serd-pipe", help="executable")
+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.tool, '-b', '1024', 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")
diff --git a/test/test_model.c b/test/test_model.c
index 3e781c7e..a64a7b7e 100644
--- a/test/test_model.c
+++ b/test/test_model.c
@@ -1281,7 +1281,7 @@ test_write_error_in_list_subject(SerdWorld* world, const unsigned n_quads)
for (size_t max_successes = 0; max_successes < 18; ++max_successes) {
FailingWriteFuncState state = {0, max_successes};
SerdOutputStream out =
- serd_open_output_stream(failing_write_func, NULL, &state);
+ serd_open_output_stream(failing_write_func, NULL, NULL, &state);
SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0, env, &out, 1);
@@ -1337,7 +1337,7 @@ test_write_error_in_list_object(SerdWorld* world, const unsigned n_quads)
for (size_t max_successes = 0; max_successes < 21; ++max_successes) {
FailingWriteFuncState state = {0, max_successes};
SerdOutputStream out =
- serd_open_output_stream(failing_write_func, NULL, &state);
+ serd_open_output_stream(failing_write_func, NULL, NULL, &state);
SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0, env, &out, 1);
diff --git a/test/test_writer.c b/test/test_writer.c
index c719642f..6ffe5d0f 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -126,10 +126,12 @@ null_sink(const void* const buf,
static void
test_writer_stack_overflow(void)
{
- SerdWorld* world = serd_world_new();
- SerdNodes* nodes = serd_world_nodes(world);
- SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
- SerdOutputStream output = serd_open_output_stream(null_sink, NULL, NULL);
+ SerdWorld* world = serd_world_new();
+ SerdNodes* nodes = serd_world_nodes(world);
+ SerdEnv* env = serd_env_new(SERD_EMPTY_STRING());
+
+ SerdOutputStream output =
+ serd_open_output_stream(null_sink, NULL, NULL, NULL);
SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0u, env, &output, 1);
@@ -244,7 +246,8 @@ test_write_error(void)
// Test with setting errno
- SerdOutputStream output = serd_open_output_stream(faulty_sink, NULL, NULL);
+ SerdOutputStream output =
+ serd_open_output_stream(faulty_sink, NULL, NULL, NULL);
SerdWriter* writer = serd_writer_new(world, SERD_TURTLE, 0u, env, &output, 1);
assert(writer);
@@ -256,7 +259,7 @@ test_write_error(void)
serd_close_output(&output);
// Test without setting errno
- output = serd_open_output_stream(faulty_sink, NULL, world);
+ output = serd_open_output_stream(faulty_sink, NULL, NULL, world);
writer = serd_writer_new(world, SERD_TURTLE, 0u, env, &output, 1);
assert(writer);