From 3a99fe59cc2848ba797254b98f64de11a2c6f671 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Tue, 18 Oct 2022 19:21:11 +0300 Subject: [PATCH] Add test cases for opaque data generation. --- .../common/260 opaque/ersatz_doctool.py | 66 +++++++++++++++++++ test cases/common/260 opaque/meson.build | 8 +++ test cases/common/260 opaque/test.json | 6 ++ .../frameworks/14 doxygen/doc/doxyrunner.py | 14 ++-- 4 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 test cases/common/260 opaque/ersatz_doctool.py create mode 100644 test cases/common/260 opaque/meson.build create mode 100644 test cases/common/260 opaque/test.json diff --git a/test cases/common/260 opaque/ersatz_doctool.py b/test cases/common/260 opaque/ersatz_doctool.py new file mode 100644 index 000000000..69fdfb08e --- /dev/null +++ b/test cases/common/260 opaque/ersatz_doctool.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +import sys, os, subprocess, shutil +import pathlib + +from argparse import ArgumentParser + +# Argparse does not permit ignoring unknown args. +# Do it by hand. + +known_args = ['--out', + '--scratch', + '--stamp', + '--dep'] + +def is_known(arg): + for a in known_args: + if arg.startswith(a): + return True + return False + +parser = ArgumentParser(description='Helper tool to test opaque generation') + +parser.add_argument('--out', + required=True, help='Directory where to write final output.') +parser.add_argument('--scratch', + required=True, + help='Directory to use for temporary files.') +parser.add_argument('--stamp', required=True, + help='Path to stamp file.') +parser.add_argument('--dep', required=True, + help='Path to dependency file.') + +def run_doxygen(meson_args, extra_args): + if len(extra_args) != 1: + sys.exit('Incorrect number of input arguments.') + if extra_args[0] != '--foobar': + sys.exit(f'Input arg is incorrect: {extra_args[0]}') + known_args = [x for x in meson_args if is_known(x)] + meson_opts = parser.parse_args(known_args) + outdir = pathlib.Path(meson_opts.out) + outsub = outdir / 'subdir' + scratchdir = pathlib.Path(meson_opts.scratch) + if os.path.exists(meson_opts.stamp): + os.unlink(meson_opts.stamp) + if not scratchdir.is_dir(): + sys.exit('Meson did not create scratch dir.') + if not outdir.is_dir(): + sys.exit('Meson did not create out dir.') + with open(scratchdir / 'dummy_file', 'wb'): + pass + with open(outdir / 'out_top.txt', 'wb'): + pass + outsub.mkdir(exist_ok=True) + with open(outsub / 'out_subdir.txt', 'wb'): + pass + # Always touch the stamp file last after every other step has succeeded. + with open(meson_opts.stamp, 'w'): + pass + +if __name__ == '__main__': + for i in range(len(sys.argv)): + if sys.argv[i] == '--': + run_doxygen(sys.argv[1:i], sys.argv[i+1:]) + sys.exit(0) + sys.exit('Mandatory separator argument "--" missing.') diff --git a/test cases/common/260 opaque/meson.build b/test cases/common/260 opaque/meson.build new file mode 100644 index 000000000..129ff479a --- /dev/null +++ b/test cases/common/260 opaque/meson.build @@ -0,0 +1,8 @@ +project('opaque_gen', 'c') + +opaque_target('datagen', + command: [find_program('ersatz_doctool.py')], + args: ['--foobar'], + install: true, + install_dir: get_option('datadir') / 'doc' +) diff --git a/test cases/common/260 opaque/test.json b/test cases/common/260 opaque/test.json new file mode 100644 index 000000000..a07599e78 --- /dev/null +++ b/test cases/common/260 opaque/test.json @@ -0,0 +1,6 @@ +{ + "installed": [ + { "type": "file", "file": "usr/share/doc/out_top.txt" }, + { "type": "file", "file": "usr/share/doc/subdir/out_subdir.txt"} + ] +} diff --git a/test cases/frameworks/14 doxygen/doc/doxyrunner.py b/test cases/frameworks/14 doxygen/doc/doxyrunner.py index ec464be12..8b242ccc4 100755 --- a/test cases/frameworks/14 doxygen/doc/doxyrunner.py +++ b/test cases/frameworks/14 doxygen/doc/doxyrunner.py @@ -7,12 +7,12 @@ from argparse import ArgumentParser parser = ArgumentParser(description='Helper tool to integrate Doxygen with Meson') -parser.add_argument('--out', +parser.add_argument('--out', required=True, help='Directory where to write final output.') -parser.add_argument('--scratch', - required=True, +parser.add_argument('--scratch', + required=True, help='Directory to use for temporary files.') -parser.add_argument('--stamp', required=True, +parser.add_argument('--stamp', required=True, help='Path to stamp file.') parser.add_argument('--dep', required=True, help='Path to dependency file.') @@ -39,8 +39,8 @@ def run_doxygen(meson_opts, extra_args): shutil.copytree(html, outdir / 'html') if doxyrc != 0: sys.exit(doxyrc) - with open(meson_opts.dep, 'w') as stampfile: - stampfile.write(f'"{meson_opts.stamp}": \n') + with open(meson_opts.dep, 'w') as depfile: + depfile.write(f'"{meson_opts.stamp}": \n') # Always touch the stamp file last after every other step has succeeded. with open(meson_opts.stamp, 'w'): pass @@ -50,4 +50,4 @@ if __name__ == '__main__': if sys.argv[i] == '--': run_doxygen(parser.parse_args(sys.argv[1:i]), sys.argv[i+1:]) sys.exit(0) - sys.exit('Mandatory separator argument "--" missing.') \ No newline at end of file + sys.exit('Mandatory separator argument "--" missing.')