aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/meson.build10
-rwxr-xr-xtest/test_empty.py25
-rw-r--r--test/test_writer.c33
3 files changed, 68 insertions, 0 deletions
diff --git a/test/meson.build b/test/meson.build
index 2ed73e63..97e082e0 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -16,6 +16,7 @@ simple_script_paths = [
'../scripts/check_formatting.py',
'serd_test_util/__init__.py',
'run_suite.py',
+ 'test_empty.py',
'test_quiet.py',
'test_stdin.py',
'test_write_error.py',
@@ -256,6 +257,15 @@ if is_variable('serdi')
suite: input_suite,
)
+ # Output
+
+ test(
+ 'empty',
+ files('test_empty.py'),
+ args: script_args + [serd_ttl],
+ env: test_env,
+ suite: 'output',
+ )
# IO errors
diff --git a/test/test_empty.py b/test/test_empty.py
new file mode 100755
index 00000000..3cd5517b
--- /dev/null
+++ b/test/test_empty.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+# Copyright 2022-2023 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: ISC
+
+"""Test writing empty output."""
+
+# pylint: disable=duplicate-code
+
+import shlex
+import subprocess
+import tempfile
+
+import serd_test_util as util
+
+args = util.wrapper_args(__doc__, True)
+command = shlex.split(args.wrapper) + [args.serdi, "-o", "empty", args.input]
+
+with tempfile.TemporaryFile() as out:
+ proc = subprocess.run(command, check=False, stdout=out)
+
+ out.seek(0, 2) # Seek to end
+
+ assert proc.returncode == 0
+ assert out.tell() == 0
diff --git a/test/test_writer.c b/test/test_writer.c
index 1334bb02..6066b6e3 100644
--- a/test/test_writer.c
+++ b/test/test_writer.c
@@ -293,6 +293,38 @@ test_writer_stack_overflow(void)
serd_world_free(world);
}
+static void
+test_write_empty_syntax(void)
+{
+ SerdWorld* world = serd_world_new();
+ SerdEnv* env = serd_env_new(serd_empty_string());
+
+ SerdNode* s = serd_new_uri(serd_string("http://example.org/s"));
+ SerdNode* p = serd_new_uri(serd_string("http://example.org/p"));
+ SerdNode* o = serd_new_curie(serd_string("eg:o"));
+
+ SerdBuffer buffer = {NULL, 0};
+
+ SerdWriter* writer = serd_writer_new(
+ world, SERD_SYNTAX_EMPTY, 0U, env, serd_buffer_sink, &buffer);
+
+ assert(writer);
+
+ assert(!serd_sink_write(serd_writer_sink(writer), 0U, s, p, o, NULL));
+
+ char* out = serd_buffer_sink_finish(&buffer);
+
+ assert(strlen(out) == 0);
+ serd_free(out);
+
+ serd_writer_free(writer);
+ serd_node_free(o);
+ serd_node_free(p);
+ serd_node_free(s);
+ serd_env_free(env);
+ serd_world_free(world);
+}
+
int
main(void)
{
@@ -303,6 +335,7 @@ main(void)
test_strict_write();
test_write_error();
test_writer_stack_overflow();
+ test_write_empty_syntax();
return 0;
}