[PATCH wayland-protocols 2/3] tests: Add compile tests
Jonas Ådahl
jadahl at gmail.com
Wed Oct 11 09:00:12 UTC 2017
Only tested by the meson build system.
Signed-off-by: Jonas Ådahl <jadahl at gmail.com>
---
tests/build-cxx.cc.in | 12 +++++++
tests/build-pedantic.c.in | 10 ++++++
tests/meson.build | 86 +++++++++++++++++++++++++++++++++++++++++++++++
tests/replace.py | 23 +++++++++++++
4 files changed, 131 insertions(+)
create mode 100644 tests/build-cxx.cc.in
create mode 100644 tests/build-pedantic.c.in
create mode 100755 tests/replace.py
diff --git a/tests/build-cxx.cc.in b/tests/build-cxx.cc.in
new file mode 100644
index 0000000..e92b155
--- /dev/null
+++ b/tests/build-cxx.cc.in
@@ -0,0 +1,12 @@
+#include "@PROTOCOL_CLIENT_INCLUDE_FILE@"
+#include "@PROTOCOL_SERVER_INCLUDE_FILE@"
+
+/* This is a build-test only */
+
+using namespace std;
+
+int
+main(int argc, char **argv)
+{
+ return 0;
+}
diff --git a/tests/build-pedantic.c.in b/tests/build-pedantic.c.in
new file mode 100644
index 0000000..51dfeac
--- /dev/null
+++ b/tests/build-pedantic.c.in
@@ -0,0 +1,10 @@
+#include "@PROTOCOL_CLIENT_INCLUDE_FILE@"
+#include "@PROTOCOL_SERVER_INCLUDE_FILE@"
+
+/* This is a build-test only */
+
+int
+main(int argc, char **argv)
+{
+ return 0;
+}
diff --git a/tests/meson.build b/tests/meson.build
index 267a36a..8113ab9 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -1,5 +1,7 @@
scan_sh = find_program('scan.sh')
wayland_scanner = find_program('wayland-scanner')
+libwayland = [dependency('wayland-client'),
+ dependency('wayland-server')]
# Check that each protocol passes through the scanner
foreach protocol : protocols
@@ -11,3 +13,87 @@ foreach protocol : protocols
'SCANNER=@0@'.format(wayland_scanner.path()),
])
endforeach
+
+# Check buildability
+
+add_languages('c', 'cpp')
+replace = find_program('replace.py')
+
+foreach protocol : protocols
+ protocol_path = join_paths(meson.source_root(), protocol)
+ protocol_components = protocol.split('/')
+ stability = protocol_components[0]
+ protocol_name = protocol_components[1]
+ xml_file = protocol_components[2]
+ xml_components = xml_file.split('.')
+ protocol_base_file_name = xml_components[0]
+
+ protocol_path = join_paths(meson.source_root(), protocol)
+ client_header_path = '@0 at -client.h'.format(protocol_base_file_name)
+ server_header_path = '@0 at -server.h'.format(protocol_base_file_name)
+ code_path = '@0 at -code.c'.format(protocol_base_file_name)
+ client_header = custom_target(client_header_path,
+ output: client_header_path,
+ input: protocol_path,
+ command: [ wayland_scanner, 'client-header',
+ '@INPUT@', '@OUTPUT@' ],
+ install: false)
+ server_header = custom_target(server_header_path,
+ output: server_header_path,
+ input: protocol_path,
+ command: [ wayland_scanner, 'server-header',
+ '@INPUT@', '@OUTPUT@' ],
+ install: false)
+ code = custom_target(code_path,
+ output: code_path,
+ input: protocol_path,
+ command: [ wayland_scanner, 'code',
+ '@INPUT@', '@OUTPUT@' ],
+ install: false)
+
+ replace_command = [ replace, '@INPUT@', '@OUTPUT@',
+ 'PROTOCOL_CLIENT_INCLUDE_FILE', client_header.full_path(),
+ 'PROTOCOL_SERVER_INCLUDE_FILE', server_header.full_path(),
+ ]
+
+ # Check that header can be included by a pedantic C99 compiler
+ test_name = 'test-build-pedantic- at 0@'.format(protocol.underscorify())
+ test_name_source = '@0 at .c'.format(test_name)
+ test_source = custom_target(test_name_source,
+ input: 'build-pedantic.c.in',
+ output: test_name_source,
+ command: replace_command)
+ pedantic_test_executable = executable(test_name,
+ [ test_source,
+ client_header,
+ server_header,
+ code ],
+ dependencies: libwayland,
+ c_args: [ '-std=c99',
+ '-pedantic',
+ '-Wall',
+ '-Werror' ],
+ install: false)
+ test(test_name, pedantic_test_executable)
+
+ # Check that the header
+ if not protocol.contains('xdg-foreign-unstable-v1')
+ test_name = 'test-build-cxx- at 0@'.format(protocol.underscorify())
+ test_name_source = '@0 at .cc'.format(test_name)
+ test_configuration = configuration_data()
+ test_configuration.set('PROTOCOL_CLIENT_INCLUDE_FILE', '@0@'.format(client_header.full_path()))
+ test_configuration.set('PROTOCOL_SERVER_INCLUDE_FILE', '@0@'.format(server_header.full_path()))
+ test_source = custom_target(test_name_source,
+ input: 'build-cxx.cc.in',
+ output: test_name_source,
+ command: replace_command)
+ cxx_test_executable = executable(test_name,
+ [ test_source,
+ client_header,
+ server_header ],
+ cpp_args: [ '-Wall',
+ '-Werror' ],
+ install: false)
+ test(test_name, cxx_test_executable)
+ endif
+endforeach
diff --git a/tests/replace.py b/tests/replace.py
new file mode 100755
index 0000000..8a8a18e
--- /dev/null
+++ b/tests/replace.py
@@ -0,0 +1,23 @@
+#!/usr/bin/python3
+
+import sys
+
+execpath, inpath, outpath, *dict_list = sys.argv
+
+dictonary = {}
+while dict_list:
+ key, value, *rest = dict_list
+ dictonary[key] = value
+ dict_list = rest
+
+infile = open(inpath, 'r')
+outfile = open(outpath, 'w')
+
+buf = infile.read()
+infile.close()
+
+for key, value in dictonary.items():
+ buf = buf.replace('@{}@'.format(key), value)
+
+outfile.write(buf)
+outfile.close()
--
2.13.5
More information about the wayland-devel
mailing list