├── .clang-format ├── .cmake-format.yaml ├── .codecov.yml ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ ├── cron_comment_template.md │ ├── cron_comment_template.md.license │ ├── release-checklist.md │ └── release-checklist.md.license ├── config │ ├── codechecker.skip │ └── codechecker.yml ├── dependabot.yml └── workflows │ ├── ci_cmake.yml │ ├── ci_coverage.yml │ ├── ci_documentation.yml │ ├── ci_license.yml │ ├── ci_lint.yml │ ├── ci_linux.yml │ ├── ci_macos.yml │ ├── ci_misc.yml │ ├── cron_api.yml │ ├── cron_codechecker.yml │ ├── cron_codeql.yml │ ├── cron_cpm.yml │ ├── readme_snippet.yml │ ├── scripts │ └── process_compiler_error_log.py │ └── update_cookbook.yml ├── .gitignore ├── .gitpod.yml ├── CHANGELOG.md ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.md ├── LICENSES ├── BSD-3-Clause.txt ├── CC-BY-4.0.txt ├── CC0-1.0.txt └── MIT.txt ├── README.md ├── cmake ├── CPM.cmake ├── cpack_install.cmake.in ├── package-lock.cmake ├── sharg-config-version.cmake ├── sharg-config.cmake ├── sharg-install.cmake └── sharg-package.cmake ├── doc ├── about │ ├── api │ │ └── index.md │ ├── copyright │ │ ├── bsdl_badge.svg │ │ ├── bsdl_badge.svg.license │ │ ├── cc0_badge.svg │ │ ├── cc0_badge.svg.license │ │ ├── ccby_badge.svg │ │ ├── ccby_badge.svg.license │ │ ├── copyfree_badge.svg │ │ └── copyfree_badge.svg.license │ ├── customisation │ │ └── index.md │ └── update_notifications │ │ └── index.md ├── cookbook │ ├── basic_arg_parse.cpp │ ├── basic_arg_parse.out │ ├── basic_arg_parse.out.license │ └── index.md ├── howto │ ├── custom_types │ │ ├── custom_type.cpp │ │ ├── custom_type.out │ │ ├── custom_type.out.license │ │ ├── external_custom_type.cpp │ │ ├── external_custom_type.out │ │ ├── external_custom_type.out.license │ │ └── index.md │ ├── custom_validator │ │ ├── custom_validator_solution1.cpp │ │ └── index.md │ └── subcommand_parser │ │ ├── index.md │ │ ├── subcommand_parse.cpp │ │ ├── subcommand_parse.out │ │ └── subcommand_parse.out.license ├── main_page.md ├── setup │ ├── library_tests │ │ └── index.md │ └── quickstart_cmake │ │ └── index.md └── tutorial │ ├── concepts │ ├── custom_validator_solution.cpp │ ├── custom_validator_solution.out │ └── custom_validator_solution.out.license │ └── parser │ ├── basic_parser_setup.cpp │ ├── basic_parser_setup.out │ ├── basic_parser_setup.out.license │ ├── data.tsv │ ├── data.tsv.license │ ├── disable_version_check.cpp │ ├── index.md │ ├── small_snippets.cpp │ ├── solution1.cpp │ ├── solution3.cpp │ ├── solution3.out │ ├── solution3.out.license │ ├── solution4.cpp │ ├── solution4.out │ ├── solution4.out.license │ ├── solution5.cpp │ ├── solution5.out │ ├── solution5.out.license │ ├── solution6.cpp │ ├── solution6.out │ └── solution6.out.license ├── include └── sharg │ ├── all.hpp │ ├── auxiliary.hpp │ ├── concept.hpp │ ├── config.hpp │ ├── detail │ ├── concept.hpp │ ├── format_base.hpp │ ├── format_help.hpp │ ├── format_html.hpp │ ├── format_man.hpp │ ├── format_parse.hpp │ ├── format_tdl.hpp │ ├── id_pair.hpp │ ├── safe_filesystem_entry.hpp │ ├── terminal.hpp │ ├── test_accessor.hpp │ ├── to_string.hpp │ ├── type_name_as_string.hpp │ └── version_check.hpp │ ├── enumeration_names.hpp │ ├── exceptions.hpp │ ├── parser.hpp │ ├── platform.hpp │ ├── std │ └── charconv │ ├── validators.hpp │ └── version.hpp └── test ├── analyse └── CMakeLists.txt ├── api_stability ├── 1.0.0 │ ├── 0001-API-FIX-Print-common-options-at-the-end-of-the-help-.patch │ ├── 0002-NOAPI-Update-copyright.patch │ ├── 0003-API-FIX-Check-app_name-at-parse.patch │ └── 0004-FIX-API-tdl-support.patch ├── 1.1.1 │ ├── 0001-API-Update-TDL.patch │ ├── 0002-API-Quoted-strings-and-paths.patch │ ├── 0003-NOAPI-Update-copyright.patch │ ├── 0004-INFRA-Update-TDL.patch │ ├── 0005-INFRA-Use-seqan3-main-branch.patch │ ├── 0006-API-FIX-positional-options-in-CWL-CTD.patch │ ├── 0007-API-MISC-Defer-everything-to-parse.patch │ ├── 0008-API-MISC-Allow-options-for-subcommands.patch │ └── 0009-FIX-is_option_set-match-both-long-and-short-ids.patch ├── CMakeLists.txt ├── README.md └── REUSE.toml ├── cmake ├── add_subdirectories.cmake ├── diagnostics │ ├── list_missing_unit_tests.cmake │ ├── list_unused_snippets.cmake │ └── list_unused_unit_tests.cmake ├── include_dependencies │ ├── add_include_dependencies.cmake │ └── generate_include_dependencies.cmake ├── sharg_generate_snippet.cmake ├── sharg_path_longest_stem.cmake ├── sharg_require_ccache.cmake ├── sharg_test_component.cmake └── sharg_test_files.cmake ├── coverage └── CMakeLists.txt ├── documentation ├── CMakeLists.txt ├── DoxygenLayout.xml.in ├── README.md ├── api-stability.js ├── doc_dev │ └── CMakeLists.txt ├── doc_usr │ └── CMakeLists.txt ├── sharg-doxygen-package.cmake ├── sharg-doxygen.cmake ├── sharg.css ├── sharg_doxygen_cfg.in ├── sharg_footer.html.in ├── sharg_header.html ├── sharg_logo.svg ├── sharg_logo.svg.license ├── version.js └── version.php ├── external_project ├── CMakeLists.txt ├── find-package-diagnostics.cmake ├── install-sharg.cmake ├── sharg_fetch_content_zip │ └── CMakeLists.txt ├── sharg_installed │ └── CMakeLists.txt ├── sharg_setup_tutorial │ └── CMakeLists.txt ├── sharg_submodule_add_subdirectory │ └── CMakeLists.txt ├── sharg_submodule_find_package │ └── CMakeLists.txt └── src │ └── hello_world.cpp ├── header ├── CMakeLists.txt └── generate_header_source.cmake ├── include └── sharg │ └── test │ ├── expect_throw_msg.hpp │ ├── file_access.hpp │ ├── test_fixture.hpp │ └── tmp_filename.hpp ├── scripts ├── add_snippets_to_cookbook.sh ├── check_markdown_doxygen.sh ├── link_check.sh └── update_copyright.sh ├── sharg-test.cmake ├── snippet ├── CMakeLists.txt ├── add_subcommands.cpp ├── add_subcommands.out ├── add_subcommands.out.license ├── auxiliary.cpp ├── compare_snippet_output.cmake ├── custom_enumeration.cpp ├── custom_enumeration.out ├── custom_enumeration.out.license ├── custom_parsing_enumeration.cpp ├── custom_parsing_enumeration.out ├── custom_parsing_enumeration.out.license ├── is_option_set.cpp ├── is_option_set.out ├── is_option_set.out.license ├── parser_1.cpp ├── parser_1.out ├── parser_1.out.license ├── parser_2.cpp ├── parser_2.out ├── parser_2.out.license ├── parser_3.cpp ├── parser_3.out ├── parser_3.out.license ├── readme_sneak_peek.cpp ├── readme_sneak_peek.out ├── readme_sneak_peek.out.license ├── safe_filesystem_entry.cpp ├── snippet_main.cpp ├── validators_1.cpp ├── validators_1.out ├── validators_1.out.license ├── validators_2.cpp ├── validators_2.out ├── validators_2.out.license ├── validators_3.cpp ├── validators_3.out ├── validators_3.out.license ├── validators_4.cpp ├── validators_4.out ├── validators_4.out.license ├── validators_chaining.cpp ├── validators_chaining.out ├── validators_chaining.out.license ├── validators_input_directory.cpp ├── validators_input_directory.out ├── validators_input_directory.out.license ├── validators_input_file.cpp ├── validators_input_file.out ├── validators_input_file.out.license ├── validators_input_file_ext_from_file.cpp ├── validators_input_file_ext_from_file.err ├── validators_input_file_ext_from_file.err.license ├── validators_output_directory.cpp ├── validators_output_directory.out ├── validators_output_directory.out.license ├── validators_output_file.cpp ├── validators_output_file.out ├── validators_output_file.out.license ├── validators_output_file_ext_from_file.cpp ├── validators_output_file_ext_from_file.err └── validators_output_file_ext_from_file.err.license └── unit ├── CMakeLists.txt ├── README.md ├── detail ├── CMakeLists.txt ├── format_ctd_test.cpp ├── format_cwl_test.cpp ├── format_help_test.cpp ├── format_html_test.cpp ├── format_man_test.cpp ├── safe_filesystem_entry_test.cpp ├── seqan3_test.cpp ├── type_name_as_string_test.cpp ├── version_check_debug_test.cpp ├── version_check_release_test.cpp └── version_check_test.hpp ├── parser ├── CMakeLists.txt ├── enumeration_names_test.cpp ├── format_parse_test.cpp ├── format_parse_validators_test.cpp ├── parser_design_error_test.cpp └── subcommand_test.cpp ├── std ├── CMakeLists.txt ├── charconv_float_test.cpp └── charconv_int_test.cpp └── test ├── CMakeLists.txt ├── file_access_test.cpp └── tmp_filename_test.cpp /.codecov.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | # See https://docs.codecov.io/docs/codecovyml-reference 6 | codecov: 7 | require_ci_to_pass: no # codecov reports its results independent of whether CI passed 8 | notify: 9 | wait_for_ci: no # codecov has not to wait until the CI is finished to post its results 10 | 11 | coverage: 12 | status: 13 | project: # project is the overall code coverage of the whole codebase 14 | default: 15 | if_ci_failed: success # per default, codecov would fail if any CI fails 16 | informational: true # the codecov/patch status is never "fail" 17 | patch: # patch is the code-coverage of the changed lines in the PR and often reports false positives 18 | default: 19 | if_ci_failed: success # per default, codecov would fail if any CI fails 20 | informational: true # the codecov/patch status is never "fail" 21 | only_pulls: true # only post codecov/patch status on PRs 22 | 23 | parsers: 24 | cobertura: 25 | partials_as_hits: true 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: 🐞 Bug report 6 | description: Create a report to help us improve Sharg. 7 | labels: [bug] 8 | body: 9 | - type: checkboxes 10 | attributes: 11 | label: Does this problem persist on the current main? 12 | description: Update to the latest main branch of Sharg and see if the issue persists. 13 | options: 14 | - label: I have verified the issue on the current main 15 | required: true 16 | - type: checkboxes 17 | attributes: 18 | label: Is there an existing issue for this? 19 | description: Please search to see if an issue already exists for the bug you encountered. 20 | options: 21 | - label: I have searched the existing issues 22 | required: true 23 | - type: textarea 24 | attributes: 25 | label: Current Behavior 26 | description: A concise description of what you're experiencing. 27 | validations: 28 | required: false 29 | - type: textarea 30 | attributes: 31 | label: Expected Behavior 32 | description: A concise description of what you expected to happen. 33 | validations: 34 | required: false 35 | - type: textarea 36 | attributes: 37 | label: Steps To Reproduce 38 | description: Steps to reproduce the behavior. 39 | placeholder: | 40 | 1. In this environment... 41 | 2. With this config... 42 | 3. Run '...' 43 | 4. See error... 44 | validations: 45 | required: false 46 | - type: textarea 47 | attributes: 48 | label: Environment 49 | description: | 50 | examples: 51 | - **Operating system**: Ubuntu 20.04 52 | - **Sharg version**: 0.1.0 53 | - **Compiler**: gcc 11.2 54 | value: | 55 | - Operating system: 56 | - Sharg version: 57 | - Compiler: 58 | render: markdown 59 | validations: 60 | required: false 61 | - type: textarea 62 | attributes: 63 | label: Anything else? 64 | description: | 65 | Links? References? Anything that will give us more context about the issue you are encountering! 66 | 67 | Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in. 68 | validations: 69 | required: false 70 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | blank_issues_enabled: true 6 | contact_links: 7 | - name: Questions and Answers 8 | url: https://github.com/seqan/sharg-parser/discussions 9 | about: Ask us about installing and using Sharg in our discussions forum! 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/cron_comment_template.md: -------------------------------------------------------------------------------- 1 | Failure {{ build }} on gcc{{ compiler }} 2 | --- 3 | 4 | See {{ url }} for more information. 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/cron_comment_template.md.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/release-checklist.md.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /.github/config/codechecker.skip: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2025, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2025, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | +${GITHUB_WORKSPACE}/* 6 | -* 7 | -------------------------------------------------------------------------------- /.github/config/codechecker.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2025, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2025, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | analyze: 6 | - --enable=performance 7 | - --enable=bugprone 8 | - --enable=prefix:clang-diagnostic-shadow 9 | - --disable=bugprone-easily-swappable-parameters 10 | - --disable=cert-dcl58-cpp 11 | - --disable=clang-diagnostic-implicit-int-float-conversion 12 | - --disable=clang-diagnostic-float-conversion 13 | - --disable=clang-diagnostic-implicit-int-conversion 14 | - --disable=bugprone-exception-escape 15 | - --disable=bugprone-narrowing-conversions 16 | - --disable=deadcode.DeadStores 17 | - --skip=${GITHUB_WORKSPACE}/.github/config/codechecker.skip 18 | - --clean 19 | 20 | parse: 21 | - --export=html 22 | - --output=./html 23 | - --skip=${GITHUB_WORKSPACE}/.github/config/codechecker.skip 24 | - --trim-path-prefix=${GITHUB_WORKSPACE}/ 25 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 6 | 7 | version: 2 8 | updates: 9 | 10 | - package-ecosystem: "github-actions" 11 | directory: "/" 12 | schedule: 13 | interval: "weekly" 14 | -------------------------------------------------------------------------------- /.github/workflows/ci_cmake.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: CMake 6 | 7 | on: 8 | push: 9 | branches: 10 | - 'main' 11 | pull_request: 12 | types: 13 | - unlabeled 14 | workflow_dispatch: 15 | 16 | concurrency: 17 | group: cmake-${{ github.event.pull_request.number || github.ref }} 18 | cancel-in-progress: ${{ github.event_name != 'push' }} 19 | 20 | env: 21 | SHARG_NO_VERSION_CHECK: 1 22 | TZ: Europe/Berlin 23 | 24 | defaults: 25 | run: 26 | shell: bash -Eexuo pipefail {0} 27 | 28 | jobs: 29 | build: 30 | name: "External project ${{ contains(matrix.SHARG_NO_TDL, 'OFF') && 'with TDL' || 'without TDL' }}" 31 | runs-on: ubuntu-latest 32 | if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' || github.event.label.name == 'lint' 33 | strategy: 34 | fail-fast: false 35 | matrix: 36 | SHARG_NO_TDL: [ON, OFF] 37 | container: 38 | image: ghcr.io/seqan/gcc-latest 39 | steps: 40 | - name: Checkout 41 | uses: actions/checkout@v4 42 | with: 43 | submodules: true 44 | 45 | - name: Install dependencies 46 | if: matrix.SHARG_NO_TDL == 'OFF' 47 | run: | 48 | git clone --depth 1 --single-branch --branch master https://github.com/jbeder/yaml-cpp.git 49 | cd yaml-cpp && mkdir build && cd build 50 | cmake ../ -DCMAKE_BUILD_TYPE=Debug \ 51 | -DYAML_CPP_BUILD_CONTRIB=OFF \ 52 | -DYAML_CPP_BUILD_TOOLS=OFF \ 53 | -DYAML_BUILD_SHARED_LIBS=OFF \ 54 | -DYAML_CPP_INSTALL=ON \ 55 | -DYAML_CPP_BUILD_TESTS=OFF 56 | make install 57 | 58 | - name: Configure tests 59 | run: | 60 | mkdir build && cd build 61 | cmake ../test/external_project -DCMAKE_BUILD_TYPE=Debug \ 62 | -DSHARG_NO_TDL=${{ matrix.SHARG_NO_TDL }} 63 | make -k sharg_test_prerequisite 64 | 65 | - name: Build tests 66 | working-directory: build 67 | run: make -k 68 | -------------------------------------------------------------------------------- /.github/workflows/ci_coverage.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: Coverage 6 | 7 | on: 8 | push: 9 | branches: 10 | - 'main' 11 | pull_request: 12 | types: 13 | - unlabeled 14 | workflow_dispatch: 15 | 16 | concurrency: 17 | group: coverage-${{ github.event.pull_request.number || github.ref }} 18 | cancel-in-progress: false 19 | 20 | env: 21 | SHARG_NO_VERSION_CHECK: 1 22 | TZ: Europe/Berlin 23 | 24 | defaults: 25 | run: 26 | shell: bash -Eexuo pipefail {0} 27 | 28 | jobs: 29 | build: 30 | runs-on: ubuntu-latest 31 | name: ${{ matrix.compiler }} 32 | if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' || github.event.label.name == 'lint' 33 | strategy: 34 | fail-fast: false 35 | matrix: 36 | compiler: ["gcc-latest"] 37 | container: 38 | image: ghcr.io/seqan/${{ matrix.compiler }} 39 | steps: 40 | - name: Checkout 41 | uses: actions/checkout@v4 42 | with: 43 | fetch-depth: 0 44 | 45 | - name: Setup cache 46 | uses: seqan/actions/setup-actions-cache@main 47 | 48 | - name: Increase ccache size 49 | run: echo "CCACHE_MAXSIZE=300M" >> "${GITHUB_ENV}" 50 | 51 | - name: Configure tests 52 | run: | 53 | mkdir build && cd build 54 | cmake ../test/coverage -DCMAKE_BUILD_TYPE=Coverage 55 | make gtest_main yaml-cpp 56 | 57 | - name: Build tests 58 | working-directory: build 59 | run: | 60 | ccache -z 61 | make -k 62 | ccache -svvx 63 | 64 | - name: Run tests 65 | working-directory: build 66 | run: ctest . -j --output-on-failure --no-tests=error 67 | 68 | - name: Generate coverage report 69 | run: | 70 | gcovr --root ${GITHUB_WORKSPACE}/test/coverage \ 71 | ${GITHUB_WORKSPACE}/build \ 72 | --filter ${GITHUB_WORKSPACE}/include/sharg \ 73 | --filter ${GITHUB_WORKSPACE}/test/include/sharg/test \ 74 | --exclude ${GITHUB_WORKSPACE}/include/sharg/contrib \ 75 | --exclude ${GITHUB_WORKSPACE}/include/sharg/std \ 76 | --exclude-lines-by-pattern '^\s*}|^\s*};' \ 77 | --exclude-noncode-lines \ 78 | --exclude-throw-branches \ 79 | --exclude-unreachable-branches \ 80 | --merge-mode-functions separate \ 81 | -j \ 82 | --cobertura \ 83 | --output ${GITHUB_WORKSPACE}/build/coverage_report.xml 84 | 85 | - name: Submit coverage build 86 | uses: codecov/codecov-action@v5.4.3 87 | with: 88 | disable_search: true 89 | fail_ci_if_error: false 90 | files: build/coverage_report.xml 91 | plugins: noop 92 | token: ${{ secrets.CODECOV_TOKEN }} 93 | -------------------------------------------------------------------------------- /.github/workflows/ci_license.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: License 6 | 7 | on: 8 | push: 9 | branches: 10 | - 'main' 11 | pull_request: 12 | types: 13 | - unlabeled 14 | workflow_dispatch: 15 | 16 | concurrency: 17 | group: license-${{ github.event.pull_request.number || github.ref }} 18 | cancel-in-progress: ${{ github.event_name != 'push' }} 19 | 20 | env: 21 | TZ: Europe/Berlin 22 | 23 | defaults: 24 | run: 25 | shell: bash -Eexuo pipefail {0} 26 | 27 | jobs: 28 | check: 29 | name: REUSE Compliance 30 | runs-on: ubuntu-latest 31 | timeout-minutes: 120 32 | if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' || github.event.label.name == 'lint' 33 | steps: 34 | - name: Checkout 35 | uses: actions/checkout@v4 36 | 37 | - name: REUSE Compliance Check 38 | uses: fsfe/reuse-action@v5 39 | 40 | - name: Check Markdown files for doxygen 41 | run: ${{ github.workspace }}/test/scripts/check_markdown_doxygen.sh ${{ github.workspace }} 42 | -------------------------------------------------------------------------------- /.github/workflows/ci_lint.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: Lint 6 | 7 | on: 8 | pull_request_target: 9 | 10 | env: 11 | TZ: Europe/Berlin 12 | 13 | defaults: 14 | run: 15 | shell: bash -Eeuxo pipefail {0} 16 | 17 | jobs: 18 | # Cancel other workflows that are dependent on this workflow by adding jobs that have the same concurrency group. 19 | cancel_running_workflows: 20 | name: Cancel ${{ matrix.workflow}} 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | workflow: ["linux", "macos", "coverage", "misc", "documentation", "cmake"] 25 | concurrency: 26 | group: ${{ matrix.workflow }}-${{ github.event.pull_request.number }} 27 | cancel-in-progress: true 28 | runs-on: ubuntu-latest 29 | steps: 30 | - name: "Cancel ${{ matrix.workflow }}" 31 | run: echo "Cancelling ${{ matrix.workflow }}" 32 | lint: 33 | name: Lint 34 | concurrency: 35 | group: lint-${{ github.event.pull_request.number }} 36 | cancel-in-progress: true 37 | needs: cancel_running_workflows 38 | runs-on: ubuntu-latest 39 | timeout-minutes: 15 40 | steps: 41 | - name: Run lint 42 | uses: seqan/actions/lint@main 43 | with: 44 | clang_format: 15 45 | token: ${{ secrets.SEQAN_ACTIONS_PAT }} 46 | gpg_key: ${{ secrets.SEQAN_ACTIONS_GPG_KEY }} 47 | gpg_passphrase: ${{ secrets.SEQAN_ACTIONS_GPG_PASSPHRASE }} 48 | -------------------------------------------------------------------------------- /.github/workflows/ci_linux.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: Linux 6 | 7 | on: 8 | push: 9 | branches: 10 | - 'main' 11 | pull_request: 12 | types: 13 | - unlabeled 14 | workflow_dispatch: 15 | 16 | concurrency: 17 | group: linux-${{ github.event.pull_request.number || github.ref }} 18 | cancel-in-progress: ${{ github.event_name != 'push' }} 19 | 20 | env: 21 | SHARG_NO_VERSION_CHECK: 1 22 | TZ: Europe/Berlin 23 | 24 | defaults: 25 | run: 26 | shell: bash -Eeuxo pipefail {0} 27 | 28 | jobs: 29 | build: 30 | runs-on: ubuntu-latest 31 | name: ${{ matrix.compiler }}${{ matrix.name_append }} 32 | if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' || github.event.label.name == 'lint' 33 | strategy: 34 | fail-fast: false 35 | matrix: 36 | compiler: ["clang-latest", "clang-second-latest", "clang-third-latest", "gcc-latest", "gcc-second-latest", "gcc-third-latest", "intel"] 37 | container: 38 | image: ghcr.io/seqan/${{ matrix.compiler }} 39 | steps: 40 | - name: Checkout 41 | uses: actions/checkout@v4 42 | 43 | - name: Setup cache 44 | uses: seqan/actions/setup-actions-cache@main 45 | 46 | - name: Configure tests 47 | run: | 48 | $CXX --version || true 49 | cmake --version || true 50 | mkdir build && cd build 51 | cmake ../test/unit -DCMAKE_BUILD_TYPE=Release \ 52 | -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" 53 | make gtest_main yaml-cpp 54 | 55 | - name: Build tests 56 | working-directory: build 57 | run: | 58 | ccache -z 59 | make -k 60 | ccache -svvx 61 | 62 | - name: Run tests 63 | working-directory: build 64 | run: ctest . -j --output-on-failure --no-tests=error 65 | 66 | -------------------------------------------------------------------------------- /.github/workflows/ci_macos.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: macOS 6 | 7 | on: 8 | push: 9 | branches: 10 | - 'main' 11 | pull_request: 12 | types: 13 | - unlabeled 14 | workflow_dispatch: 15 | 16 | concurrency: 17 | group: macos-${{ github.event.pull_request.number || github.ref }} 18 | cancel-in-progress: ${{ github.event_name != 'push' }} 19 | 20 | env: 21 | SHARG_NO_VERSION_CHECK: 1 22 | TZ: Europe/Berlin 23 | 24 | defaults: 25 | run: 26 | shell: bash -Eeuxo pipefail {0} 27 | 28 | jobs: 29 | build: 30 | name: ${{ matrix.compiler }} 31 | runs-on: macos-latest 32 | if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' || github.event.label.name == 'lint' 33 | strategy: 34 | fail-fast: false 35 | matrix: 36 | compiler: ["clang-latest", "clang-second-latest", "clang-third-latest", "gcc-latest", "gcc-second-latest", "gcc-third-latest"] 37 | steps: 38 | - name: Checkout 39 | uses: actions/checkout@v4 40 | 41 | - name: Setup toolchain 42 | uses: seqan/actions/setup-toolchain@main 43 | with: 44 | compiler: ${{ matrix.compiler }} 45 | ccache_size: 75M 46 | 47 | - name: Configure tests 48 | run: | 49 | mkdir build && cd build 50 | cmake ../test/unit -DCMAKE_BUILD_TYPE=Release 51 | make gtest_main 52 | 53 | - name: Build tests 54 | working-directory: build 55 | run: | 56 | ccache -z 57 | make -k 58 | ccache -svvx 59 | 60 | - name: Run tests 61 | working-directory: build 62 | run: ctest . -j --output-on-failure --no-tests=error 63 | -------------------------------------------------------------------------------- /.github/workflows/ci_misc.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: Misc 6 | 7 | on: 8 | push: 9 | branches: 10 | - 'main' 11 | pull_request: 12 | types: 13 | - unlabeled 14 | workflow_dispatch: 15 | 16 | concurrency: 17 | group: misc-${{ github.event.pull_request.number || github.ref }} 18 | cancel-in-progress: ${{ github.event_name != 'push' }} 19 | 20 | env: 21 | SHARG_NO_VERSION_CHECK: 1 22 | TZ: Europe/Berlin 23 | 24 | defaults: 25 | run: 26 | shell: bash -Eeuxo pipefail {0} 27 | 28 | jobs: 29 | build: 30 | name: ${{ matrix.build }} ${{ matrix.compiler }} 31 | runs-on: ubuntu-latest 32 | if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' || github.event.label.name == 'lint' 33 | strategy: 34 | fail-fast: false 35 | matrix: 36 | compiler: ["clang-latest", "gcc-latest", "gcc-third-latest", "intel"] 37 | build: ["snippet", "header"] 38 | container: 39 | image: ghcr.io/seqan/${{ matrix.compiler }} 40 | steps: 41 | - name: Checkout 42 | uses: actions/checkout@v4 43 | 44 | - name: Setup cache 45 | uses: seqan/actions/setup-actions-cache@main 46 | 47 | - name: Configure tests 48 | run: | 49 | mkdir build && cd build 50 | cmake ../test/${{ matrix.build }} -DCMAKE_BUILD_TYPE=Release \ 51 | -DCMAKE_CXX_FLAGS="${{ matrix.cxx_flags }}" 52 | make gtest_main yaml-cpp 53 | 54 | - name: Build tests 55 | working-directory: build 56 | run: | 57 | ccache -z 58 | make -k 59 | ccache -svvx 60 | 61 | - name: Run tests 62 | working-directory: build 63 | run: ctest . -j${{ matrix.build == 'snippet' && '1' || '' }} --output-on-failure --no-tests=error 64 | -------------------------------------------------------------------------------- /.github/workflows/cron_codechecker.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2025, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2025, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: CodeChecker 6 | 7 | on: 8 | schedule: 9 | - cron: "0 8 * * MON" 10 | workflow_dispatch: 11 | 12 | concurrency: 13 | group: codechecker-${{ github.ref }} 14 | cancel-in-progress: true 15 | 16 | env: 17 | SHARG_NO_VERSION_CHECK: 1 18 | TZ: Europe/Berlin 19 | 20 | defaults: 21 | run: 22 | shell: bash -Eexuo pipefail {0} 23 | 24 | jobs: 25 | build: 26 | name: CodeChecker 27 | runs-on: ubuntu-latest 28 | if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' 29 | container: 30 | image: ghcr.io/seqan/codechecker 31 | steps: 32 | - name: Run CodeChecker 33 | uses: seqan/actions/codechecker@main 34 | with: 35 | configure_path: ../test/analyse 36 | deploy_host: ${{ secrets.DEPLOY_HOST }} 37 | deploy_user: ${{ secrets.DEPLOY_USER }} 38 | deploy_ssh_key: ${{ secrets.DEPLOY_SSH_KEY }} 39 | deploy_path: ${{ secrets.DEPLOY_CODECHECKER_PATH }} 40 | -------------------------------------------------------------------------------- /.github/workflows/cron_codeql.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: CodeQL 6 | 7 | on: 8 | schedule: 9 | - cron: "0 21 * * MON" 10 | workflow_dispatch: 11 | 12 | concurrency: 13 | group: codeql-${{ github.ref }} 14 | cancel-in-progress: true 15 | 16 | env: 17 | SHARG_NO_VERSION_CHECK: 1 18 | CODEQL_EXTRACTOR_CPP_AUTOINSTALL_DEPENDENCIES: false 19 | TZ: Europe/Berlin 20 | 21 | defaults: 22 | run: 23 | shell: bash -Eeuxo pipefail {0} 24 | 25 | jobs: 26 | codeql: 27 | name: CodeQL 28 | runs-on: ubuntu-latest 29 | if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' 30 | permissions: 31 | security-events: write 32 | container: 33 | image: ghcr.io/seqan/gcc-second-latest 34 | steps: 35 | - name: Checkout 36 | uses: actions/checkout@v4 37 | 38 | - name: Initialize CodeQL 39 | uses: github/codeql-action/init@v3 40 | with: 41 | languages: cpp 42 | build-mode: manual 43 | trap-caching: false 44 | 45 | - name: Build tests 46 | run: | 47 | cmake test/analyse -DCMAKE_BUILD_TYPE=Release \ 48 | -DCMAKE_EXPORT_COMPILE_COMMANDS=ON 49 | make -k 50 | 51 | - name: Perform CodeQL Analysis 52 | uses: github/codeql-action/analyze@v3 53 | with: 54 | category: "/language:cpp" 55 | -------------------------------------------------------------------------------- /.github/workflows/cron_cpm.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: Update CPM 6 | 7 | on: 8 | schedule: 9 | - cron: "0 12 * * SAT" 10 | workflow_dispatch: 11 | 12 | env: 13 | TZ: Europe/Berlin 14 | 15 | concurrency: 16 | group: update-cpm-actions 17 | cancel-in-progress: true 18 | 19 | jobs: 20 | update_cpm: 21 | name: Update CPM 22 | runs-on: ubuntu-latest 23 | timeout-minutes: 15 24 | if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' 25 | steps: 26 | - name: Run update CPM 27 | uses: seqan/actions/update_cpm_package_lock@main 28 | with: 29 | token: ${{ secrets.SEQAN_ACTIONS_PAT }} 30 | gpg_key: ${{ secrets.SEQAN_ACTIONS_GPG_KEY }} 31 | gpg_passphrase: ${{ secrets.SEQAN_ACTIONS_GPG_PASSPHRASE }} 32 | package_lock_file: cmake/package-lock.cmake 33 | -------------------------------------------------------------------------------- /.github/workflows/readme_snippet.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: Sharg Markdown 6 | 7 | on: 8 | push: 9 | branches: 10 | - 'main' 11 | workflow_dispatch: 12 | 13 | concurrency: 14 | group: readme-snippet-${{ github.ref }} 15 | cancel-in-progress: true 16 | 17 | env: 18 | TZ: Europe/Berlin 19 | 20 | defaults: 21 | run: 22 | shell: bash -exo pipefail {0} 23 | 24 | jobs: 25 | readme-snippet: 26 | name: Update README 27 | runs-on: ubuntu-latest 28 | timeout-minutes: 15 29 | if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' 30 | steps: 31 | - name: Checkout Sharg 32 | uses: actions/checkout@v4 33 | with: 34 | token: ${{ secrets.SEQAN_ACTIONS_PAT }} 35 | 36 | - name: Import GPG key 37 | uses: crazy-max/ghaction-import-gpg@v6 38 | with: 39 | gpg_private_key: ${{ secrets.SEQAN_ACTIONS_GPG_KEY }} 40 | passphrase: ${{ secrets.SEQAN_ACTIONS_GPG_PASSPHRASE }} 41 | git_user_signingkey: true 42 | git_commit_gpgsign: true 43 | 44 | - name: Update README 45 | uses: dineshsonachalam/markdown-autodocs@v1.0.7 46 | with: 47 | commit_author: seqan-actions[bot] 48 | commit_user_email: seqan-actions@users.noreply.github.com 49 | commit_message: "[MISC] Update README.md" 50 | output_file_paths: '[./README.md]' 51 | categories: '[code-block]' 52 | -------------------------------------------------------------------------------- /.github/workflows/scripts/process_compiler_error_log.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 4 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 5 | # SPDX-License-Identifier: CC0-1.0 6 | # 7 | # Usage process_compiler_error_log.py 8 | # 9 | # Processes a build log and writes a GitHub-Markdown-formatted list of build errors to stdcout. 10 | import html 11 | import re 12 | import sys 13 | 14 | # https://regex101.com/r/aE0qX3/2 15 | tokenise_regex = re.compile(r"(\[\s*\d+%\](?:.(?!\[\s*\d+%\]))+(?:: error:).*?(?=\[\s*\d+%\]|$))", re.DOTALL) 16 | # Match line containg 'error:', but stop at linebreak, semicolon or parenthesis. 17 | error_regex = re.compile(r"(error:[^(;\n]*)") 18 | 19 | with open(sys.argv[1]) as file: 20 | content = file.read() 21 | 22 | counter = 1 23 | log = '' 24 | # One `group` (a string) is all messages in the log associated with one failing compilation 25 | for group in [match.groups()[0] for match in tokenise_regex.finditer(content)]: 26 | error_message = html.escape(re.search(error_regex, group).group().rstrip()[:110]) 27 | log += '
Error {}: {}\n\n```text\n'.format(counter, error_message) 28 | log += '\n'.join(group.split('\n')[:30]).rstrip() # Only take first 30 lines 29 | log += '\n```\n
\n' 30 | counter += 1 31 | 32 | # Truncate to 65300 to not exceed the limit of GitHub's API 33 | print(log[:65300]) 34 | -------------------------------------------------------------------------------- /.github/workflows/update_cookbook.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | name: Sharg Cookbook 6 | 7 | on: 8 | push: 9 | branches: 10 | - 'main' 11 | workflow_dispatch: 12 | 13 | concurrency: 14 | group: update-cookbook-${{ github.ref }} 15 | cancel-in-progress: true 16 | 17 | env: 18 | TZ: Europe/Berlin 19 | 20 | defaults: 21 | run: 22 | shell: bash -exo pipefail {0} 23 | 24 | jobs: 25 | update-cookbook: 26 | name: Update Cookbook 27 | runs-on: ubuntu-latest 28 | timeout-minutes: 15 29 | if: github.repository_owner == 'seqan' || github.event_name == 'workflow_dispatch' 30 | steps: 31 | - name: Checkout Sharg 32 | uses: actions/checkout@v4 33 | with: 34 | token: ${{ secrets.SEQAN_ACTIONS_PAT }} 35 | 36 | - name: Import GPG key 37 | uses: crazy-max/ghaction-import-gpg@v6 38 | with: 39 | gpg_private_key: ${{ secrets.SEQAN_ACTIONS_GPG_KEY }} 40 | passphrase: ${{ secrets.SEQAN_ACTIONS_GPG_PASSPHRASE }} 41 | git_user_signingkey: true 42 | git_commit_gpgsign: true 43 | 44 | - name: Update cookbook 45 | run: ./test/scripts/add_snippets_to_cookbook.sh . 46 | 47 | - name: Commit changes 48 | uses: EndBug/add-and-commit@v9 49 | with: 50 | add: ./doc/cookbook/index.md 51 | author_name: seqan-actions[bot] 52 | author_email: seqan-actions@users.noreply.github.com 53 | message: '[MISC] Update cookbook' 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | # Prerequisites 6 | *.d 7 | 8 | # Compiled Object files 9 | *.slo 10 | *.lo 11 | *.o 12 | *.obj 13 | 14 | # Precompiled Headers 15 | *.gch 16 | *.pch 17 | 18 | # Compiled Dynamic libraries 19 | *.so 20 | *.dylib 21 | *.dll 22 | 23 | # Fortran module files 24 | *.mod 25 | *.smod 26 | 27 | # Compiled Static libraries 28 | *.lai 29 | *.la 30 | *.a 31 | *.lib 32 | 33 | # Executables 34 | *.exe 35 | *.app 36 | -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | # https://www.gitpod.io/docs/references/gitpod-yml 6 | checkoutLocation: "tutorial/sharg-parser" 7 | workspaceLocation: "/tutorial" 8 | tasks: 9 | - name: Setup 10 | before: mkdir -p build source 11 | init: HOMEBREW_NO_INSTALL_CLEANUP=1 HOMEBREW_NO_ENV_HINTS=1 brew install cmake gcc@12 tree 12 | command: echo && echo "GCC 12 available via g++-12" && echo && echo "g++-12 --version" && g++-12 --version 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # This file provides functionality common to the different test modules used by 6 | # Sharg. To build tests, run cmake on one of the sub-folders in this directory 7 | # which contain a CMakeLists.txt. 8 | 9 | cmake_minimum_required (VERSION 3.12) 10 | 11 | find_path (SHARG_MODULE_PATH "sharg-config.cmake" HINTS "${CMAKE_CURRENT_LIST_DIR}/cmake/") 12 | list (APPEND CMAKE_MODULE_PATH "${SHARG_MODULE_PATH}") 13 | 14 | include (sharg-config-version) 15 | 16 | project (sharg 17 | LANGUAGES CXX 18 | VERSION "${SHARG_PROJECT_VERSION}" 19 | DESCRIPTION "Sharg -- hungrily eating away your arguments" 20 | HOMEPAGE_URL "https://github.com/seqan/sharg-parser") 21 | 22 | include (sharg-config) 23 | 24 | option (INSTALL_SHARG "Enable installation of Sharg. (Projects embedding Sharg may want to turn this OFF.)" ON) 25 | 26 | if (INSTALL_SHARG) 27 | include (sharg-install) 28 | include (sharg-package) 29 | endif () 30 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct {#about_code_of_conduct} 2 | 3 | 8 | 9 | The Sharg-parser adheres to the [Berlin Code of Conduct](https://berlincodeofconduct.org/). As the Sharg-parser was 10 | created and is maintained by the SeqAn team, it is part of the SeqAn project. Therefore, SeqAn's Code of Conduct 11 | applies to the Sharg-parser as well. Please see 12 | [SeqAn's Code of Conduct](https://docs.seqan.de/seqan3/main_user/about_code_of_conduct.html) for more 13 | information on our Code of Conduct. 14 | -------------------------------------------------------------------------------- /LICENSES/BSD-3-Clause.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) . 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 7 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 12 | -------------------------------------------------------------------------------- /LICENSES/MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /cmake/CPM.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: MIT 2 | # 3 | # SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors 4 | 5 | set (CPM_DOWNLOAD_VERSION 0.42.0) 6 | set (CPM_HASH_SUM "2020b4fc42dba44817983e06342e682ecfc3d2f484a581f11cc5731fbe4dce8a") 7 | 8 | if (CPM_SOURCE_CACHE) 9 | set (CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") 10 | elseif (DEFINED ENV{CPM_SOURCE_CACHE}) 11 | set (CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") 12 | else () 13 | set (CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") 14 | endif () 15 | 16 | # Expand relative path. This is important if the provided path contains a tilde (~) 17 | get_filename_component (CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) 18 | 19 | file (DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake 20 | ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}) 21 | 22 | include (${CPM_DOWNLOAD_LOCATION}) 23 | -------------------------------------------------------------------------------- /cmake/cpack_install.cmake.in: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # Only if creating the source package (`make package_source`): 6 | # Copy dependency include directories into package's staging folder 7 | if (CPACK_SOURCE_INSTALLED_DIRECTORIES) 8 | configure_file ("@CPM_DOWNLOAD_LOCATION@" "${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake" COPYONLY) 9 | if ("@use_ccache_ADDED@" STREQUAL "YES") 10 | configure_file ("@use_ccache_SOURCE_DIR@/ccache/CMakeLists.txt" 11 | "${CMAKE_CURRENT_BINARY_DIR}/test/cmake/sharg_require_ccache.cmake" COPYONLY) 12 | endif () 13 | endif () 14 | -------------------------------------------------------------------------------- /cmake/package-lock.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | # CPM Package Lock 6 | # This file should be committed to version control 7 | 8 | # URL/GIT_TAG may be annotated with a branch name 9 | # This is needed for https://github.com/seqan/actions/tree/main/update_cpm_package_lock 10 | 11 | # The first argument of CPMDeclarePackage can be freely chosen and is used as argument in CPMGetPackage. 12 | # The NAME argument should be package name that would also be used in a find_package call. 13 | # Ideally, both are the same, which might not always be possible: https://github.com/cpm-cmake/CPM.cmake/issues/603 14 | # This is needed to support CPM_USE_LOCAL_PACKAGES 15 | 16 | # TDL 17 | set (SHARG_TDL_VERSION 1.0.1) 18 | CPMDeclarePackage (tdl 19 | NAME tdl 20 | VERSION ${SHARG_TDL_VERSION} 21 | GITHUB_REPOSITORY deNBI-cibi/tool_description_lib 22 | SYSTEM TRUE 23 | OPTIONS "INSTALL_TDL OFF" "CMAKE_MESSAGE_LOG_LEVEL WARNING") 24 | # googletest 25 | set (SHARG_GOOGLETEST_VERSION 1.17.0) 26 | CPMDeclarePackage (googletest 27 | NAME GTest 28 | VERSION ${SHARG_GOOGLETEST_VERSION} 29 | GITHUB_REPOSITORY google/googletest 30 | SYSTEM TRUE 31 | OPTIONS "BUILD_GMOCK OFF" "INSTALL_GTEST OFF" "CMAKE_MESSAGE_LOG_LEVEL WARNING") 32 | # doxygen-awesome 33 | set (SHARG_DOXYGEN_AWESOME_VERSION 2.3.4) 34 | CPMDeclarePackage (doxygen_awesome 35 | NAME doxygen_awesome 36 | VERSION ${SHARG_DOXYGEN_AWESOME_VERSION} 37 | GITHUB_REPOSITORY jothepro/doxygen-awesome-css 38 | DOWNLOAD_ONLY TRUE 39 | QUIET YES) 40 | # use_ccache 41 | set (SHARG_USE_CCACHE_VERSION d2a54ef555b6fc2d496a4c9506dbeb7cf899ce37) 42 | CPMDeclarePackage (use_ccache 43 | NAME use_ccache 44 | GIT_TAG ${SHARG_USE_CCACHE_VERSION} # main 45 | GITHUB_REPOSITORY seqan/cmake-scripts 46 | SOURCE_SUBDIR ccache 47 | SYSTEM TRUE 48 | EXCLUDE_FROM_ALL TRUE) 49 | -------------------------------------------------------------------------------- /cmake/sharg-install.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # This file describes where and which parts of Sharg should be installed to. 6 | 7 | cmake_minimum_required (VERSION 3.14) 8 | 9 | include (GNUInstallDirs) 10 | 11 | # install documentation files in /share/doc 12 | install (FILES "${SHARG_CLONE_DIR}/CHANGELOG.md" # 13 | "${SHARG_CLONE_DIR}/CODE_OF_CONDUCT.md" # 14 | "${SHARG_CLONE_DIR}/CONTRIBUTING.md" # 15 | "${SHARG_CLONE_DIR}/LICENSE.md" # 16 | "${SHARG_CLONE_DIR}/README.md" 17 | TYPE DOC) 18 | 19 | # install cmake files in /share/cmake 20 | install (FILES "${SHARG_CLONE_DIR}/cmake/sharg-config.cmake" "${SHARG_CLONE_DIR}/cmake/sharg-config-version.cmake" 21 | DESTINATION "${CMAKE_INSTALL_DATADIR}/cmake/sharg") 22 | 23 | # install sharg header files in /include/sharg 24 | install (DIRECTORY "${SHARG_INCLUDE_DIR}/sharg" TYPE INCLUDE) 25 | -------------------------------------------------------------------------------- /cmake/sharg-package.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # This file describes how Sharg will be packaged. 6 | 7 | cmake_minimum_required (VERSION 3.12) 8 | 9 | set (CPACK_GENERATOR "TXZ") 10 | 11 | set (CPACK_PACKAGE_VERSION "${SHARG_VERSION}") 12 | set (CPACK_PACKAGE_VENDOR "seqan") 13 | # A description of the project, used in places such as the introduction screen of CPack-generated Windows installers. 14 | # set (CPACK_PACKAGE_DESCRIPTION_FILE "") # TODO 15 | set (CPACK_PACKAGE_CHECKSUM "SHA256") 16 | set (CPACK_PACKAGE_ICON "${SHARG_CLONE_DIR}/test/documentation/sharg_logo.svg") 17 | set (CPACK_RESOURCE_FILE_LICENSE "${SHARG_CLONE_DIR}/LICENSE.md") 18 | set (CPACK_RESOURCE_FILE_README "${SHARG_CLONE_DIR}/README.md") 19 | 20 | # Already being called on source package, i.e. CPM is already downloaded. 21 | if (NOT CPM_DOWNLOAD_LOCATION) 22 | set (CPM_DOWNLOAD_LOCATION "${SHARG_CLONE_DIR}/cmake/CPM.cmake") 23 | else () 24 | CPMGetPackage (use_ccache) 25 | endif () 26 | 27 | configure_file ("${SHARG_CLONE_DIR}/cmake/cpack_install.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cpack_install.cmake" 28 | @ONLY) 29 | set (CPACK_INSTALL_SCRIPT "${CMAKE_CURRENT_BINARY_DIR}/cpack_install.cmake") 30 | 31 | # Source Package 32 | set (CPACK_SOURCE_GENERATOR "TXZ") 33 | # Next 2 lines would overwrite copy in cpack_install.cmake 34 | list (APPEND CPACK_SOURCE_IGNORE_FILES "/cmake/CPM.cmake") 35 | list (APPEND CPACK_SOURCE_IGNORE_FILES "/test/cmake/sharg_require_ccache.cmake") 36 | list (APPEND CPACK_SOURCE_IGNORE_FILES "/\.git($|/)") 37 | list (APPEND CPACK_SOURCE_IGNORE_FILES "/\.github/") 38 | list (APPEND CPACK_SOURCE_IGNORE_FILES "/\.vscode/") 39 | list (APPEND CPACK_SOURCE_IGNORE_FILES "/build/") 40 | list (APPEND CPACK_SOURCE_IGNORE_FILES "/submodules/") 41 | 42 | include (CPack) 43 | -------------------------------------------------------------------------------- /doc/about/copyright/bsdl_badge.svg: -------------------------------------------------------------------------------- 1 | LicenseLicenseBSD 3-ClauseBSD 3-Clause -------------------------------------------------------------------------------- /doc/about/copyright/bsdl_badge.svg.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: Shields IO Project Contributors 2 | SPDX-License-Identifier: CC0-1.0 3 | -------------------------------------------------------------------------------- /doc/about/copyright/cc0_badge.svg: -------------------------------------------------------------------------------- 1 | LicenseLicenseCC0 1.0CC0 1.0 -------------------------------------------------------------------------------- /doc/about/copyright/cc0_badge.svg.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: Shields IO Project Contributors 2 | SPDX-License-Identifier: CC0-1.0 3 | -------------------------------------------------------------------------------- /doc/about/copyright/ccby_badge.svg: -------------------------------------------------------------------------------- 1 | LicenseLicenseCC BY 4.0CC BY 4.0 -------------------------------------------------------------------------------- /doc/about/copyright/ccby_badge.svg.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: Shields IO Project Contributors 2 | SPDX-License-Identifier: CC0-1.0 3 | -------------------------------------------------------------------------------- /doc/about/copyright/copyfree_badge.svg: -------------------------------------------------------------------------------- 1 | LicenseLicensepermissive/copyfreepermissive/copyfree -------------------------------------------------------------------------------- /doc/about/copyright/copyfree_badge.svg.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: Shields IO Project Contributors 2 | SPDX-License-Identifier: CC0-1.0 3 | -------------------------------------------------------------------------------- /doc/about/customisation/index.md: -------------------------------------------------------------------------------- 1 | # Customisation {#about_customisation} 2 | 3 | 8 | 9 | Please see the SeqAn documentation about 10 | [customisation](https://docs.seqan.de/seqan3/main_user/about_customisation.html). 11 | -------------------------------------------------------------------------------- /doc/cookbook/basic_arg_parse.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | void run_program(std::filesystem::path const & reference_path, std::filesystem::path const & index_path) 8 | { 9 | std::cerr << "reference_file_path: " << reference_path << '\n'; 10 | std::cerr << "index_path " << index_path << '\n'; 11 | } 12 | 13 | struct cmd_arguments 14 | { 15 | std::filesystem::path reference_path{}; 16 | std::filesystem::path index_path{"out.index"}; 17 | }; 18 | 19 | void initialise_parser(sharg::parser & parser, cmd_arguments & args) 20 | { 21 | parser.info.author = "E. coli"; 22 | parser.info.short_description = "Creates an index over a reference."; 23 | parser.info.version = "1.0.0"; 24 | parser.add_option(args.reference_path, 25 | sharg::config{.short_id = 'r', 26 | .long_id = "reference", 27 | .description = "The path to the reference.", 28 | .required = true, 29 | .validator = sharg::input_file_validator{{"fa", "fasta"}}}); 30 | parser.add_option( 31 | args.index_path, 32 | sharg::config{.short_id = 'o', 33 | .long_id = "output", 34 | .description = "The output index file path.", 35 | .validator = 36 | sharg::output_file_validator{sharg::output_file_open_options::create_new, {"index"}}}); 37 | } 38 | 39 | //![main] 40 | int main(int argc, char const ** argv) 41 | { 42 | sharg::parser parser("Indexer", argc, argv); 43 | cmd_arguments args{}; 44 | 45 | initialise_parser(parser, args); 46 | 47 | try 48 | { 49 | parser.parse(); 50 | } 51 | catch (sharg::parser_error const & ext) 52 | { 53 | std::cerr << "[PARSER ERROR] " << ext.what() << '\n'; 54 | return -1; 55 | } 56 | 57 | run_program(args.reference_path, args.index_path); 58 | 59 | return 0; 60 | } 61 | //![main] 62 | -------------------------------------------------------------------------------- /doc/cookbook/basic_arg_parse.out: -------------------------------------------------------------------------------- 1 | Indexer - Creates an index over a reference. 2 | ============================================ 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /doc/cookbook/basic_arg_parse.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /doc/cookbook/index.md: -------------------------------------------------------------------------------- 1 | # The Sharg Cookbook {#cookbook} 2 | 3 | 8 | 9 | [TOC] 10 | 11 | This document provides example recipes on how to carry out particular tasks using the Sharg functionalities in C++. 12 | Please note that these **recipes are not ordered**. You can use the links in the table of contents or the search 13 | function of your browser to navigate them. 14 | 15 | It will take some time, but we hope to expand this document into containing numerous great examples. 16 | If you have suggestions for how to improve the Cookbook and/or examples you would like included, 17 | please feel free to contact us. 18 | 19 | # Constructing a basic parser 20 | 21 | \include doc/cookbook/basic_arg_parse.cpp 22 | 23 | # Constructing a subcommand parser 24 | 25 | \include doc/howto/subcommand_parser/subcommand_parse.cpp 26 | 27 | # Write a custom validator {#cookbook_custom_validator} 28 | This recipe implements a validator that checks whether a numeric argument is an integral square (i.e. 0, 1, 4, 9...). 29 | Invalid values throw a sharg::validation_error. 30 | 31 | \snippet doc/tutorial/concepts/custom_validator_solution.cpp validator 32 | 33 | # All Sharg documentation snippets 34 | 35 | The following lists all snippets that appear in our documentation. Search for keywords with Strg + F. 36 | 37 | 38 | \include test/snippet/add_subcommands.cpp 39 | \include test/snippet/auxiliary.cpp 40 | \include test/snippet/custom_enumeration.cpp 41 | \include test/snippet/custom_parsing_enumeration.cpp 42 | \include test/snippet/is_option_set.cpp 43 | \include test/snippet/parser_1.cpp 44 | \include test/snippet/parser_2.cpp 45 | \include test/snippet/parser_3.cpp 46 | \include test/snippet/readme_sneak_peek.cpp 47 | \include test/snippet/safe_filesystem_entry.cpp 48 | \include test/snippet/snippet_main.cpp 49 | \include test/snippet/validators_1.cpp 50 | \include test/snippet/validators_2.cpp 51 | \include test/snippet/validators_3.cpp 52 | \include test/snippet/validators_4.cpp 53 | \include test/snippet/validators_chaining.cpp 54 | \include test/snippet/validators_input_directory.cpp 55 | \include test/snippet/validators_input_file.cpp 56 | \include test/snippet/validators_input_file_ext_from_file.cpp 57 | \include test/snippet/validators_output_directory.cpp 58 | \include test/snippet/validators_output_file.cpp 59 | \include test/snippet/validators_output_file_ext_from_file.cpp 60 | -------------------------------------------------------------------------------- /doc/howto/custom_types/custom_type.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | // my custom type 8 | namespace foo 9 | { 10 | 11 | class bar 12 | { 13 | public: 14 | int a; 15 | 16 | // Make foo::bar satisfy sharg::ostreamable 17 | friend std::ostream & operator<<(std::ostream & output, bar const & my_bar) 18 | { 19 | output << my_bar.a; // Adapt this for your type 20 | return output; 21 | } 22 | 23 | // Make foo::bar satisfy sharg::istreamable 24 | friend std::istream & operator>>(std::istream & input, bar & my_bar) 25 | { 26 | input >> my_bar.a; // Adapt this for your type 27 | return input; 28 | } 29 | }; 30 | 31 | } // namespace foo 32 | 33 | int main(int argc, char const ** argv) 34 | { 35 | sharg::parser parser{"my_foobar_parser", argc, argv, sharg::update_notifications::off}; 36 | 37 | foo::bar my_bar{}; 38 | parser.add_option(my_bar, 39 | sharg::config{.short_id = 'f', .long_id = "foo-bar", .description = "Supply an integer."}); 40 | 41 | try 42 | { 43 | parser.parse(); // trigger command line parsing 44 | } 45 | catch (sharg::parser_error const & ext) // catch user errors 46 | { 47 | std::cerr << "[Error] " << ext.what() << "\n"; // customise your error message 48 | return -1; 49 | } 50 | 51 | std::cout << "my_bar was initialised with a = " << my_bar.a << '\n'; 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /doc/howto/custom_types/custom_type.out: -------------------------------------------------------------------------------- 1 | my_foobar_parser 2 | ================ 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /doc/howto/custom_types/custom_type.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /doc/howto/custom_types/external_custom_type.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | // external type, i.e., you cannot change the implementation 8 | namespace external 9 | { 10 | 11 | class bar 12 | { 13 | public: 14 | int a; 15 | }; 16 | 17 | } // namespace external 18 | 19 | namespace std 20 | { 21 | 22 | // Make external::bar satisfy sharg::ostreamable 23 | ostream & operator<<(ostream & output, external::bar const & ext_bar) 24 | { 25 | output << ext_bar.a; // Adapt this for your type 26 | return output; 27 | } 28 | 29 | // Make external::bar satisfy sharg::istreamable 30 | istream & operator>>(istream & input, external::bar & ext_bar) 31 | { 32 | input >> ext_bar.a; // Adapt this for your type 33 | return input; 34 | } 35 | 36 | } // namespace std 37 | 38 | int main(int argc, char const ** argv) 39 | { 40 | sharg::parser parser{"my_ext_bar_parser", argc, argv, sharg::update_notifications::off}; 41 | 42 | external::bar ext_bar{}; 43 | parser.add_option(ext_bar, sharg::config{.short_id = 'f', .long_id = "ext-bar", .description = "Supply an int."}); 44 | 45 | try 46 | { 47 | parser.parse(); // trigger command line parsing 48 | } 49 | catch (sharg::parser_error const & ext) // catch user errors 50 | { 51 | std::cerr << "[Error] " << ext.what() << "\n"; // customise your error message 52 | return -1; 53 | } 54 | 55 | std::cout << "ext_bar was initialised with a = " << ext_bar.a << '\n'; 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /doc/howto/custom_types/external_custom_type.out: -------------------------------------------------------------------------------- 1 | my_ext_bar_parser 2 | ================= 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /doc/howto/custom_types/external_custom_type.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /doc/howto/custom_types/index.md: -------------------------------------------------------------------------------- 1 | # How to make your custom type model sharg::parsable {#fulfil_parsable} 2 | 3 | 8 | 9 | [TOC] 10 | 11 | This HowTo guides you through satisfying the requirements of sharg::parsable. 12 | 13 | \tutorial_head{Easy, 10 min, , } 14 | 15 | # Motivation 16 | 17 | To use a custom type with `sharg::parser::add_option` or 18 | `sharg::parser::add_positional_option`, the type must satisfy `sharg::parsable`. 19 | This tutorial shows you what requirements must be met and supplies you with a copy and paste source 20 | for your code. 21 | 22 | # Concept sharg::parsable 23 | 24 | As you can see in the API documentation of `sharg::parsable`, the type must model either both 25 | `sharg::istreamable` and `sharg::ostreamable` or `sharg::named_enumeration`. 26 | 27 | **If your type is an enum, refer to `sharg::enumeration_names` on how to make it compatible with the 28 | `sharg::parser`.** 29 | 30 | In all other cases, your type needs to model `sharg::istreamable` and `sharg::ostreamable`. 31 | As you can see in the respective documentation, the concept is simple. You merely need to 32 | supply the stream operators `operator>>()` and `operator<<()` for your type. 33 | 34 | # Make your own type compatible 35 | 36 | \note You must be able to modify the class itself for this solution to work. 37 | 38 | The following example makes the class `bar` in namespace `foo` compatible with the `sharg::parser`: 39 | 40 | \include doc/howto/custom_types/custom_type.cpp 41 | 42 | # Make an external type compatible 43 | 44 | If you cannot modify the class, you can do the following: 45 | 46 | \include doc/howto/custom_types/external_custom_type.cpp 47 | -------------------------------------------------------------------------------- /doc/howto/custom_validator/custom_validator_solution1.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | struct custom_validator 8 | { 9 | using option_value_type = double; // used for all arithmetic types 10 | 11 | void operator()(option_value_type const &) const 12 | { 13 | // add implementation later 14 | } 15 | 16 | std::string get_help_page_message() const 17 | { 18 | // add real implementation later 19 | return ""; 20 | } 21 | }; 22 | 23 | static_assert(sharg::validator); // does not cause compile error 24 | 25 | int main() 26 | {} 27 | -------------------------------------------------------------------------------- /doc/howto/subcommand_parser/index.md: -------------------------------------------------------------------------------- 1 | # How to write a parser with subcommands {#subcommand_parse} 2 | 3 | 8 | 9 | [TOC] 10 | 11 | This HowTo shows you how to write a parser with subcommands like `git push` using Sharg. 12 | 13 | \tutorial_head{Easy, 15 min, \ref tutorial_parser, } 14 | 15 | # Motivation 16 | 17 | A common use case for command line tools, e.g. `git`, is to have multiple subcommands, e.g. `git fetch` or `git push`. 18 | Each subcommand has its own set of options and its own help page. 19 | This HowTo explains how this can be done with the sharg::parser and serves as a copy'n'paste source. 20 | If you are new to Sharg, we recommend to do the basic 21 | \link tutorial_parser parser tutorial \endlink before you read further. 22 | 23 | # A subcommand parser 24 | 25 | In order to keep parsing with subcommands straightforward and simple, 26 | the sharg::parser provides an advanced interface that internally takes care of the correct input parsing. 27 | 28 | You simply need to specify the names of the subcommands when constructing your top-level parser: 29 | 30 | \snippet doc/howto/subcommand_parser/subcommand_parse.cpp construction 31 | 32 | \attention You can still add flags to your top-level parser if needed but **no (positional) options**. 33 | This avoids ambiguous parsing (e.g. subcommand fasta given file extension fasta 34 | `./myfasta_parser --filext fasta fasta ...`). 35 | 36 | After calling sharg::parser::parse() on your top-level parser, 37 | you can then access the sub-parser via the function sharg::parser::get_sub_parser(): 38 | 39 | \snippet doc/howto/subcommand_parser/subcommand_parse.cpp get_sub_parser 40 | 41 | The sub-parser's **sharg::parser::info::app_name will be set to the user chosen sub command**. 42 | For example, if the user calls 43 | 44 | ``` 45 | max$ ./mygit push -h 46 | ``` 47 | 48 | then the sub-parser will be named `mygit-push` and will be instantiated with all arguments 49 | followed by the keyword `push` which in this case triggers printing the help page (`-h`). 50 | 51 | That's it. Here is a full example of a subcommand parser you can try and adjust to your needs: 52 | 53 | \include doc/howto/subcommand_parser/subcommand_parse.cpp 54 | 55 | # Recursive subcommands 56 | 57 | If you want to have subcommands with subcommands, you can add subcommands to the sub-parser 58 | with sharg::parser::add_subcommands(): 59 | 60 | \include test/snippet/add_subcommands.cpp 61 | -------------------------------------------------------------------------------- /doc/howto/subcommand_parser/subcommand_parse.out: -------------------------------------------------------------------------------- 1 | mygit 2 | ===== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /doc/howto/subcommand_parser/subcommand_parse.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /doc/main_page.md: -------------------------------------------------------------------------------- 1 | # Welcome {#mainpage} 2 | 3 | 8 | 9 | Welcome to the documentation of the Sharg parser. 10 | This web-site contains the API reference (documentation of our interfaces) and more elaborate Tutorials and 11 | How-Tos. 12 | 13 | If you are new to [SeqAn](https://github.com/seqan/seqan3) or the Sharg parser, we recommend that you begin by reading \ref setup. 14 | 15 | In contrast to the Tutorials (which are expected to be useful for all developers), the How-Tos contain more advanced 16 | or specific guides. 17 | 18 | \ref cookbook contains a listing of code snippets, or *recipes* that might prove helpful once you 19 | have finished the full tutorial and you are implementing your own code. 20 | When you are looking for some inspiration on how to perform a particular task or when you searching for something you 21 | already know - its on the tip of your tongue - but you can't remember the syntax, take a look here. 22 | 23 | Before you publish and/or redistribute software based on Sharg, please read through the notes on \ref about_copyright. 24 | There are few requirements beyond proper attribution, but this requirement we take seriously as it is the basis of 25 | acquiring funding for the future development and maintenance of Sharg. 26 | 27 | Resources outside of this web-site that might be useful: 28 | 29 | * The [project homepage](https://www.seqan.de) with news and application pages. 30 | * The [GitHub repository](https://github.com/seqan/sharg-parser) with issue tracker and downloads. 31 | * The [SeqAn documentation](https://docs.seqan.de/). 32 | 33 | ### Some notes on using this documentation 34 | 35 | We use [doxygen](https://doxygen.nl) to generate our documentation. 36 | It may not be the most beautiful system, but it works quite well in practice. 37 | If you spot any dead links in the documentation, please open an issue at our bug-tracker (see above) or 38 | [directly submit a pull request](\ref about_contributing) fixing the problem. 39 | 40 | The documentation is versioned together with the library, see https://docs.seqan.de for release-specific 41 | documentation builds. 42 | The tutorial on \ref setup_tests contains instructions for setting up local documentation builds. 43 | -------------------------------------------------------------------------------- /doc/setup/library_tests/index.md: -------------------------------------------------------------------------------- 1 | # Setting up library tests {#setup_tests} 2 | 3 | 8 | 9 | Please see the SeqAn documentation about [setup tests](https://docs.seqan.de/seqan3/main_dev/setup_tests.html). 10 | -------------------------------------------------------------------------------- /doc/tutorial/concepts/custom_validator_solution.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | //![validator] 7 | #include 8 | 9 | struct custom_validator 10 | { 11 | using option_value_type = double; // used for all arithmetic types 12 | 13 | void operator()(option_value_type const & val) const 14 | { 15 | if ((std::round(val) != val) || // not an integer 16 | (std::pow(std::round(std::sqrt(val)), 2) != val)) // not a square 17 | { 18 | throw sharg::validation_error{"The provided number is not an arithmetic square."}; 19 | } 20 | } 21 | 22 | std::string get_help_page_message() const 23 | { 24 | return "Value must be the square of an integral number."; 25 | } 26 | }; 27 | //![validator] 28 | 29 | static_assert(sharg::validator); 30 | 31 | //![main] 32 | int main(int argc, char ** argv) 33 | { 34 | sharg::parser myparser("Test-Parser", argc, argv); 35 | 36 | int32_t variable{}; 37 | int16_t variable2{}; 38 | 39 | myparser.add_option(variable, 40 | sharg::config{.short_id = 'i', 41 | .description = "An int that is a square", 42 | .validator = custom_validator{}}); // ← your validator is used! 43 | 44 | myparser.add_option(variable2, 45 | sharg::config{.short_id = 'j', 46 | .description = "An int that is a square and within [0,20].", 47 | .validator = custom_validator{} 48 | | sharg::arithmetic_range_validator{0, 20}}); // ← now it's chained 49 | 50 | try 51 | { 52 | myparser.parse(); // trigger command line parsing 53 | } 54 | catch (sharg::parser_error const & ext) 55 | { 56 | std::cout << ext.what() << '\n'; 57 | return -1; 58 | } 59 | std::cout << "Yeah!\n"; 60 | 61 | return 0; 62 | } 63 | //![main] 64 | -------------------------------------------------------------------------------- /doc/tutorial/concepts/custom_validator_solution.out: -------------------------------------------------------------------------------- 1 | Test-Parser 2 | =========== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /doc/tutorial/concepts/custom_validator_solution.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /doc/tutorial/parser/basic_parser_setup.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include // includes all necessary headers 6 | 7 | int main(int argc, char ** argv) 8 | { 9 | sharg::parser myparser{"Game-of-Parsing", argc, argv}; // initialise myparser 10 | 11 | // ... add information, options, flags and positional options 12 | 13 | try 14 | { 15 | myparser.parse(); // trigger command line parsing 16 | } 17 | catch (sharg::parser_error const & ext) // catch user errors 18 | { 19 | std::cerr << "[Winter has come] " << ext.what() << "\n"; // customise your error message 20 | return -1; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /doc/tutorial/parser/basic_parser_setup.out: -------------------------------------------------------------------------------- 1 | Game-of-Parsing 2 | =============== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /doc/tutorial/parser/basic_parser_setup.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /doc/tutorial/parser/data.tsv: -------------------------------------------------------------------------------- 1 | Season Month Day Year Avg. U.S. viewers (millions) 2 | 1 April 17 2011 2.52 3 | 2 April 1 2012 3.80 4 | 3 March 31 2013 4.97 5 | 4 April 6 2014 6.84 6 | 5 April 12 2015 6.88 7 | 6 April 24 2016 7.69 8 | 7 July 16 2017 10.26 9 | -------------------------------------------------------------------------------- /doc/tutorial/parser/data.tsv.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /doc/tutorial/parser/disable_version_check.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char ** argv) 8 | { 9 | sharg::parser myparser{"Game-of-Parsing", argc, argv, sharg::update_notifications::off}; 10 | // disable update notifications permanently ----------------------------^ 11 | } 12 | -------------------------------------------------------------------------------- /doc/tutorial/parser/small_snippets.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | //![validator_include] 8 | #include 9 | 10 | //![validator_include] 11 | 12 | struct cmd_arguments 13 | { 14 | std::filesystem::path file_path{}; 15 | std::vector seasons{}; 16 | std::string aggregate_by{"mean"}; 17 | bool header_is_set{}; 18 | }; 19 | 20 | cmd_arguments args{}; 21 | 22 | // clang-format off 23 | int main(int argc, char ** argv) 24 | { 25 | 26 | { 27 | sharg::parser parser{"Example-Parser", argc, argv}; 28 | //![add_positional_option] 29 | size_t variable{}; 30 | parser.add_positional_option(variable, sharg::config{.description = "This is a description."}); 31 | //![add_positional_option] 32 | } 33 | 34 | { 35 | sharg::parser parser{"Example-Parser", argc, argv}; 36 | //![add_option] 37 | size_t variable{}; 38 | parser.add_option(variable, sharg::config{.short_id = 'n', .long_id = "my-num", .description = "A description."}); 39 | //![add_option] 40 | } 41 | 42 | { 43 | sharg::parser parser{"Example-Parser", argc, argv}; 44 | //![add_flag] 45 | bool variable{false}; 46 | parser.add_flag(variable, sharg::config{.short_id = 'f', .long_id = "my-flag", .description = "A description."}); 47 | //![add_flag] 48 | } 49 | 50 | { 51 | sharg::parser parser{"Example-Parser", argc, argv}; 52 | //![option_list] 53 | std::vector list_variable{}; 54 | parser.add_option(list_variable, sharg::config{.short_id = 'n', .long_id = "names", .description = "Some names."}); 55 | //![option_list] 56 | } 57 | 58 | { 59 | sharg::parser parser{"Example-Parser", argc, argv}; 60 | //![positional_option_list] 61 | std::string variable{}; 62 | std::vector list_variable{}; 63 | parser.add_positional_option(variable, sharg::config{.description = "Give me a single variable."}); 64 | parser.add_positional_option(list_variable, sharg::config{.description = "Give me one or more variables!."}); 65 | //![positional_option_list] 66 | } 67 | 68 | { 69 | sharg::parser parser{"Example-Parser", argc, argv}; 70 | //![required_option] 71 | std::string required_variable{}; 72 | parser.add_option(required_variable, sharg::config{.short_id = 'n', .long_id = "name", 73 | .description = "I really need a name.", .required = true}); 74 | //![required_option] 75 | } 76 | 77 | { 78 | sharg::parser parser{"Example-Parser", argc, argv}; 79 | //![input_file_validator] 80 | parser.add_positional_option(args.file_path, sharg::config{.description = "Please provide a tab separated data file.", 81 | .validator = sharg::input_file_validator{{"tsv"}}}); 82 | //![input_file_validator] 83 | } 84 | } 85 | // clang-format on 86 | -------------------------------------------------------------------------------- /doc/tutorial/parser/solution1.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include // includes all necessary headers 6 | 7 | void initialise_parser(sharg::parser & parser) 8 | { 9 | parser.info.author = "Cersei"; 10 | parser.info.short_description = "Aggregate average Game of Thrones viewers by season."; 11 | parser.info.version = "1.0.0"; 12 | } 13 | 14 | int main(int argc, char ** argv) 15 | { 16 | sharg::parser myparser{"Game-of-Parsing", argc, argv}; 17 | initialise_parser(myparser); 18 | // code from assignment 1 19 | } 20 | -------------------------------------------------------------------------------- /doc/tutorial/parser/solution3.out: -------------------------------------------------------------------------------- 1 | Game-of-Parsing - Aggregate average Game of Thrones viewers by season. 2 | ====================================================================== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /doc/tutorial/parser/solution3.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /doc/tutorial/parser/solution4.out: -------------------------------------------------------------------------------- 1 | Game-of-Parsing - Aggregate average Game of Thrones viewers by season. 2 | ====================================================================== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /doc/tutorial/parser/solution4.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /doc/tutorial/parser/solution5.out: -------------------------------------------------------------------------------- 1 | Game-of-Parsing - Aggregate average Game of Thrones viewers by season. 2 | ====================================================================== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /doc/tutorial/parser/solution5.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /doc/tutorial/parser/solution6.out: -------------------------------------------------------------------------------- 1 | Game-of-Parsing - Aggregate average Game of Thrones viewers by season. 2 | ====================================================================== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /doc/tutorial/parser/solution6.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /include/sharg/all.hpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | /*!\file 6 | * \author Svenja Mehringer 7 | * \brief Meta-header for the \link parser Parser module \endlink. 8 | */ 9 | 10 | /*!\defgroup parser Parser 11 | * \brief The Parser Module 12 | * 13 | * # The Parser Class 14 | * 15 | * \copydetails sharg::parser 16 | * 17 | * # Parsing Command Line Arguments 18 | * 19 | * \copydetails sharg::parser::parse 20 | * 21 | * # Argument Validation 22 | * 23 | * The Sharg Parser offers a validation mechanism for (positional_)options 24 | * via callables. You can pass any functor that fulfils the sharg::validator 25 | * and takes the value passed to the add_(positional_)option function call as 26 | * a parameter. We provide some commonly used functor that might come in handy: 27 | * 28 | * - sharg::regex_validator 29 | * - sharg::value_list_validator 30 | * - sharg::arithmetic_range_validator 31 | * - sharg::input_file_validator 32 | * - sharg::output_file_validator 33 | * - sharg::input_directory_validator 34 | * - sharg::output_directory_validator 35 | */ 36 | 37 | // Groups will appear in order they are defined. 38 | 39 | /*!\defgroup exceptions Exceptions 40 | * \brief The Exceptions Module 41 | */ 42 | 43 | /*!\defgroup validators Validators 44 | * \brief The Validators Module 45 | */ 46 | 47 | /*!\defgroup misc Misc 48 | * \brief The Misc Module 49 | */ 50 | 51 | #pragma once 52 | 53 | #include 54 | #include 55 | #include 56 | #include 57 | -------------------------------------------------------------------------------- /include/sharg/detail/concept.hpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | /*!\file 6 | * \author Svenja Mehringer 7 | * \brief Provides the concept sharg::detail::is_container_option. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace sharg::detail 17 | { 18 | 19 | /*!\concept sharg::detail::is_container_option 20 | * \ingroup misc 21 | * \brief Whether the option type is considered to be a container. 22 | * \details 23 | * 24 | * When adding options or positionial arguments, a distinction needs to be made between container and non-container 25 | * `option_type`s. 26 | * 27 | * In general, all standard library containers except std::string can be considered containers. 28 | * 29 | * In order to be considered a container, the `option_type` must: 30 | * * not be `std::string` 31 | * * define a member type `value_type` 32 | * * provide a member function `push_back(value_type)` 33 | * 34 | * \noapi 35 | */ 36 | // clang-format off 37 | template 38 | concept is_container_option = (!std::is_same_v, std::string>) && 39 | requires (option_type container, 40 | typename std::ranges::range_value_t value) 41 | { 42 | { container.push_back(value) }; 43 | }; 44 | // clang-format on 45 | 46 | } // namespace sharg::detail 47 | -------------------------------------------------------------------------------- /include/sharg/detail/test_accessor.hpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | /*!\file 6 | * \brief Forward declares sharg::detail::test_accessor. 7 | * \author Lydia Buntrock 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | namespace sharg::detail 15 | { 16 | 17 | /*!\brief Attorney-Client pattern for accessing private / protected class members in test cases. 18 | * \ingroup misc 19 | * \attention You can currently only have one definition of test_accessor in one translation unit. 20 | * \see https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Friendship_and_the_Attorney-Client 21 | */ 22 | struct test_accessor; 23 | 24 | } // namespace sharg::detail 25 | -------------------------------------------------------------------------------- /include/sharg/detail/to_string.hpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | /*!\file 6 | * \author Svenja Mehringer 7 | * \brief Provides sharg::detail::to_string. 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | 17 | namespace sharg::detail 18 | { 19 | 20 | //!\brief A string containing all supported export formats. 21 | static std::string const supported_exports = 22 | #if SHARG_HAS_TDL 23 | "[html, man, ctd, cwl]"; 24 | #else 25 | "[html, man]"; 26 | #endif 27 | 28 | //!\brief Concept for views whose value type is ostreamable. 29 | template 30 | concept is_ostreamable_view = std::ranges::view && ostreamable>; 31 | 32 | /*!\brief Streams all parameters via std::ostringstream and returns a concatenated string. 33 | * \ingroup misc 34 | * \tparam value_types Must be sharg::ostreamable (stream << value). 35 | * \param[in] values Variable number of parameters of any type that implement the stream operator. 36 | * \returns A concatenated string of all values (no separator in between is added). 37 | */ 38 | template 39 | requires (ostreamable && ...) 40 | std::string to_string(value_types &&... values) 41 | { 42 | std::stringstream stream; 43 | 44 | auto print = [&stream](auto && val) 45 | { 46 | using value_t = std::remove_cvref_t; 47 | 48 | // When passing a `std::vector | std::views::transform(...)` which returns `std::quoted(str)` for 49 | // each element, the `std::quoted`'s return value does not model a range, but is ostreamable. 50 | if constexpr (is_container_option || is_ostreamable_view) 51 | { 52 | if (val.empty()) 53 | { 54 | stream << "[]"; 55 | } 56 | else 57 | { 58 | stream << '['; 59 | auto it = val.begin(); 60 | stream << *it++; 61 | for (; it != val.end(); ++it) 62 | stream << ", " << *it; 63 | stream << ']'; 64 | } 65 | } 66 | else if constexpr (std::is_same_v || std::is_same_v) 67 | { 68 | stream << static_cast(val); 69 | } 70 | else 71 | { 72 | stream << val; 73 | } 74 | }; 75 | 76 | (print(std::forward(values)), ...); 77 | 78 | return stream.str(); 79 | } 80 | 81 | } // namespace sharg::detail 82 | -------------------------------------------------------------------------------- /include/sharg/platform.hpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | #pragma once 6 | 7 | /*!\file 8 | * \brief Provides platform and dependency checks. 9 | * \author Svenja Mehringer 10 | */ 11 | 12 | // ============================================================================ 13 | // C++ standard and features 14 | // ============================================================================ 15 | 16 | // C++ standard [required] 17 | #ifdef __cplusplus 18 | static_assert(__cplusplus >= 201709L, "SHARG requires C++20, make sure that you have set -std=c++20."); 19 | #else 20 | # error "This is not a C++ compiler." 21 | #endif 22 | 23 | #include 24 | 25 | // ============================================================================ 26 | // Dependencies 27 | // ============================================================================ 28 | 29 | // SHARG [required] 30 | #if __has_include() 31 | # include 32 | #else 33 | # error SHARG include directory not set correctly. Forgot to add -I ${INSTALLDIR}/include to your CXXFLAGS? 34 | #endif 35 | 36 | // ============================================================================ 37 | // Documentation 38 | // ============================================================================ 39 | 40 | // Doxygen related 41 | // this macro is a NO-OP unless doxygen parses it, in which case it resolves to the argument 42 | #ifndef SHARG_DOXYGEN_ONLY 43 | # define SHARG_DOXYGEN_ONLY(x) 44 | #endif 45 | -------------------------------------------------------------------------------- /include/sharg/version.hpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | /*!\file 11 | * \brief Provides SHARG version macros and global variables. 12 | * \author Svenja Mehringer 13 | */ 14 | 15 | //!\brief The major version as MACRO. 16 | #define SHARG_VERSION_MAJOR 1 17 | //!\brief The minor version as MACRO. 18 | #define SHARG_VERSION_MINOR 1 19 | //!\brief The patch version as MACRO. 20 | #define SHARG_VERSION_PATCH 2 21 | //!\brief The release candidate number. 0 means stable release, >= 1 means release candidate. 22 | #define SHARG_RELEASE_CANDIDATE 1 23 | 24 | //!\brief The full version as MACRO (number). 25 | #define SHARG_VERSION (SHARG_VERSION_MAJOR * 10000 + SHARG_VERSION_MINOR * 100 + SHARG_VERSION_PATCH) 26 | 27 | /*!\brief Converts a number to a string. Preprocessor needs this indirection to 28 | * properly expand the values to strings. 29 | */ 30 | #define SHARG_VERSION_CSTRING_HELPER_STR(str) #str 31 | 32 | //!\brief Converts version numbers to string. 33 | #define SHARG_VERSION_CSTRING_HELPER_FUNC(MAJOR, MINOR, PATCH) \ 34 | SHARG_VERSION_CSTRING_HELPER_STR(MAJOR) \ 35 | "." SHARG_VERSION_CSTRING_HELPER_STR(MINOR) "." SHARG_VERSION_CSTRING_HELPER_STR(PATCH) 36 | 37 | #if (SHARG_RELEASE_CANDIDATE > 0) 38 | //!\brief A helper function that expands to a suitable release candidate suffix. 39 | # define SHARG_RELEASE_CANDIDATE_HELPER(RC) "-rc." SHARG_VERSION_CSTRING_HELPER_STR(RC) 40 | #else 41 | //!\brief A helper function that expands to a suitable release candidate suffix. 42 | # define SHARG_RELEASE_CANDIDATE_HELPER(RC) "" 43 | #endif 44 | 45 | //!\brief The full version as null terminated string. 46 | #define SHARG_VERSION_CSTRING \ 47 | SHARG_VERSION_CSTRING_HELPER_FUNC(SHARG_VERSION_MAJOR, SHARG_VERSION_MINOR, SHARG_VERSION_PATCH) \ 48 | SHARG_RELEASE_CANDIDATE_HELPER(SHARG_RELEASE_CANDIDATE) 49 | 50 | namespace sharg 51 | { 52 | 53 | //!\brief The major version. 54 | constexpr uint8_t sharg_version_major = SHARG_VERSION_MAJOR; 55 | //!\brief The minor version. 56 | constexpr uint8_t sharg_version_minor = SHARG_VERSION_MINOR; 57 | //!\brief The patch version. 58 | constexpr uint8_t sharg_version_patch = SHARG_VERSION_PATCH; 59 | 60 | //!\brief The full version as `std::size_t`. 61 | constexpr std::size_t sharg_version = SHARG_VERSION; 62 | 63 | //!\brief The full version as null terminated string. 64 | constexpr char const * sharg_version_cstring = SHARG_VERSION_CSTRING; 65 | 66 | } // namespace sharg 67 | 68 | #undef SHARG_VERSION_CSTRING_HELPER_STR 69 | #undef SHARG_VERSION_CSTRING_HELPER_FUNC 70 | #undef SHARG_RELEASE_CANDIDATE_HELPER 71 | -------------------------------------------------------------------------------- /test/analyse/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.20...3.31) 6 | project (sharg_test_analyze CXX) 7 | 8 | include (../sharg-test.cmake) 9 | 10 | enable_testing () 11 | 12 | add_subdirectory (../snippet snippet) 13 | add_subdirectory (../unit unit) 14 | -------------------------------------------------------------------------------- /test/api_stability/1.0.0/0003-API-FIX-Check-app_name-at-parse.patch: -------------------------------------------------------------------------------- 1 | From ed9fcd579308edef9530ef53d657b59118fe5469 Mon Sep 17 00:00:00 2001 2 | From: Enrico Seiler 3 | Date: Sun, 7 May 2023 13:15:46 +0200 4 | Subject: [PATCH 3/4] [API] [FIX] Check app_name at parse() 5 | 6 | --- 7 | test/unit/parser/parser_design_error_test.cpp | 25 +++++++++++++------ 8 | 1 file changed, 17 insertions(+), 8 deletions(-) 9 | 10 | diff --git a/test/unit/parser/parser_design_error_test.cpp b/test/unit/parser/parser_design_error_test.cpp 11 | index e4725f5..a984ee3 100644 12 | --- a/test/unit/parser/parser_design_error_test.cpp 13 | +++ b/test/unit/parser/parser_design_error_test.cpp 14 | @@ -11,15 +11,24 @@ 15 | 16 | TEST(design_error, app_name_validation) 17 | { 18 | - char const * argv[] = {"./parser_test"}; 19 | - 20 | - EXPECT_NO_THROW((sharg::parser{"test_parser", 1, argv})); 21 | - EXPECT_NO_THROW((sharg::parser{"test-parser1234_foo", 1, argv})); 22 | + char const * argv[] = {"./parser_test", "-i", "3"}; 23 | + int const argc{3}; 24 | + int option_value; 25 | 26 | - EXPECT_THROW((sharg::parser{"test parser", 1, argv}), sharg::design_error); 27 | - EXPECT_THROW((sharg::parser{"test;", 1, argv}), sharg::design_error); 28 | - EXPECT_THROW((sharg::parser{";", 1, argv}), sharg::design_error); 29 | - EXPECT_THROW((sharg::parser{"test;bad script:D", 1, argv}), sharg::design_error); 30 | + auto create_parser = [&](std::string && app_name) 31 | + { 32 | + sharg::parser parser{std::move(app_name), argc, argv, sharg::update_notifications::off}; 33 | + parser.add_option(option_value, sharg::config{.short_id = 'i'}); 34 | + return parser; 35 | + }; 36 | + 37 | + EXPECT_NO_THROW(create_parser("test_parser").parse()); 38 | + EXPECT_NO_THROW(create_parser("test-parser1234_foo").parse()); 39 | + 40 | + EXPECT_THROW(create_parser("test parser").parse(), sharg::design_error); 41 | + EXPECT_THROW(create_parser("test;").parse(), sharg::design_error); 42 | + EXPECT_THROW(create_parser(";").parse(), sharg::design_error); 43 | + EXPECT_THROW(create_parser("test;bad script:D").parse(), sharg::design_error); 44 | } 45 | 46 | // ----------------------------------------------------------------------------- 47 | -- 48 | 2.40.1 49 | 50 | -------------------------------------------------------------------------------- /test/api_stability/1.1.1/0005-INFRA-Use-seqan3-main-branch.patch: -------------------------------------------------------------------------------- 1 | From 2ef2616e6041875e7ca2c376e134addb902ca588 Mon Sep 17 00:00:00 2001 2 | From: Enrico Seiler 3 | Date: Fri, 9 Feb 2024 18:13:36 +0100 4 | Subject: [PATCH 5/9] [INFRA] Use seqan3 main branch 5 | 6 | --- 7 | test/unit/detail/CMakeLists.txt | 2 +- 8 | 1 file changed, 1 insertion(+), 1 deletion(-) 9 | 10 | diff --git a/test/unit/detail/CMakeLists.txt b/test/unit/detail/CMakeLists.txt 11 | index 392f878..1f9a8e0 100644 12 | --- a/test/unit/detail/CMakeLists.txt 13 | +++ b/test/unit/detail/CMakeLists.txt 14 | @@ -23,7 +23,7 @@ sharg_test (type_name_as_string_test.cpp) 15 | sharg_test (version_check_debug_test.cpp) 16 | sharg_test (version_check_release_test.cpp) 17 | 18 | -file (DOWNLOAD https://raw.githubusercontent.com/seqan/seqan3/master/include/seqan3/version.hpp 19 | +file (DOWNLOAD https://raw.githubusercontent.com/seqan/seqan3/main/include/seqan3/version.hpp 20 | ${CMAKE_BINARY_DIR}/include/seqan3/version.hpp) 21 | sharg_test (seqan3_test.cpp) 22 | target_include_directories (seqan3_test SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/include) 23 | -- 24 | 2.49.0 25 | 26 | -------------------------------------------------------------------------------- /test/api_stability/1.1.1/0009-FIX-is_option_set-match-both-long-and-short-ids.patch: -------------------------------------------------------------------------------- 1 | From 0347f577de59a062fc91e633d171de4acc8517df Mon Sep 17 00:00:00 2001 2 | From: Enrico Seiler 3 | Date: Wed, 2 Apr 2025 18:02:31 +0200 4 | Subject: [PATCH 9/9] [FIX] is_option_set: match both long and short ids 5 | 6 | --- 7 | test/unit/parser/format_parse_test.cpp | 4 ++-- 8 | 1 file changed, 2 insertions(+), 2 deletions(-) 9 | 10 | diff --git a/test/unit/parser/format_parse_test.cpp b/test/unit/parser/format_parse_test.cpp 11 | index c2a8f58..8e5b7e2 100644 12 | --- a/test/unit/parser/format_parse_test.cpp 13 | +++ b/test/unit/parser/format_parse_test.cpp 14 | @@ -977,8 +977,8 @@ TEST(parse_test, is_option_set) 15 | EXPECT_TRUE(parser.is_option_set('l')); 16 | EXPECT_TRUE(parser.is_option_set("foobar")); 17 | 18 | - EXPECT_FALSE(parser.is_option_set('f')); 19 | - EXPECT_FALSE(parser.is_option_set("loo")); // --loo is behind the `--` which signals the end of options! 20 | + EXPECT_TRUE(parser.is_option_set('f')); 21 | + EXPECT_TRUE(parser.is_option_set("loo")); // --loo is behind the `--` which signals the end of options! 22 | 23 | // errors: 24 | EXPECT_THROW(parser.is_option_set("l"), sharg::design_error); // short identifiers are passed as chars not strings 25 | -- 26 | 2.49.0 27 | 28 | -------------------------------------------------------------------------------- /test/api_stability/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | project (api_stability) 8 | 9 | if (NOT CMAKE_VERSION VERSION_LESS 3.24) # cmake >= 3.24 10 | cmake_policy (SET CMP0135 NEW) 11 | endif () 12 | 13 | find_package (Git) 14 | 15 | include (../sharg-test.cmake) 16 | 17 | include (ExternalProject) 18 | set (SHARG_LAST_STABLE_VERSION "1.1.1") 19 | set (SHARG_LAST_STABLE_SOURCE_URL 20 | "https://github.com/seqan/sharg-parser/releases/download/${SHARG_LAST_STABLE_VERSION}/sharg-${SHARG_LAST_STABLE_VERSION}-Source.tar.xz" 21 | ) 22 | set (SHARG_LAST_STABLE_SOURCE_SHA256 "7330f06501718e7871e55e5fd70d0e41472cc8b34bd0e3519f8c5547510c671c") 23 | 24 | set (SHARG_API_STABILITY_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSHARG_DISABLE_DEPRECATED_WARNINGS=1") 25 | 26 | macro (sharg_api_stability_test test_suite git_apply) 27 | ExternalProject_Add ( 28 | api_stability_${test_suite} 29 | URL ${SHARG_LAST_STABLE_SOURCE_URL} 30 | URL_HASH SHA256=${SHARG_LAST_STABLE_SOURCE_SHA256} 31 | SOURCE_SUBDIR "test/${test_suite}" 32 | CMAKE_ARGS ${SHARG_EXTERNAL_PROJECT_CMAKE_ARGS} 33 | -DCMAKE_CXX_FLAGS=${SHARG_API_STABILITY_CXX_FLAGS} 34 | -DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER} 35 | -DCMAKE_PREFIX_PATH=${CMAKE_CURRENT_LIST_DIR}/../../cmake # use current build system 36 | -DSHARG_VERBOSE_TESTS=OFF 37 | PATCH_COMMAND ${CMAKE_COMMAND} -E echo "" 38 | COMMAND ${CMAKE_COMMAND} -E remove_directory "/include" 39 | COMMAND ${CMAKE_COMMAND} -E remove_directory "/build_system" 40 | COMMAND ${CMAKE_COMMAND} -E remove_directory "/cmake" 41 | COMMAND sh -c "${git_apply}" 42 | TEST_BEFORE_INSTALL TRUE 43 | TEST_COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -j2 44 | INSTALL_COMMAND "") 45 | endmacro () 46 | 47 | if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/${SHARG_LAST_STABLE_VERSION}") 48 | set (SHARG_GIT_APPLY 49 | "${GIT_EXECUTABLE} init . && ${GIT_EXECUTABLE} apply --verbose ${CMAKE_CURRENT_LIST_DIR}/${SHARG_LAST_STABLE_VERSION}/*.patch" 50 | ) 51 | else () 52 | set (SHARG_GIT_APPLY "true") 53 | message (STATUS "No patches found in ${CMAKE_CURRENT_LIST_DIR}/${SHARG_LAST_STABLE_VERSION}.") 54 | endif () 55 | 56 | sharg_api_stability_test ("snippet" "${SHARG_GIT_APPLY}") 57 | sharg_api_stability_test ("unit" "${SHARG_GIT_APPLY}") 58 | -------------------------------------------------------------------------------- /test/api_stability/REUSE.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2025 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2025 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | version = 1 6 | 7 | [[annotations]] 8 | path = "**/*.patch" 9 | precedence = "aggregate" 10 | SPDX-FileCopyrightText = ["2006-2025, Knut Reinert & Freie Universität Berlin", "2016-2025, Knut Reinert & MPI für molekulare Genetik"] 11 | SPDX-License-Identifier = "BSD-3-Clause" 12 | 13 | -------------------------------------------------------------------------------- /test/cmake/add_subdirectories.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | # Calls add_subdirectory on all (direct) subdirectories of the given directory if they contain a `CMakeLists.txt` 8 | # 9 | # Example: 10 | # If we have 11 | # * /some/path/directory/subdir1/CMakeLists.txt 12 | # * /some/path/directory/subdir2/CMakeLists.txt 13 | # * /some/path/directory/subdir3/CMakeLists.txt 14 | # * /some/path/directory/subdir4/has-no-CMakeLists.txt 15 | # 16 | # This macro calls 17 | # * `add_subdirectory ("/some/path/directory/subdir1")`, 18 | # * `add_subdirectory ("/some/path/directory/subdir2")`, and 19 | # * `add_subdirectory ("/some/path/directory/subdir3")`, 20 | # but not `add_subdirectory ("/some/path/directory/subdir4")`, because it does not contain a CMakeLists.txt 21 | macro (add_subdirectories_of directory) 22 | file (GLOB ENTRIES 23 | RELATIVE ${directory} 24 | ${directory}/[!.]*) 25 | 26 | foreach (ENTRY ${ENTRIES}) 27 | if (IS_DIRECTORY ${directory}/${ENTRY}) 28 | if (EXISTS ${directory}/${ENTRY}/CMakeLists.txt) 29 | add_subdirectory (${directory}/${ENTRY} ${CMAKE_CURRENT_BINARY_DIR}/${ENTRY}) 30 | endif () 31 | endif () 32 | endforeach () 33 | unset (ENTRIES) 34 | endmacro () 35 | 36 | macro (add_subdirectories) 37 | add_subdirectories_of (${CMAKE_CURRENT_SOURCE_DIR}) 38 | endmacro () 39 | -------------------------------------------------------------------------------- /test/cmake/diagnostics/list_missing_unit_tests.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | set (sharg_test_include_targets 8 | "" 9 | CACHE STRING "" FORCE) 10 | 11 | function (collect_include_target include_target) 12 | set (sharg_test_include_targets 13 | "${sharg_test_include_targets};${include_target}" 14 | CACHE STRING "" FORCE) 15 | endfunction () 16 | 17 | function (list_missing_unit_tests) 18 | list (SORT sharg_test_include_targets) 19 | foreach (include_target ${sharg_test_include_targets}) 20 | if (NOT TARGET ${include_target}) 21 | continue () 22 | endif () 23 | 24 | get_target_property (dependencies ${include_target} MANUALLY_ADDED_DEPENDENCIES) 25 | 26 | # if include_target has dependencies that means a test must be associated with it 27 | # => so this include_target has no missing tests 28 | if (dependencies) 29 | continue () 30 | endif () 31 | 32 | string (REPLACE "-" "/" header ${include_target}) 33 | string (REPLACE "_test" ".hpp" header ${header}) 34 | 35 | get_filename_component (header_filename "${header}" NAME) 36 | 37 | # skip these headers 38 | if (header_filename MATCHES "all.hpp|concept.hpp") 39 | continue () 40 | endif () 41 | 42 | message (STATUS "header '${header}' is missing a test") 43 | endforeach () 44 | endfunction () 45 | -------------------------------------------------------------------------------- /test/cmake/diagnostics/list_unused_snippets.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | set (sharg_test_snippets 8 | "" 9 | CACHE STRING "" FORCE) 10 | 11 | include ("${CMAKE_CURRENT_LIST_DIR}/../sharg_path_longest_stem.cmake") 12 | include ("${CMAKE_CURRENT_LIST_DIR}/../sharg_test_files.cmake") 13 | 14 | # Add the `target` to the list of used test targets. This effectively marks the `target` as a used test. 15 | function (collect_used_snippet target) 16 | set (sharg_test_snippets 17 | "${sharg_test_snippets};${target}" 18 | CACHE STRING "" FORCE) 19 | endfunction () 20 | 21 | # Glob all snippet output files (e.g. *.out and *.err files) and compare them to the list of used snippet outputs. 22 | function (list_unused_snippets snippet_base_path) 23 | sharg_test_files (test_snippet_output_glob_list "${snippet_base_path}" "*.out;*.err") 24 | set (test_snippet_output_list "") 25 | 26 | # get the source location of each "used" test target and collect it. 27 | foreach (test_target ${sharg_test_snippets}) 28 | # e.g. /seqan3/test/snippet/../../doc/tutorial/pairwise_alignment/configurations.cpp 29 | get_target_property (source "${test_target}" SOURCES) 30 | # e.g. configurations 31 | sharg_path_longest_stem (source_wle "${source}") 32 | # e.g. /seqan3/test/snippet/../../doc/tutorial/pairwise_alignment 33 | get_filename_component (source_dir "${source}" DIRECTORY) 34 | # e.g. ../../doc/tutorial/pairwise_alignment 35 | file (RELATIVE_PATH source_relative_stem "${snippet_base_path}" "${source_dir}/${source_wle}") 36 | 37 | # test_snippet_output_list adds all potential cout / cerr files even if they don't really exist 38 | # This list will be subtracted from the real list of files, so it can contain "more" without changing the 39 | # result. 40 | list (APPEND test_snippet_output_list "${source_relative_stem}.out") 41 | list (APPEND test_snippet_output_list "${source_relative_stem}.err") 42 | endforeach () 43 | 44 | # create the difference between test_snippet_output_glob_list set and test_snippet_output_list set. 45 | list (REMOVE_ITEM test_snippet_output_glob_list ${test_snippet_output_list}) 46 | 47 | # list all unused tests 48 | foreach (test_snippet_output ${test_snippet_output_glob_list}) 49 | message (AUTHOR_WARNING "'${snippet_base_path}/${test_snippet_output}' snippet output exists, " 50 | "but the corresponding .cpp file is missing!") 51 | endforeach () 52 | endfunction () 53 | -------------------------------------------------------------------------------- /test/cmake/diagnostics/list_unused_unit_tests.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | set (sharg_test_targets 8 | "" 9 | CACHE STRING "" FORCE) 10 | 11 | # Add the `target` to the list of used test targets. This effectively marks the `target` as a used test. 12 | function (collect_used_test target) 13 | set (sharg_test_targets 14 | "${sharg_test_targets};${target}" 15 | CACHE STRING "" FORCE) 16 | endfunction () 17 | 18 | # Glob all test files (e.g. *.cpp files) and compare them to the list of used test targets. 19 | function (list_unused_unit_tests) 20 | file (GLOB_RECURSE test_source_glob_list *.cpp) 21 | set (test_source_declared_list "") 22 | 23 | # get the source location of each "used" test target and collect it. 24 | foreach (test_target ${sharg_test_targets}) 25 | get_target_property (sources "${test_target}" SOURCES) 26 | get_target_property (source_dir "${test_target}" SOURCE_DIR) 27 | 28 | list (APPEND test_source_declared_list "${source_dir}/${sources}") 29 | endforeach () 30 | 31 | # create the difference between test_source_glob_list set and test_source_declared_list set. 32 | list (REMOVE_ITEM test_source_glob_list ${test_source_declared_list}) 33 | 34 | # list all unused tests 35 | foreach (test_source ${test_source_glob_list}) 36 | message (WARNING "'${test_source}' test exists, but was not defined by sharg_test(...)") 37 | endforeach () 38 | endfunction () 39 | -------------------------------------------------------------------------------- /test/cmake/sharg_generate_snippet.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | # Generate snippets from a source_snippet 8 | # 9 | # Example: 10 | # sharg_generate_snippet("<..>/@target_alphabet@_implicit_conversion_from_@source_alphabet@.cpp.in" 11 | # -Dtarget_alphabet=dna4 12 | # -Dsource_alphabet=rna4) 13 | # 14 | # Will generate a snippet in the same directory as the source_snippet. 15 | # 16 | # The generated snippet 17 | # * will be <..>/dna4_implicit_conversion_from_rna4.cpp 18 | # * the @placeholder@ will be replaced by the specified `-Dplaceholder=value` value 19 | # * the .in ending will be stripped 20 | # 21 | # In the source_snippet 22 | # * all ${placeholder} will be replaced by the specified `-Dplaceholder=value` value 23 | # * see `cmake`s [configure_file](https://cmake.org/cmake/help/latest/command/configure_file.html) for more detail 24 | function (sharg_generate_snippet source_snippet) 25 | if (NOT SHARG_CLONE_DIR) 26 | message (AUTHOR_WARNING "sharg_generate_snippet can't be used if " 27 | "SHARG_CLONE_DIR (i.e. no git checkout) is not defined.") 28 | return () 29 | endif () 30 | # e.g. source_snippet: <...>/@target_alphabet@_implicit_conversion_from_@source_alphabet@.cpp.in 31 | 32 | foreach (definition IN LISTS ARGN) 33 | # e.g. definition -Dsource_alphabet=rna4 34 | if (definition MATCHES "-D(.+)=(.+)") 35 | # e.g. CMAKE_MATCH_1: source_alphabet and CMAKE_MATCH_2: rna4 36 | # i.e. set ("source_alphabet" "rna4") 37 | set ("${CMAKE_MATCH_1}" "${CMAKE_MATCH_2}") 38 | endif () 39 | endforeach () 40 | 41 | # remove .in file ending 42 | # e.g. <...>/@target_alphabet@_implicit_conversion_from_@source_alphabet@.cpp.in 43 | # to: <...>/@target_alphabet@_implicit_conversion_from_@source_alphabet@.cpp 44 | string (REGEX REPLACE ".in$" "" target_snippet "${source_snippet}") 45 | 46 | # substitute @variable@s 47 | # 48 | # substitute 49 | # <...>/@target_alphabet@_implicit_conversion_from_@source_alphabet@.cpp 50 | # by e.g. target_alphabet: dna4 and source_alphabet: rna4 51 | # <...>/dna4_implicit_conversion_from_rna4.cpp 52 | string (CONFIGURE "${target_snippet}" target_snippet @ONLY) 53 | 54 | # substitute source_snippet with all definitions 55 | configure_file ("${SHARG_CLONE_DIR}/${source_snippet}" "${SHARG_CLONE_DIR}/${target_snippet}") 56 | endfunction () 57 | -------------------------------------------------------------------------------- /test/cmake/sharg_path_longest_stem.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | # A compatible function for cmake < 3.20 that basically returns `cmake_path (GET STEM LAST_ONLY )` 8 | function (sharg_path_longest_stem out_var filename) 9 | if (CMAKE_VERSION VERSION_LESS 3.20) # cmake < 3.20 10 | get_filename_component (result "${filename}" NAME) 11 | if (result MATCHES "\\.") 12 | string (REGEX REPLACE "(.+)[.].*" "\\1" result "${result}") 13 | endif () 14 | else () # cmake >= 3.20 15 | cmake_path (GET filename STEM LAST_ONLY result) 16 | endif () 17 | 18 | set ("${out_var}" 19 | "${result}" 20 | PARENT_SCOPE) # out-var 21 | endfunction () 22 | 23 | # ====== 24 | # TESTS 25 | # ====== 26 | 27 | sharg_path_longest_stem (sharg_cmake_test_path "/a/b/c/") 28 | if (NOT sharg_cmake_test_path STREQUAL "") 29 | message (FATAL_ERROR "internal error: '${sharg_cmake_test_path}' vs '', " 30 | "sharg_path_longest_stem produces wrong result") 31 | endif () 32 | 33 | sharg_path_longest_stem (sharg_cmake_test_path "/a/b/c/hello") 34 | if (NOT sharg_cmake_test_path STREQUAL "hello") 35 | message (FATAL_ERROR "internal error: '${sharg_cmake_test_path}' vs 'hello', " 36 | "sharg_path_longest_stem produces wrong result") 37 | endif () 38 | 39 | sharg_path_longest_stem (sharg_cmake_test_path "/a/b/c/hello.cpp") 40 | if (NOT sharg_cmake_test_path STREQUAL "hello") 41 | message (FATAL_ERROR "internal error: '${sharg_cmake_test_path}' vs 'hello', " 42 | "sharg_path_longest_stem produces wrong result") 43 | endif () 44 | 45 | sharg_path_longest_stem (sharg_cmake_test_path "/a/b/c/hello.world.cpp") 46 | if (NOT sharg_cmake_test_path STREQUAL "hello.world") 47 | message (FATAL_ERROR "internal error: '${sharg_cmake_test_path}' vs 'hello.world', " 48 | "sharg_path_longest_stem produces wrong result") 49 | endif () 50 | -------------------------------------------------------------------------------- /test/cmake/sharg_require_ccache.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # This file's only purpose is to be replaced with the content of the use_ccache CMakeLists.txt file 6 | # when creating the source package. 7 | CPMGetPackage (use_ccache) 8 | -------------------------------------------------------------------------------- /test/cmake/sharg_test_component.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | include (sharg_path_longest_stem) 8 | 9 | # Get a specific component of a test file which follows the seqan3 naming scheme. 10 | # e.g. target_source_file = "range/views/take.cpp" 11 | # component: 12 | # * TARGET_NAME - the target name (e.g. "take") 13 | # * TARGET_UNIQUE_NAME - the target name which includes the target_path (e.g. range-view-take) 14 | # * TEST_NAME - the test name which includes the target_path (e.g. "range/views/take") 15 | # * TARGET_PATH - the path to the target source (e.g. "range/view") 16 | macro (sharg_test_component VAR target_source_file component_name_) 17 | string (TOUPPER "${component_name_}" component_name) 18 | 19 | get_filename_component (target_relative_path "${target_source_file}" DIRECTORY) 20 | sharg_path_longest_stem (target_name "${target_source_file}") 21 | 22 | if (component_name STREQUAL "TARGET_NAME") 23 | set (${VAR} "${target_name}") 24 | elseif (component_name MATCHES "TEST_NAME|TARGET_UNIQUE_NAME") 25 | if (target_relative_path) 26 | set (${VAR} "${target_relative_path}/${target_name}") 27 | else () 28 | set (${VAR} "${target_name}") 29 | endif () 30 | 31 | if (component_name STREQUAL "TARGET_UNIQUE_NAME") 32 | string (REPLACE "/" "-" ${VAR} "${${VAR}}") 33 | endif () 34 | elseif (component_name STREQUAL "TARGET_PATH") 35 | set (${VAR} "${target_relative_path}") 36 | endif () 37 | 38 | unset (target_name) 39 | unset (target_relative_path) 40 | endmacro () 41 | -------------------------------------------------------------------------------- /test/cmake/sharg_test_files.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | # Finds all files relative to the `test_base_path_` which satisfy the given file pattern. 8 | # 9 | # Example: 10 | # sharg_test_files (header_files "/seqan3/include" "*.hpp;*.h") 11 | # 12 | # The variable `header_files` will contain: 13 | # seqan3/alphabet/adaptation/all.hpp 14 | # seqan3/alphabet/adaptation/char.hpp 15 | # seqan3/alphabet/adaptation/concept.hpp 16 | # seqan3/alphabet/adaptation/uint.hpp 17 | # seqan3/alphabet/all.hpp 18 | # seqan3/alphabet/dna5_detail.hpp 19 | # .... 20 | macro (sharg_test_files VAR test_base_path_ extension_wildcards) 21 | # test_base_path is /home/.../seqan3/test/ 22 | get_filename_component (test_base_path "${test_base_path_}" ABSOLUTE) 23 | file (RELATIVE_PATH test_base_path_relative "${CMAKE_CURRENT_SOURCE_DIR}" "${test_base_path}") 24 | # ./ is a hack to deal with empty test_base_path_relative 25 | set (test_base_path_relative "./${test_base_path_relative}") 26 | # collect all cpp files 27 | set (${VAR} "") 28 | foreach (extension_wildcard ${extension_wildcards}) 29 | file (GLOB_RECURSE test_files 30 | RELATIVE "${test_base_path}" 31 | "${test_base_path_relative}/${extension_wildcard}") 32 | list (APPEND ${VAR} ${test_files}) 33 | endforeach () 34 | 35 | unset (test_base_path) 36 | unset (test_base_path_relative) 37 | endmacro () 38 | -------------------------------------------------------------------------------- /test/coverage/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.10...3.22) 6 | project (sharg_test_coverage CXX) 7 | 8 | # Add a custom build type: Coverage 9 | # 10 | # `--coverage` is equivalent to `-fprofile-arcs -ftest-coverage` 11 | # https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-gcov 12 | # 13 | # `-fprofile-update=atomic` prevents profile corruption in multi-threaded tests 14 | # https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fprofile-update 15 | # 16 | # `-fprofile-abs-path` converts relative source file names to absolute paths in the coverage files 17 | # https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fprofile-abs-path 18 | 19 | set (CMAKE_CXX_FLAGS_COVERAGE 20 | "${CMAKE_CXX_FLAGS_DEBUG} --coverage -g -O0 -fprofile-abs-path -fprofile-update=atomic" 21 | CACHE STRING "Flags used by the C++ compiler during coverage builds." FORCE) 22 | set (CMAKE_C_FLAGS_COVERAGE 23 | "${CMAKE_C_FLAGS_DEBUG} --coverage -g -O0 -fprofile-abs-path -fprofile-update=atomic" 24 | CACHE STRING "Flags used by the C compiler during coverage builds." FORCE) 25 | set (CMAKE_EXE_LINKER_FLAGS_COVERAGE 26 | "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -Wl,-lgcov" 27 | CACHE STRING "Flags used for linking binaries during coverage builds." FORCE) 28 | set (CMAKE_SHARED_LINKER_FLAGS_COVERAGE 29 | "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -Wl,-lgcov" 30 | CACHE STRING "Flags used by the shared libraries linker during coverage builds." FORCE) 31 | 32 | mark_as_advanced (CMAKE_CXX_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE CMAKE_EXE_LINKER_FLAGS_COVERAGE 33 | CMAKE_SHARED_LINKER_FLAGS_COVERAGE) 34 | 35 | enable_testing () 36 | add_subdirectory ("../unit" "${CMAKE_CURRENT_BINARY_DIR}/unit") 37 | -------------------------------------------------------------------------------- /test/documentation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # Minimum cmake version 6 | cmake_minimum_required (VERSION 3.12) 7 | 8 | ### Find sharg 9 | include (../../cmake/sharg-config-version.cmake) 10 | set (SHARG_VERSION "${PACKAGE_VERSION}") 11 | 12 | # ---------------------------------------------------------------------------- 13 | # CPM 14 | # ---------------------------------------------------------------------------- 15 | 16 | # This will be true for git clones and source packages. 17 | if (EXISTS "${SHARG_INCLUDE_DIR}/../cmake/CPM.cmake") 18 | set (SHARG_HAS_CPM TRUE) 19 | else () 20 | set (SHARG_HAS_CPM FALSE) 21 | endif () 22 | 23 | if (SHARG_HAS_CPM) 24 | set (CPM_INDENT "CMake Package Manager CPM: ") 25 | include ("${SHARG_INCLUDE_DIR}/../cmake/CPM.cmake") 26 | CPMUsePackageLock ("${SHARG_INCLUDE_DIR}/../cmake/package-lock.cmake") 27 | endif () 28 | 29 | project (sharg 30 | LANGUAGES NONE 31 | VERSION "${SHARG_PROJECT_VERSION}") 32 | 33 | if (NOT EXISTS "${SHARG_INCLUDE_DIR}/sharg/version.hpp") 34 | message (FATAL_ERROR "Could not find sharg. Not building documentation.") 35 | endif () 36 | message (STATUS "Found: ${SHARG_INCLUDE_DIR} (${SHARG_VERSION})") 37 | 38 | if (SHARG_HAS_CPM) 39 | CPMGetPackage (doxygen_awesome) 40 | else () 41 | message (FATAL_ERROR "Could not find doxygen-awesome. Not building documentation.") 42 | endif () 43 | message (STATUS "Found: ${doxygen_awesome_SOURCE_DIR}") 44 | 45 | set (SHARG_DOXYGEN_INPUT_DIR "${CMAKE_SOURCE_DIR}") 46 | 47 | include (sharg-doxygen.cmake) 48 | 49 | enable_testing () 50 | 51 | if (SHARG_USER_DOC) 52 | add_subdirectory (doc_usr) 53 | endif () 54 | 55 | if (SHARG_DEV_DOC) 56 | add_subdirectory (doc_dev) 57 | endif () 58 | 59 | include (sharg-doxygen-package.cmake) 60 | -------------------------------------------------------------------------------- /test/documentation/api-stability.js: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | /* Enrico Seiler (enrico.seiler@fu-berlin.de), 2021 */ 6 | 7 | $(document).ready(function() 8 | { 9 | var add_mlabel = function() 10 | { 11 | var memname_html = $(this).find('table.memname').prop('outerHTML'); 12 | var new_html = "
" + 13 | memname_html + 14 | " " + 15 | "
"; 16 | 17 | $(this).find('div.memproto').html(new_html); 18 | } 19 | 20 | var add_labels = function(api_type, entry_type) 21 | { 22 | if (entry_type == "member") 23 | { 24 | $(this).find('span.mlabels').prepend('' + api_type + ''); 25 | 26 | // get header above the item, append the api_type tag to the header and change the style class 27 | var header = $(this).prev('h2.memtitle')[0]; 28 | header.append(' [' + api_type + '] '); 29 | header.className += ' ' + api_type; 30 | } 31 | else if (entry_type == "header") 32 | { 33 | $('h2.groupheader:contains("Detailed Description")').append('' + api_type + ''); 34 | } 35 | } 36 | 37 | var select_and_add_label = function(entry_obj, entry_type) 38 | { 39 | var is_no_api = $(entry_obj).find('dl.no-api').length; 40 | var is_experimental_api = $(entry_obj).find('dl.experimental-api').length; 41 | var is_stable_api = $(entry_obj).find('dl.stable-api').length; 42 | var has_mlabels = $(this).find('span.mlabels').length; 43 | 44 | if (!has_mlabels) 45 | add_mlabel.call(this); 46 | 47 | if (is_no_api) 48 | add_labels.call(this, "no-api", entry_type); 49 | else if (is_experimental_api) 50 | add_labels.call(this, "experimental-api", entry_type); 51 | else if (is_stable_api) 52 | add_labels.call(this, "stable-api", entry_type); 53 | else 54 | add_labels.call(this, "no-api", entry_type); 55 | } 56 | 57 | // Badges for members 58 | $('div.memitem').each(function(index) 59 | { 60 | select_and_add_label.call(this, this, "member"); 61 | }); 62 | 63 | }); 64 | -------------------------------------------------------------------------------- /test/documentation/doc_dev/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | message (STATUS "Configuring devel doc.") 6 | 7 | set (SHARG_DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}") 8 | set (SHARG_DOXYGEN_EXCLUDE_SYMBOLS "") 9 | set (SHARG_DOXYGEN_PREDEFINED_NDEBUG "") 10 | set (SHARG_DOXYGEN_ENABLED_SECTIONS "DEV") 11 | set (SHARG_SHOW_DEV_GROUP "YES") 12 | set (SHARG_DOXYGEN_EXTRACT_PRIVATE "YES") 13 | 14 | configure_file (${SHARG_DOXYFILE_IN} ${SHARG_DOXYGEN_OUTPUT_DIR}/Doxyfile) 15 | configure_file (${SHARG_FOOTER_HTML_IN} ${SHARG_DOXYGEN_OUTPUT_DIR}/sharg_footer.html) 16 | configure_file (${SHARG_LAYOUT_IN} ${SHARG_DOXYGEN_OUTPUT_DIR}/DoxygenLayout.xml) 17 | 18 | add_custom_target (doc_dev ALL 19 | COMMAND ${DOXYGEN_EXECUTABLE} 20 | WORKING_DIRECTORY ${SHARG_DOXYGEN_OUTPUT_DIR} 21 | BYPRODUCTS html/ 22 | DEPENDS download-cppreference-doxygen-web-tag 23 | COMMENT "Generating developer API documentation with Doxygen" 24 | VERBATIM) 25 | 26 | # Install doc_dev documentation in ./install_doc_dev folder 27 | # cmake --install . --prefix install_doc_dev --component doc_dev 28 | install (DIRECTORY "${SHARG_DOXYGEN_OUTPUT_DIR}/html" 29 | DESTINATION "${CMAKE_INSTALL_DOCDIR}" 30 | COMPONENT doc-dev 31 | EXCLUDE_FROM_ALL 32 | PATTERN "*.md5" EXCLUDE 33 | PATTERN "*.map" EXCLUDE 34 | PATTERN "formula.repository" EXCLUDE) 35 | 36 | ### Enable testing 37 | 38 | enable_testing () 39 | 40 | message (STATUS "Add dev doc test.") 41 | add_test (NAME doc_dev_no_warnings_test 42 | COMMAND bash -c "${SHARG_TEST_DOXYGEN_FAIL_ON_WARNINGS}" 43 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 44 | set_tests_properties (doc_dev_no_warnings_test PROPERTIES DEPENDS cppreference-doxygen-web-tag) 45 | -------------------------------------------------------------------------------- /test/documentation/doc_usr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | message (STATUS "Configuring user doc.") 6 | 7 | set (SHARG_DOXYGEN_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}") 8 | set (SHARG_DOXYGEN_EXCLUDE_SYMBOLS "detail sharg::simd") #/"" 9 | set (SHARG_DOXYGEN_PREDEFINED_NDEBUG "-NDEBUG") #/"" 10 | set (SHARG_DOXYGEN_ENABLED_SECTIONS "") #/"DEV" 11 | set (SHARG_SHOW_DEV_GROUP "NO") #/"YES" 12 | set (SHARG_DOXYGEN_EXTRACT_PRIVATE "NO") #/"YES": 13 | 14 | configure_file (${SHARG_DOXYFILE_IN} ${SHARG_DOXYGEN_OUTPUT_DIR}/Doxyfile) 15 | configure_file (${SHARG_FOOTER_HTML_IN} ${SHARG_DOXYGEN_OUTPUT_DIR}/sharg_footer.html) 16 | configure_file (${SHARG_LAYOUT_IN} ${SHARG_DOXYGEN_OUTPUT_DIR}/DoxygenLayout.xml) 17 | 18 | add_custom_target (doc_usr ALL 19 | COMMAND ${DOXYGEN_EXECUTABLE} 20 | WORKING_DIRECTORY ${SHARG_DOXYGEN_OUTPUT_DIR} 21 | BYPRODUCTS html/ 22 | DEPENDS download-cppreference-doxygen-web-tag 23 | COMMENT "Generating user API documentation with Doxygen" 24 | VERBATIM) 25 | 26 | # Install doc_usr documentation in ./export folder 27 | # make DESTDIR=export install 28 | install (DIRECTORY "${SHARG_DOXYGEN_OUTPUT_DIR}/html" 29 | DESTINATION "${CMAKE_INSTALL_DOCDIR}" 30 | COMPONENT doc 31 | PATTERN "*.md5" EXCLUDE 32 | PATTERN "*.map" EXCLUDE 33 | PATTERN "formula.repository" EXCLUDE) 34 | 35 | ### Enable testing 36 | 37 | enable_testing () 38 | 39 | message (STATUS "Add user doc test.") 40 | add_test (NAME doc_usr_no_warnings_test COMMAND bash -c "${SHARG_TEST_DOXYGEN_FAIL_ON_WARNINGS}") 41 | set_tests_properties (doc_usr_no_warnings_test PROPERTIES DEPENDS cppreference-doxygen-web-tag) 42 | -------------------------------------------------------------------------------- /test/documentation/sharg-doxygen-package.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | set (CPACK_GENERATOR "TXZ") 8 | 9 | set (CPACK_COMPONENTS_ALL doc) 10 | 11 | set (CPACK_ARCHIVE_COMPONENT_INSTALL ON) 12 | 13 | set (CPACK_PACKAGE_VENDOR "sharg") 14 | # A description of the project, used in places such as the introduction screen of CPack-generated Windows installers. 15 | # set (CPACK_PACKAGE_DESCRIPTION_FILE "") # TODO 16 | set (CPACK_PACKAGE_CHECKSUM "SHA256") 17 | 18 | include (CPack) 19 | -------------------------------------------------------------------------------- /test/documentation/sharg_footer.html.in: -------------------------------------------------------------------------------- 1 | 5 | 6 | 8 | 9 | 10 |
Hide me
11 | 12 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /test/documentation/sharg_logo.svg.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: BSD-3-Clause 4 | -------------------------------------------------------------------------------- /test/documentation/version.js: -------------------------------------------------------------------------------- 1 | /* SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: BSD-3-Clause 4 | */ 5 | /* Jongkyu Kim (j.kim@fu-berlin.de), 2016.01.12 6 | Adaptations by Enrico Seiler (enrico.seiler@fu-berlin.de), 2020 */ 7 | 8 | function changeVersion(form_id) 9 | { 10 | // Get the base url without version information, e.g. "https://docs.seqan.de/seqan" 11 | var current_script_url = document.scripts[document.scripts.length - 1].src; 12 | var base_url = current_script_url.split('/').slice(0, -2).join('/'); 13 | 14 | // Get the current page, e.g. "index.html" 15 | var full_url = window.top.location.href; 16 | var current_page = full_url.substring(full_url.lastIndexOf("/") + 1); 17 | 18 | // Get the selected version 19 | var form = document.getElementById(form_id); 20 | var version = form.options[form.selectedIndex].value; 21 | 22 | // Check if the current page is valid with the selected version 23 | var proposed_url = base_url + '/' + version + '/' + current_page; 24 | var request = new XMLHttpRequest(); 25 | request.open('GET', proposed_url, false); 26 | request.send(); 27 | // If the URL is invalid, redirect to main page of the selected version 28 | // If htaccess is configured to redirect invalid URLs to the base domain, 29 | // no 404 is returned, hence the second condition 30 | if (request.status === 404 || request.responseURL == window.location.origin + '/') 31 | { 32 | proposed_url = base_url + '/' + version; 33 | } 34 | 35 | // Load the proper page 36 | window.top.location.href = proposed_url; 37 | } 38 | 39 | function addVersionSelection(arr) 40 | { 41 | // add HTMLs 42 | var version_select = document.createElement("select"); 43 | version_select.setAttribute("id","version_select"); 44 | version_select.setAttribute("style","color: var(--page-foreground-color);"); 45 | document.getElementById("list_bottom_right").appendChild(version_select); 46 | 47 | version_select.addEventListener("change", function(){changeVersion(this.id);}, false); 48 | 49 | // current selection is.. 50 | cur_sel = window.location.pathname.split("/").at(-2); 51 | 52 | for(i=0; i < arr.length; ++i) 53 | { 54 | var op = document.createElement("option"); 55 | op.value = arr[i]; 56 | op.text = arr[i]; 57 | op.selected = ( arr[i] == cur_sel ) ? true : false; 58 | version_select.add(op); 59 | } 60 | } 61 | 62 | // get JSON data & add selection form 63 | var request = new XMLHttpRequest(); 64 | request.open("GET", "version.php", true); 65 | request.setRequestHeader("Content-type", "application/json"); 66 | request.onreadystatechange = function() 67 | { 68 | if( request.readyState == 4 && request.status == 200 ) 69 | { 70 | var response = JSON.parse(request.responseText); 71 | addVersionSelection(response); // add selection form 72 | } 73 | } 74 | request.send(); 75 | -------------------------------------------------------------------------------- /test/documentation/version.php: -------------------------------------------------------------------------------- 1 | 28 | -------------------------------------------------------------------------------- /test/external_project/find-package-diagnostics.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | # list all search places 6 | # NOTE: this can be enabled globally by -DSHARG_EXTERNAL_PROJECT_FIND_DEBUG_MODE=1 to help debug search paths 7 | # set (CMAKE_FIND_DEBUG_MODE ${SHARG_EXTERNAL_PROJECT_FIND_DEBUG_MODE}) 8 | 9 | macro (sharg_print_diagnostics text) 10 | message (STATUS " ${text}") 11 | endmacro () 12 | 13 | message (STATUS "=== SHARG find_package Diagnostics start ===") 14 | sharg_print_diagnostics ("CMAKE_COMMAND: ${CMAKE_COMMAND}") 15 | sharg_print_diagnostics ("CMAKE_VERSION: ${CMAKE_VERSION}") 16 | sharg_print_diagnostics ("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") 17 | 18 | sharg_print_diagnostics ( 19 | "Search paths (https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure)") 20 | sharg_print_diagnostics ("1) CMAKE_FIND_USE_PACKAGE_ROOT_PATH: ${CMAKE_FIND_USE_CMAKE_PATH}") 21 | sharg_print_diagnostics (" SHARG_ROOT: ${SHARG_ROOT}") 22 | 23 | sharg_print_diagnostics ("2) CMAKE_FIND_USE_CMAKE_PATH: ${CMAKE_FIND_USE_CMAKE_PATH}") 24 | sharg_print_diagnostics (" CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}") 25 | sharg_print_diagnostics (" CMAKE_FRAMEWORK_PATH: ${CMAKE_FRAMEWORK_PATH}") 26 | sharg_print_diagnostics (" CMAKE_APPBUNDLE_PATH: ${CMAKE_APPBUNDLE_PATH}") 27 | 28 | sharg_print_diagnostics ("3) CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: ${CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH}") 29 | sharg_print_diagnostics (" SHARG_DIR: ${SHARG_DIR}") 30 | 31 | # 4) Using the HINTS option. 32 | # See point 4 in https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure. 33 | # There is no output. 34 | 35 | sharg_print_diagnostics ("5) CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: ${CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH}") 36 | 37 | sharg_print_diagnostics ("6) CMAKE_FIND_USE_PACKAGE_REGISTRY: ${CMAKE_FIND_USE_PACKAGE_REGISTRY}") 38 | 39 | sharg_print_diagnostics ("7) CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: ${CMAKE_FIND_USE_CMAKE_SYSTEM_PATH}") 40 | sharg_print_diagnostics (" CMAKE_SYSTEM_PREFIX_PATH: ${CMAKE_SYSTEM_PREFIX_PATH}") 41 | sharg_print_diagnostics (" CMAKE_SYSTEM_FRAMEWORK_PATH: ${CMAKE_SYSTEM_FRAMEWORK_PATH}") 42 | sharg_print_diagnostics (" CMAKE_SYSTEM_APPBUNDLE_PATH: ${CMAKE_SYSTEM_APPBUNDLE_PATH}") 43 | 44 | sharg_print_diagnostics ("8) CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY: ${CMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY}") 45 | message (STATUS "=== SHARG find_package Diagnostics end ===") 46 | -------------------------------------------------------------------------------- /test/external_project/install-sharg.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.14) 6 | 7 | # install and package sharg library 8 | ExternalProject_Add ( 9 | sharg_test_prerequisite 10 | PREFIX sharg_test_prerequisite 11 | SOURCE_DIR "${SHARG_ROOT}" 12 | CMAKE_ARGS ${SHARG_EXTERNAL_PROJECT_CMAKE_ARGS} # 13 | "-DCMAKE_INSTALL_PREFIX=/usr" 14 | STEP_TARGETS configure install 15 | BUILD_BYPRODUCTS "/include") 16 | 17 | set (SHARG_PACKAGE_ZIP_URL "${PROJECT_BINARY_DIR}/sharg-${SHARG_VERSION}-${CMAKE_SYSTEM_NAME}.zip") 18 | ExternalProject_Add_Step ( 19 | sharg_test_prerequisite package 20 | COMMAND ${CMAKE_CPACK_COMMAND} -G ZIP -B "${PROJECT_BINARY_DIR}" 21 | DEPENDEES configure install 22 | WORKING_DIRECTORY "" 23 | BYPRODUCTS ${SHARG_PACKAGE_ZIP_URL} # 24 | "${SHARG_PACKAGE_ZIP_URL}.sha256") 25 | 26 | ExternalProject_Get_Property (sharg_test_prerequisite BINARY_DIR) 27 | set (SHARG_SYSTEM_PREFIX "${BINARY_DIR}/usr") 28 | -------------------------------------------------------------------------------- /test/external_project/sharg_fetch_content_zip/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.14) 6 | project (sharg_app CXX) 7 | 8 | # --- helper scripts 9 | include (../find-package-diagnostics.cmake) 10 | file (SHA256 "${SHARG_PACKAGE_ZIP_URL}" SHARG_PACKAGE_ZIP_HASH) 11 | message (STATUS "SHARG_PACKAGE_ZIP_URL: ${SHARG_PACKAGE_ZIP_URL}") 12 | message (STATUS "SHARG_PACKAGE_ZIP_HASH: SHA256=${SHARG_PACKAGE_ZIP_HASH}") 13 | # --- 14 | 15 | # fetch sharg sources (requires >= cmake 3.14) 16 | include (FetchContent) 17 | FetchContent_Declare ( 18 | sharg 19 | URL "${SHARG_PACKAGE_ZIP_URL}" # change these values 20 | URL_HASH "SHA256=${SHARG_PACKAGE_ZIP_HASH}" # change these values 21 | ) 22 | FetchContent_MakeAvailable (sharg) 23 | 24 | # add sharg to search path 25 | list (APPEND CMAKE_PREFIX_PATH "${sharg_SOURCE_DIR}") 26 | 27 | # require sharg with a version between >=1.0.0 and <2.0.0 28 | find_package (sharg 1.0 REQUIRED) 29 | 30 | # build app with sharg 31 | add_executable (hello_world ../src/hello_world.cpp) 32 | target_link_libraries (hello_world sharg::sharg) 33 | install (TARGETS hello_world) 34 | -------------------------------------------------------------------------------- /test/external_project/sharg_installed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | project (sharg_app CXX) 7 | 8 | # --- helper scripts 9 | include (../find-package-diagnostics.cmake) 10 | # --- 11 | 12 | # require sharg with a version between >=1.0.0 and <2.0.0 13 | find_package (sharg 1.0 REQUIRED) 14 | 15 | # build app with sharg 16 | add_executable (hello_world ../src/hello_world.cpp) 17 | target_link_libraries (hello_world sharg::sharg) 18 | if (CMAKE_VERSION VERSION_LESS 3.14) 19 | install (TARGETS hello_world RUNTIME DESTINATION bin) 20 | else () 21 | install (TARGETS hello_world) # RUNTIME DESTINATION not needed anymore since cmake 3.14 22 | endif () 23 | -------------------------------------------------------------------------------- /test/external_project/sharg_setup_tutorial/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | # --- helper scripts 8 | include (../find-package-diagnostics.cmake) 9 | # --- 10 | 11 | # Copy the cpp so we can use add_executable like in the tutorial 12 | file (COPY "${CMAKE_SOURCE_DIR}/../src/hello_world.cpp" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") 13 | file (RENAME "${CMAKE_CURRENT_BINARY_DIR}/hello_world.cpp" "${CMAKE_CURRENT_BINARY_DIR}/another_program.cpp") 14 | file (COPY "${CMAKE_SOURCE_DIR}/../src/hello_world.cpp" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") 15 | # In the tutorial, the CMAKE_CURRENT_SOURCE_DIR is a sibling directory of the sharg checkout 16 | set (CMAKE_CURRENT_SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../../source") 17 | 18 | ## [adding_files] 19 | cmake_minimum_required (VERSION 3.12) 20 | project (sharg_tutorial CXX) 21 | 22 | # add sharg to search path 23 | list (APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../sharg-parser/cmake") 24 | 25 | # require sharg with a version between >=1.0.0 and <2.0.0 26 | find_package (sharg 1.0 REQUIRED) 27 | 28 | # build app with sharg 29 | add_executable (hello_world hello_world.cpp) 30 | target_link_libraries (hello_world sharg::sharg) 31 | 32 | add_executable (another_program another_program.cpp) 33 | target_link_libraries (another_program sharg::sharg) 34 | ## [adding_files] 35 | 36 | install (TARGETS hello_world another_program) 37 | -------------------------------------------------------------------------------- /test/external_project/sharg_submodule_add_subdirectory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | project (sharg_app CXX) 7 | 8 | # --- helper scripts 9 | include (../find-package-diagnostics.cmake) 10 | # --- 11 | 12 | # use git checkout of sharg 13 | option (INSTALL_SHARG "" OFF) # we don't need to install sharg 14 | add_subdirectory ("${SHARG_ROOT}" "sharg_build") 15 | 16 | # build app with sharg 17 | add_executable (hello_world ../src/hello_world.cpp) 18 | target_link_libraries (hello_world sharg::sharg) 19 | install (TARGETS hello_world) 20 | -------------------------------------------------------------------------------- /test/external_project/sharg_submodule_find_package/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | project (sharg_app CXX) 7 | 8 | # --- helper scripts 9 | include (../find-package-diagnostics.cmake) 10 | # --- 11 | 12 | # add sharg to search path 13 | list (APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/submodules/sharg/cmake") 14 | 15 | # require sharg with a version between >=1.0.0 and <2.0.0 16 | find_package (sharg 1.0 REQUIRED) 17 | 18 | # build app with sharg 19 | add_executable (hello_world ../src/hello_world.cpp) 20 | target_link_libraries (hello_world sharg::sharg) 21 | install (TARGETS hello_world) 22 | -------------------------------------------------------------------------------- /test/external_project/src/hello_world.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char ** argv) 8 | { 9 | int val{}; 10 | 11 | sharg::parser parser{"Eat-Me-App", argc, argv}; 12 | parser.add_subsection("Eating Numbers"); 13 | parser.add_option(val, sharg::config{.short_id = 'i', .long_id = "int", .description = "Desc."}); 14 | parser.parse(); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /test/header/generate_header_source.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | option (HEADER_FILE_ABSOLUTE "") 8 | option (HEADER_FILE_INCLUDE "") 9 | option (HEADER_TARGET_SOURCE "") 10 | option (HEADER_TEST_NAME_SAFE "") 11 | option (HEADER_COMPONENT "") 12 | option (HEADER_SUB_TEST "") 13 | 14 | file (WRITE "${HEADER_TARGET_SOURCE}" "") # write empty file 15 | 16 | # cmake-format: off 17 | 18 | if (HEADER_SUB_TEST STREQUAL "no-self-include") 19 | # this test ensures that a header will not be included by itself later 20 | file (READ "${HEADER_FILE_ABSOLUTE}" header_content) 21 | 22 | string (REPLACE "#pragma once" "" header_content "${header_content}") 23 | 24 | file (APPEND "${HEADER_TARGET_SOURCE}" 25 | "// sharg-header-test-no-self-include-start\n" 26 | "${header_content}\n" 27 | "// sharg-header-test-no-self-include-end\n\n") 28 | else () 29 | # this test ensures that a header guard is in place 30 | file (APPEND "${HEADER_TARGET_SOURCE}" 31 | "// sharg-header-test-header-guard-start\n" 32 | "#include <${HEADER_FILE_INCLUDE}>\n" 33 | "#include <${HEADER_FILE_INCLUDE}>\n" 34 | "// sharg-header-test-header-guard-end\n\n") 35 | endif () 36 | 37 | # these includes are required by some headers (note that they follow) 38 | file (APPEND "${HEADER_TARGET_SOURCE}" 39 | "// sharg-header-test-dependencies-start\n" 40 | "#include \n" 41 | "TEST(${HEADER_TEST_NAME_SAFE}) {}\n" 42 | "// sharg-header-test-dependencies-end\n\n") 43 | 44 | # test that sharg headers include platform.hpp 45 | if ("${HEADER_COMPONENT}" MATCHES "sharg") 46 | 47 | # exclude sharg/std/* and sharg/version.hpp from platform test 48 | if (NOT HEADER_FILE_INCLUDE MATCHES "sharg/(std/|version.hpp)") 49 | file (APPEND "${HEADER_TARGET_SOURCE}" 50 | "// sharg-header-test-platform-start\n" 51 | "#ifndef SHARG_DOXYGEN_ONLY\n" 52 | "#error \"Your header '${HEADER_FILE_INCLUDE}' file is missing #include \"\n" 53 | "#endif\n" 54 | "// sharg-header-test-platform-end\n\n") 55 | endif () 56 | 57 | # sharg/std/* must not include platform.hpp (and therefore any other sharg header) 58 | # See https://github.com/seqan/product_backlog/issues/135 59 | if (HEADER_FILE_INCLUDE MATCHES "sharg/std/") 60 | file (APPEND "${HEADER_TARGET_SOURCE}" 61 | "// sharg-header-test-no-platform-start\n" 62 | "#ifdef SHARG_DOXYGEN_ONLY\n" 63 | "#error \"The standard header '${HEADER_FILE_INCLUDE}' file MUST NOT include any other sharg header\"\n" 64 | "#endif\n" 65 | "// sharg-header-test-no-platform-end\n\n") 66 | endif () 67 | endif () 68 | 69 | # cmake-format: on 70 | -------------------------------------------------------------------------------- /test/include/sharg/test/file_access.hpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | /*!\file 6 | * \brief Detects read and write access for a path. 7 | * \author Lydia Buntrock 8 | */ 9 | 10 | #pragma once 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace sharg::test 18 | { 19 | 20 | //!\brief Checks wheter there is read access to a path. 21 | inline bool read_access(std::filesystem::path const & file) 22 | { 23 | std::fstream stream; 24 | stream.open(file, std::ios::in); 25 | return !stream.fail(); 26 | } 27 | 28 | //!\brief Checks wheter there is write access to a path. 29 | inline bool write_access(std::filesystem::path const & file) 30 | { 31 | if (std::filesystem::is_directory(file)) 32 | { 33 | std::filesystem::path test_file{file}; 34 | test_file /= "sharg_test_write_access"; 35 | std::fstream stream; 36 | stream.open(test_file, std::ios::out); 37 | bool result = !stream.fail(); 38 | if (result) 39 | { 40 | stream.close(); 41 | std::filesystem::remove(test_file); 42 | } 43 | return result; 44 | } 45 | else 46 | { 47 | std::fstream stream; 48 | stream.open(file, std::ios::out); 49 | return !stream.fail(); 50 | } 51 | } 52 | 53 | } // namespace sharg::test 54 | -------------------------------------------------------------------------------- /test/scripts/add_snippets_to_cookbook.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 3 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 4 | # SPDX-License-Identifier: BSD-3-Clause 5 | # 6 | # Usage: add_snippets_to_cookbook.sh 7 | # Will update the cookbook to include all snippets of the documentation. 8 | 9 | COOKBOOK="doc/cookbook/index.md" 10 | 11 | if [[ $# -ne 1 ]]; then 12 | echo "Usage: add_snippets_to_cookbook.sh " 13 | exit 1 14 | fi 15 | 16 | if [[ ! -d "$1" ]]; then 17 | echo "The directory $1 does not exist." 18 | exit 1 19 | fi 20 | 21 | if [[ ! -f "$1/${COOKBOOK}" ]]; then 22 | echo "The directory $1 does not seem to be the Sharg root directory." 23 | echo "Cannot find cookbook file $1/${COOKBOOK}." 24 | exit 1 25 | fi 26 | 27 | KEY_LINE_IN_COOKBOOK="ALL SNIPPETS START" 28 | 29 | if [[ -z $(grep -n "${KEY_LINE_IN_COOKBOOK}" ${COOKBOOK}) ]]; then 30 | echo "Line '${KEY_LINE_IN_COOKBOOK}' could not be found in ${COOKBOOK}. Update not possible." 31 | exit 1 32 | fi 33 | 34 | LINE_NUMBER_OF_KEY_LINE=$(grep -n "${KEY_LINE_IN_COOKBOOK}" ${COOKBOOK} | cut -d : -f 1) 35 | 36 | # Copy cookbook except the snippet includes into tmp file 37 | TMP_FILE=$(mktemp) 38 | head -n ${LINE_NUMBER_OF_KEY_LINE} ${COOKBOOK} > ${TMP_FILE} 39 | 40 | # Iterate through all files in test/snippet/* 41 | # Order of results from find is not fixed, so we sort the results alphabetically. 42 | # Snippets of doc would be: find ./doc/ -type f -name "*.cpp" -and -not -path "./doc/cookbook/*" 43 | for snippet in $(find test/snippet/ -type f -name "*.cpp" | sort); do 44 | echo "\include ${snippet}" >> ${TMP_FILE} 45 | done 46 | 47 | # Update cookbook 48 | echo "Updating cookbook at ${COOKBOOK}" 49 | mv ${TMP_FILE} ${COOKBOOK} 50 | -------------------------------------------------------------------------------- /test/scripts/check_markdown_doxygen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 3 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 4 | # SPDX-License-Identifier: BSD-3-Clause 5 | # 6 | # Usage: check_markdown_doxygen.sh 7 | # 8 | # Checks that all markdown files start with a markdown header. 9 | # This is important for Doxygen to correctly parse the markdown files. 10 | 11 | ANY_FAIL=0 12 | 13 | do_check () 14 | { 15 | IS_CORRECT=$(head -n1 "$1" | grep -c "^#" || true) 16 | if [[ $IS_CORRECT -eq 0 ]]; then 17 | echo 'File does not start with a markdown header:' $1 18 | ANY_FAIL=1 19 | fi 20 | } 21 | 22 | if [[ $# -ne 1 ]]; then 23 | echo "Usage: check_markdown_doxygen.sh " 24 | exit 1 25 | fi 26 | 27 | SHARG_ROOT=$(readlink -f "$1") 28 | 29 | if [[ ! -d ${SHARG_ROOT} ]]; then 30 | echo "The directory ${SHARG_ROOT} does not exist." 31 | exit 1 32 | fi 33 | 34 | if [[ ! -f ${SHARG_ROOT}/include/sharg/version.hpp ]]; then 35 | echo "The directory ${SHARG_ROOT} does not seem to be the Sharg root directory." 36 | echo "Cannot find ${SHARG_ROOT}/include/sharg/version.hpp." 37 | exit 1 38 | fi 39 | 40 | for FILE in $(find "${SHARG_ROOT}/doc" -name "*.md" -and -not -path "${SHARG_ROOT}/doc/fragments/*") 41 | do 42 | do_check $FILE 43 | done 44 | 45 | for FILE in $(find "${SHARG_ROOT}" -maxdepth 1 -name "*.md") 46 | do 47 | do_check $FILE 48 | done 49 | 50 | exit $ANY_FAIL 51 | -------------------------------------------------------------------------------- /test/scripts/link_check.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 3 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 4 | # SPDX-License-Identifier: BSD-3-Clause 5 | # 6 | # Usage: link_check.sh 7 | # Will output the status of links in the repository. 8 | # 9 | # Of main interest are broken links and those with a "Link STATUS" message. 10 | # Some URLs may not be properly matched by the regex. 11 | # 12 | # The general workflow is to first run the script and then check the non-working links by searching the occurrence 13 | # within the codebase and verifying that they are indeed broken. 14 | 15 | do_check () 16 | { 17 | RESPONSE=$(curl --http2 -Is -A 'Mozilla/5.0' $1) # HTTP2 is the default. 18 | if ! [[ "$RESPONSE" =~ ^HTTP.* ]]; then # If this does not work, 19 | RESPONSE=$(curl --http1.1 -Is -A 'Mozilla/5.0' $1) # fall back to HTTP1.1. 20 | fi 21 | 22 | HEADER=($(echo $RESPONSE | head -1)); # May look like: HTTP/2 200 23 | STATUS=${HEADER[1]} 24 | case "$STATUS" in 25 | 200) echo "Link OK :" $1;; 26 | 301) echo "Link PERM MOVED :" $1;; 27 | 302) echo "Link TEMP MOVED :" $1;; 28 | 404) echo "Link BROKE :" $1;; 29 | 429) sleep 5; do_check $1;; 30 | *) echo "Link STATUS" $STATUS ":" $1;; 31 | esac 32 | } 33 | 34 | if [[ $# -ne 1 ]]; then 35 | echo "Usage: link_check.sh " 36 | exit 1 37 | fi 38 | 39 | if [[ ! -d $1 ]]; then 40 | echo "The directory $1 does not exist." 41 | exit 1 42 | fi 43 | 44 | if [[ ! -f $1/include/sharg/version.hpp ]]; then 45 | echo "The directory $1 does not seem to be the Sharg root directory." 46 | echo "Cannot find $1/include/sharg/version.hpp." 47 | exit 1 48 | fi 49 | 50 | for URL in $(grep -ohr --exclude-dir={.git,submodules,build} "https*://[a-zA-Z0-9./#+?=_%:-]*[a-zA-Z0-9/#+?=_%:-]" $1 | sort | uniq) 51 | do 52 | do_check $URL 53 | done 54 | -------------------------------------------------------------------------------- /test/scripts/update_copyright.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 4 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 5 | # SPDX-License-Identifier: BSD-3-Clause 6 | 7 | set -Eeuo pipefail 8 | 9 | usage="\ 10 | SYNOPSIS 11 | update_copyright.sh [] []... 12 | 13 | DESCRIPTION 14 | Updates the copyright year of files that are formatted in a certain way. And prints out the 15 | copyright years that it ignores. 16 | 17 | EXAMPLES 18 | ./test/scripts/update_copyright.sh 2024 2025 \$(find . -not -path '*/\.git/**' -and -not -path '*/submodules/*' -and -not -path '*/build/*' -and -not -iname '*.patch' -type f) 19 | Updates all copyright entries from 2024 to 2025. Only scans non hidden directories. Does not scan build and 20 | submodules directory. 21 | " 22 | 23 | if [ $# -eq 0 ]; then 24 | echo -e "$usage" 25 | exit 1 26 | fi 27 | # New update year 28 | oldyear=$1 29 | year=$2 30 | shift 2 31 | 32 | echo "Setting copyright dates from ${oldyear} to ${year}" 33 | 34 | for file in "$@"; do 35 | perl -i -pe 's/^(.*SPDX-FileCopyrightText: [0-9]{4}-)'${oldyear}'(,? Knut Reinert.*$)/${1}'${year}'${2}/' $file 36 | perl -ne 'print "'$file':$.: $_" if (/^.*SPDX-FileCopyrightText.*'${oldyear}'.*$/);' $file 37 | done 38 | -------------------------------------------------------------------------------- /test/snippet/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | project (sharg_test_snippet CXX) 7 | 8 | include (../sharg-test.cmake) 9 | include (../cmake/diagnostics/list_unused_snippets.cmake) 10 | 11 | CPMGetPackage (googletest) 12 | 13 | add_library (snippet_main snippet_main.cpp) 14 | target_link_libraries (snippet_main PUBLIC sharg::test gtest) 15 | 16 | macro (sharg_snippet test_name_prefix snippet snippet_base_path) 17 | sharg_test_component (snippet_target_name "${snippet}" TARGET_NAME) 18 | sharg_test_component (snippet_test_name "${snippet}" TEST_NAME) 19 | sharg_test_component (snippet_target_path "${snippet}" TARGET_PATH) 20 | set (target "${snippet_target_name}_snippet") 21 | 22 | add_executable (${target} "${snippet_base_path}/${snippet}") 23 | target_link_libraries (${target} PUBLIC snippet_main) 24 | set_target_properties (${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY 25 | "${CMAKE_CURRENT_BINARY_DIR}/${snippet_target_path}") 26 | collect_used_snippet (${target}) 27 | 28 | set (snippet_test_target "${test_name_prefix}/${snippet_test_name}_snippet") 29 | add_test (NAME "${snippet_test_target}" COMMAND ${target}) 30 | 31 | # disable version checker, as it interferes with comparing the snippet output 32 | set_tests_properties ("${snippet_test_target}" PROPERTIES ENVIRONMENT SHARG_NO_VERSION_CHECK=0) 33 | 34 | set (snippet_compare_test_target "${test_name_prefix}/${snippet_test_name}_snippet_cmp_output") 35 | 36 | add_test (NAME "${snippet_compare_test_target}" 37 | COMMAND ${CMAKE_COMMAND} -DTARGET_FILE=$ 38 | -DSOURCE_FILE=${snippet_base_path}/${snippet} -P 39 | "${CMAKE_SOURCE_DIR}/compare_snippet_output.cmake") 40 | 41 | # disable version checker, as it interferes with comparing the snippet output 42 | set_tests_properties ("${snippet_compare_test_target}" PROPERTIES ENVIRONMENT SHARG_NO_VERSION_CHECK=0) 43 | 44 | unset (snippet_target_name) 45 | unset (snippet_test_name) 46 | unset (snippet_target_path) 47 | unset (target) 48 | endmacro () 49 | 50 | macro (sharg_snippets test_name_prefix snippet_base_path_) 51 | get_filename_component (snippet_base_path "${snippet_base_path_}" ABSOLUTE BASE_DIR 52 | "${CMAKE_CURRENT_SOURCE_DIR}/../..") 53 | sharg_test_files (snippet_files "${snippet_base_path}" "*.cpp") 54 | foreach (snippet ${snippet_files}) 55 | sharg_snippet ("${test_name_prefix}" "${snippet}" "${snippet_base_path}") 56 | endforeach () 57 | endmacro () 58 | 59 | sharg_snippets ("snippet" "${CMAKE_CURRENT_SOURCE_DIR}") 60 | sharg_snippets ("doc/snippet" "${CMAKE_CURRENT_SOURCE_DIR}/../../doc") 61 | 62 | list_unused_snippets ("${CMAKE_CURRENT_SOURCE_DIR}") 63 | list_unused_snippets ("${CMAKE_CURRENT_SOURCE_DIR}/../../doc") 64 | -------------------------------------------------------------------------------- /test/snippet/add_subcommands.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | void run(std::vector const & arguments) 8 | { 9 | sharg::parser git_parser{"git", arguments, sharg::update_notifications::off, {"pull", "push"}}; 10 | git_parser.add_subcommands({"remote"}); 11 | git_parser.parse(); 12 | 13 | sharg::parser & sub_parser = git_parser.get_sub_parser(); 14 | 15 | if (sub_parser.info.app_name == std::string_view{"git-pull"}) 16 | { 17 | auto & pull_parser = sub_parser; 18 | std::string repository{}; 19 | pull_parser.add_positional_option(repository, sharg::config{}); 20 | pull_parser.parse(); 21 | } 22 | else if (sub_parser.info.app_name == std::string_view{"git-push"}) 23 | { 24 | auto & push_parser = sub_parser; 25 | std::string repository{}; 26 | push_parser.add_positional_option(repository, sharg::config{}); 27 | push_parser.parse(); 28 | } 29 | else if (sub_parser.info.app_name == std::string_view{"git-remote"}) 30 | { 31 | auto & remote_parser = sub_parser; 32 | remote_parser.add_subcommands({"set-url", "show"}); 33 | remote_parser.parse(); 34 | 35 | sharg::parser & recursive_sub_parser = remote_parser.get_sub_parser(); 36 | 37 | if (recursive_sub_parser.info.app_name == std::string_view{"git-remote-set-url"}) 38 | { 39 | auto & set_url_parser = recursive_sub_parser; 40 | std::string repository{}; 41 | set_url_parser.add_positional_option(repository, sharg::config{}); 42 | set_url_parser.parse(); 43 | } 44 | else if (recursive_sub_parser.info.app_name == std::string_view{"git-remote-show"}) 45 | { 46 | auto & show_parser = recursive_sub_parser; 47 | show_parser.parse(); 48 | } 49 | } 50 | } 51 | 52 | int main(int argc, char ** argv) 53 | { 54 | try 55 | { 56 | run({argv, argv + argc}); 57 | } 58 | catch (sharg::parser_error const & ext) 59 | { 60 | std::cerr << "[Error] " << ext.what() << '\n'; 61 | std::exit(-1); 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /test/snippet/add_subcommands.out: -------------------------------------------------------------------------------- 1 | git 2 | === 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/add_subcommands.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/auxiliary.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char const ** argv) 8 | { 9 | sharg::parser myparser{"Test", argc, argv}; 10 | std::string myvar{"Example"}; 11 | myparser.add_option(myvar, sharg::config{.short_id = 's', .long_id = "special-op", .advanced = true}); 12 | } 13 | -------------------------------------------------------------------------------- /test/snippet/compare_snippet_output.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: CC0-1.0 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | 7 | include ("${CMAKE_CURRENT_LIST_DIR}/../cmake/sharg_path_longest_stem.cmake") 8 | 9 | message (STATUS "TARGET_FILE: ${TARGET_FILE}") 10 | message (STATUS "SOURCE_FILE: ${SOURCE_FILE}") 11 | 12 | get_filename_component (TARGET_FILE_DIR "${TARGET_FILE}" DIRECTORY) 13 | sharg_path_longest_stem (SOURCE_FILE_NAME "${SOURCE_FILE}") 14 | get_filename_component (SOURCE_FILE_DIR "${SOURCE_FILE}" DIRECTORY) 15 | 16 | set (ACTUAL_OUTPUT_FILE "${TARGET_FILE}.out") 17 | set (EXPECTED_OUTPUT_FILE "${SOURCE_FILE_DIR}/${SOURCE_FILE_NAME}.out") 18 | set (ACTUAL_ERROR_FILE "${TARGET_FILE}.err") 19 | set (EXPECTED_ERROR_FILE "${SOURCE_FILE_DIR}/${SOURCE_FILE_NAME}.err") 20 | 21 | message (STATUS "ACTUAL_OUTPUT_FILE: ${ACTUAL_OUTPUT_FILE}") 22 | message (STATUS "EXPECTED_OUTPUT_FILE: ${EXPECTED_OUTPUT_FILE}") 23 | 24 | message (STATUS "ACTUAL_ERROR_FILE: ${ACTUAL_ERROR_FILE}") 25 | message (STATUS "EXPECTED_ERROR_FILE: ${EXPECTED_ERROR_FILE}") 26 | 27 | # execute snippet 28 | execute_process (COMMAND "${TARGET_FILE}" 29 | WORKING_DIRECTORY "${TARGET_FILE_DIR}" 30 | OUTPUT_FILE "${ACTUAL_OUTPUT_FILE}" 31 | ERROR_FILE "${ACTUAL_ERROR_FILE}" 32 | RESULT_VARIABLE error_result) 33 | 34 | if (error_result) # != 0 return code 35 | message (SEND_ERROR "error: executing snippet exited with '${error_result}'") 36 | endif () 37 | 38 | function (compare_files actual_file expected_file) 39 | file (READ "${actual_file}" actual_output) 40 | 41 | if (actual_output AND EXISTS "${expected_file}") 42 | execute_process (COMMAND ${CMAKE_COMMAND} -E compare_files "${actual_file}" "${expected_file}" 43 | RESULT_VARIABLE error_result) 44 | 45 | if (NOT error_result) # == 0 return code => files are identical 46 | # if successful move one 47 | return () 48 | endif () 49 | 50 | message (SEND_ERROR "error: `${actual_file}` and `${expected_file}` differ (exited with '${error_result}')") 51 | 52 | find_package (Git) 53 | if (Git_FOUND) 54 | execute_process (COMMAND "${GIT_EXECUTABLE}" diff --no-index "${expected_file}" "${actual_file}") 55 | endif () 56 | elseif (EXISTS "${expected_file}") 57 | message (SEND_ERROR "error: `${expected_file}` exists, but `${actual_file}` has no output.") 58 | elseif (actual_output) 59 | message (SEND_ERROR "error: `${actual_file}` has output, but `${expected_file}` does not exist.") 60 | else () 61 | message (STATUS "Output matches ${expected_file}") 62 | endif () 63 | endfunction () 64 | 65 | # compare output to file 66 | compare_files ("${ACTUAL_OUTPUT_FILE}" "${EXPECTED_OUTPUT_FILE}") 67 | compare_files ("${ACTUAL_ERROR_FILE}" "${EXPECTED_ERROR_FILE}") 68 | -------------------------------------------------------------------------------- /test/snippet/custom_enumeration.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | namespace foo 8 | { 9 | 10 | enum class bar : uint8_t 11 | { 12 | one, 13 | two, 14 | three 15 | }; 16 | 17 | // Specialise a mapping from an identifying string to the respective value of your type bar. 18 | auto enumeration_names(bar) 19 | { 20 | return std::unordered_map{{"one", bar::one}, {"two", bar::two}, {"three", bar::three}}; 21 | } 22 | 23 | } // namespace foo 24 | 25 | int main(int argc, char const * argv[]) 26 | { 27 | foo::bar value{}; 28 | 29 | sharg::parser parser{"my_program", argc, argv}; 30 | 31 | // Because of the enumeration_names function 32 | // you can now add an option that takes a value of type bar: 33 | auto vali = sharg::value_list_validator{(sharg::enumeration_names | std::views::values)}; 34 | parser.add_option( 35 | value, 36 | sharg::config{.short_id = 'f', .long_id = "foo", .description = "Give me a value for foo.", .validator = vali}); 37 | 38 | try 39 | { 40 | parser.parse(); 41 | } 42 | catch (sharg::parser_error const & ext) // the user did something wrong 43 | { 44 | std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message 45 | return -1; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /test/snippet/custom_enumeration.out: -------------------------------------------------------------------------------- 1 | my_program 2 | ========== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/custom_enumeration.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/custom_parsing_enumeration.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | #include 8 | 9 | namespace sharg::custom 10 | { 11 | // Specialise the sharg::custom::parsing data structure to enable parsing of std::errc. 12 | template <> 13 | struct parsing 14 | { 15 | // Specialise a mapping from an identifying string to the respective value of your type Foo. 16 | static inline std::unordered_map const enumeration_names{ 17 | {"no_error", std::errc{}}, 18 | {"timed_out", std::errc::timed_out}, 19 | {"invalid_argument", std::errc::invalid_argument}, 20 | {"io_error", std::errc::io_error}}; 21 | }; 22 | 23 | } // namespace sharg::custom 24 | 25 | int main(int argc, char const * argv[]) 26 | { 27 | std::errc value{}; 28 | 29 | sharg::parser parser{"my_program", argc, argv}; 30 | 31 | // Because of the parsing struct and 32 | // the static member function enumeration_names 33 | // you can now add an option that takes a value of type std::errc: 34 | auto validator = sharg::value_list_validator{(sharg::enumeration_names | std::views::values)}; 35 | parser.add_option(value, 36 | sharg::config{.short_id = 'e', 37 | .long_id = "errc", 38 | .description = "Give me a std::errc value.", 39 | .validator = validator}); 40 | 41 | try 42 | { 43 | parser.parse(); 44 | } 45 | catch (sharg::parser_error const & ext) // the user did something wrong 46 | { 47 | std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message 48 | return -1; 49 | } 50 | 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /test/snippet/custom_parsing_enumeration.out: -------------------------------------------------------------------------------- 1 | my_program 2 | ========== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/custom_parsing_enumeration.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/is_option_set.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char ** argv) 8 | { 9 | sharg::parser myparser{"awesome-app", argc, argv}; // initialize 10 | 11 | int a{3}; 12 | myparser.add_option(a, sharg::config{.short_id = 'a', .long_id = "aint", .description = "Specify an integer."}); 13 | 14 | try 15 | { 16 | myparser.parse(); 17 | } 18 | catch (sharg::parser_error const & ext) // the user did something wrong 19 | { 20 | std::cerr << "[PARSER ERROR] " << ext.what() << '\n'; // customize your error message 21 | return -1; 22 | } 23 | 24 | if (myparser.is_option_set('a')) 25 | std::cerr << "The user set option -a on the command line.\n"; 26 | 27 | if (myparser.is_option_set("awesome-parameter")) 28 | std::cerr << "The user set option --awesome-parameter on the command line.\n"; 29 | 30 | // Asking for an option identifier that was not used before throws an error: 31 | // myparser.is_option_set("foo"); // throws sharg::design_error 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /test/snippet/is_option_set.out: -------------------------------------------------------------------------------- 1 | awesome-app 2 | =========== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/is_option_set.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/parser_1.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char ** argv) 8 | { 9 | sharg::parser myparser{"Grade-Average", argc, argv}; // initialize 10 | 11 | std::string name{"Max Muster"}; // define default values directly in the variable. 12 | bool bonus{false}; 13 | std::vector grades{}; // you can also specify a vector that is treated as a list option. 14 | 15 | myparser.add_option(name, sharg::config{.short_id = 'n', .long_id = "name", .description = "Your name please."}); 16 | myparser.add_flag(bonus, sharg::config{.short_id = 'b', .long_id = "bonus", .description = "Got a bonus?."}); 17 | myparser.add_positional_option(grades, sharg::config{.description = "Please specify your grades."}); 18 | 19 | try 20 | { 21 | myparser.parse(); 22 | } 23 | catch (sharg::parser_error const & ext) // the user did something wrong 24 | { 25 | std::cerr << "[PARSER ERROR] " << ext.what() << '\n'; // customize your error message 26 | return -1; 27 | } 28 | 29 | if (bonus) 30 | grades.push_back(1.0); // extra good grade 31 | 32 | double avg{0}; 33 | for (auto g : grades) 34 | avg += g; 35 | 36 | avg = avg / grades.size(); 37 | 38 | std::cerr << name << " has an average grade of " << avg << '\n'; 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /test/snippet/parser_1.out: -------------------------------------------------------------------------------- 1 | Grade-Average 2 | ============= 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/parser_1.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/parser_2.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char ** argv) 8 | { 9 | sharg::parser myparser{"The-Age-App", argc, argv}; // initialize 10 | 11 | int age{30}; // define default values directly in the variable 12 | 13 | myparser.add_option(age, sharg::config{.short_id = 'a', .long_id = "user-age", .description = "Your age please."}); 14 | 15 | try 16 | { 17 | myparser.parse(); 18 | } 19 | catch (sharg::parser_error const & ext) // the user did something wrong 20 | { 21 | std::cerr << "The-Age-App - [PARSER ERROR] " << ext.what() << '\n'; // customize your error message 22 | return -1; 23 | } 24 | 25 | std::cerr << "integer given by user: " << age << '\n'; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /test/snippet/parser_2.out: -------------------------------------------------------------------------------- 1 | The-Age-App 2 | =========== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/parser_2.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/parser_3.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char ** argv) 8 | { 9 | sharg::parser myparser{"Penguin_Parade", argc, argv}; // initialize 10 | 11 | myparser.info.version = "2.0.0"; 12 | myparser.info.date = "12.01.2017"; 13 | myparser.info.short_description = "Organize your penguin parade"; 14 | myparser.info.description.push_back("First Paragraph."); 15 | myparser.info.description.push_back("Second Paragraph."); 16 | myparser.info.examples.push_back("./penguin_parade Skipper Kowalski Rico Private -d 10 -m 02 -y 2017"); 17 | 18 | int d{01}; // day 19 | int m{01}; // month 20 | int y{2050}; // year 21 | 22 | myparser.add_option(d, sharg::config{.short_id = 'd', .long_id = "day", .description = "Your preferred day."}); 23 | myparser.add_option(m, sharg::config{.short_id = 'm', .long_id = "month", .description = "Your preferred month."}); 24 | myparser.add_option(y, sharg::config{.short_id = 'y', .long_id = "year", .description = "Your preferred year."}); 25 | 26 | std::vector penguin_names; 27 | 28 | myparser.add_positional_option(penguin_names, sharg::config{.description = "Specify the names of the penguins."}); 29 | 30 | try 31 | { 32 | myparser.parse(); 33 | } 34 | catch (sharg::parser_error const & ext) // the user did something wrong 35 | { 36 | std::cerr << ext.what() << "\n"; 37 | return -1; 38 | } 39 | 40 | // organize ... 41 | 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /test/snippet/parser_3.out: -------------------------------------------------------------------------------- 1 | Penguin_Parade - Organize your penguin parade 2 | ============================================= 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/parser_3.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/readme_sneak_peek.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #define main test 6 | 7 | #include 8 | 9 | int main(int argc, char ** argv) 10 | { 11 | int val{}; 12 | 13 | sharg::parser parser{"Eat-Me-App", argc, argv}; 14 | parser.add_subsection("Eating Numbers"); 15 | parser.add_option(val, sharg::config{.short_id = 'i', .long_id = "int", .description = "Desc."}); 16 | parser.parse(); 17 | 18 | return 0; 19 | } 20 | 21 | #undef main 22 | 23 | int main() 24 | { 25 | std::string argv1{"./Eat-Me-App"}, argv2{"-h"}; 26 | std::array argv{argv1.data(), argv2.data()}; 27 | 28 | return test(argv.size(), argv.data()); 29 | } 30 | -------------------------------------------------------------------------------- /test/snippet/readme_sneak_peek.out: -------------------------------------------------------------------------------- 1 | Eat-Me-App 2 | ========== 3 | 4 | OPTIONS 5 | 6 | Eating Numbers 7 | -i, --int (signed 32 bit integer) 8 | Desc. Default: 0 9 | 10 | Common options 11 | -h, --help 12 | Prints the help page. 13 | -hh, --advanced-help 14 | Prints the help page including advanced options. 15 | --version 16 | Prints the version information. 17 | --copyright 18 | Prints the copyright/license information. 19 | --export-help (std::string) 20 | Export the help page information. Value must be one of [html, man, 21 | ctd, cwl]. 22 | --version-check (bool) 23 | Whether to check for the newest app version. Default: true 24 | 25 | VERSION 26 | Last update: 27 | Eat-Me-App version: 28 | Sharg version: 1.1.2-rc.1 29 | -------------------------------------------------------------------------------- /test/snippet/readme_sneak_peek.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/safe_filesystem_entry.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | int main() 11 | { 12 | std::filesystem::path my_file = std::filesystem::temp_directory_path() / "dummy.txt"; 13 | 14 | std::ifstream file{my_file}; // Create the file. 15 | sharg::detail::safe_filesystem_entry file_guard{my_file}; // Safe cleanup in case of errors. 16 | 17 | // Do something on the file, that can possibly throw. 18 | // If an unhandled exception is thrown, the file guard destructor safely removes the file from the filesystem. 19 | 20 | file_guard.remove(); // Explicitly remove the file. 21 | } 22 | -------------------------------------------------------------------------------- /test/snippet/snippet_main.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | int main() 6 | {} 7 | -------------------------------------------------------------------------------- /test/snippet/validators_1.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char const ** argv) 8 | { 9 | sharg::parser myparser{"Test", argc, argv}; // initialize 10 | 11 | //![validator_call] 12 | int myint; 13 | sharg::arithmetic_range_validator my_validator{2, 10}; 14 | 15 | myparser.add_option(myint, 16 | sharg::config{.short_id = 'i', 17 | .long_id = "integer", 18 | .description = "Give me a number.", 19 | .validator = my_validator}); 20 | //![validator_call] 21 | 22 | // an exception will be thrown if the user specifies an integer 23 | // that is not in range [2,10] (e.g. "./test_app -i 15") 24 | try 25 | { 26 | myparser.parse(); 27 | } 28 | catch (sharg::parser_error const & ext) // the user did something wrong 29 | { 30 | std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message 31 | return -1; 32 | } 33 | 34 | std::cerr << "integer given by user passed validation: " << myint << "\n"; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/snippet/validators_1.out: -------------------------------------------------------------------------------- 1 | Test 2 | ==== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/validators_1.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/validators_2.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char const ** argv) 8 | { 9 | sharg::parser myparser{"Test", argc, argv}; // initialize 10 | 11 | //![validator_call] 12 | int myint; 13 | sharg::value_list_validator my_validator{2, 4, 6, 8, 10}; 14 | 15 | myparser.add_option(myint, 16 | sharg::config{.short_id = 'i', 17 | .long_id = "integer", 18 | .description = "Give me a number.", 19 | .validator = my_validator}); 20 | //![validator_call] 21 | 22 | // an exception will be thrown if the user specifies an integer 23 | // that is not one of [2,4,6,8,10] (e.g. "./test_app -i 3") 24 | try 25 | { 26 | myparser.parse(); 27 | } 28 | catch (sharg::parser_error const & ext) // the user did something wrong 29 | { 30 | std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message 31 | return -1; 32 | } 33 | 34 | std::cerr << "integer given by user passed validation: " << myint << "\n"; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/snippet/validators_2.out: -------------------------------------------------------------------------------- 1 | Test 2 | ==== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/validators_2.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/validators_3.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char const ** argv) 8 | { 9 | sharg::parser myparser{"Test", argc, argv}; // initialize 10 | 11 | //![validator_call] 12 | std::filesystem::path myfile; 13 | auto vali = sharg::input_file_validator{{"fa", "fasta"}}; 14 | 15 | myparser.add_option( 16 | myfile, 17 | sharg::config{.short_id = 'f', .long_id = "file", .description = "Give me a filename.", .validator = vali}); 18 | //![validator_call] 19 | 20 | // an exception will be thrown if the user specifies a filename 21 | // that does not have one of the extensions ["fa","fasta"], 22 | // does not exists, or is not readable. 23 | try 24 | { 25 | myparser.parse(); 26 | } 27 | catch (sharg::parser_error const & ext) // the user did something wrong 28 | { 29 | std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message 30 | return -1; 31 | } 32 | 33 | std::cerr << "filename given by user passed validation: " << myfile << "\n"; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/snippet/validators_3.out: -------------------------------------------------------------------------------- 1 | Test 2 | ==== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/validators_3.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/validators_4.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char const ** argv) 8 | { 9 | sharg::parser myparser{"Test", argc, argv}; // initialize 10 | 11 | //![validator_call] 12 | std::string my_string; 13 | sharg::regex_validator my_validator{"[a-zA-Z]+@[a-zA-Z]+\\.com"}; 14 | 15 | myparser.add_option(my_string, 16 | sharg::config{.short_id = 's', 17 | .long_id = "str", 18 | .description = "Give me a string.", 19 | .validator = my_validator}); 20 | //![validator_call] 21 | 22 | // an exception will be thrown if the user specifies a string 23 | // that is no email address ending on .com 24 | try 25 | { 26 | myparser.parse(); 27 | } 28 | catch (sharg::parser_error const & ext) // the user did something wrong 29 | { 30 | std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message 31 | return -1; 32 | } 33 | 34 | std::cerr << "email address given by user passed validation: " << my_string << "\n"; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /test/snippet/validators_4.out: -------------------------------------------------------------------------------- 1 | Test 2 | ==== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/validators_4.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/validators_chaining.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char const ** argv) 8 | { 9 | sharg::parser myparser{"Test", argc, argv}; // initialize 10 | 11 | //![validator_call] 12 | std::string file_name; 13 | 14 | sharg::regex_validator absolute_path_validator{"(/[^/]+)+/.*\\.[^/\\.]+$"}; 15 | sharg::input_file_validator my_file_ext_validator{{"sa", "so"}}; 16 | 17 | myparser.add_option(file_name, 18 | sharg::config{.short_id = 'f', 19 | .long_id = "file", 20 | .description = "Give me a file name with an absolute path.", 21 | .validator = absolute_path_validator | my_file_ext_validator}); 22 | //![validator_call] 23 | 24 | // an exception will be thrown if the user specifies a file name 25 | // that is not an absolute path or does not have one of the file extension [sa,so] 26 | try 27 | { 28 | myparser.parse(); 29 | } 30 | catch (sharg::parser_error const & ext) // the user did something wrong 31 | { 32 | std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message 33 | return -1; 34 | } 35 | 36 | std::cout << "filename given by user passed validation: " << file_name << "\n"; 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /test/snippet/validators_chaining.out: -------------------------------------------------------------------------------- 1 | Test 2 | ==== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/validators_chaining.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/validators_input_directory.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char const ** argv) 8 | { 9 | sharg::parser myparser{"Test", argc, argv}; // initialize 10 | 11 | //! [validator_call] 12 | std::filesystem::path mydir{}; 13 | 14 | myparser.add_option(mydir, 15 | sharg::config{.short_id = 'd', 16 | .long_id = "dir", 17 | .description = "The directory containing the input files.", 18 | .validator = sharg::input_directory_validator{}}); 19 | //! [validator_call] 20 | 21 | // an exception will be thrown if the user specifies a directory that does not exists or has insufficient 22 | // read permissions. 23 | try 24 | { 25 | myparser.parse(); 26 | } 27 | catch (sharg::parser_error const & ext) // the user did something wrong 28 | { 29 | std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message 30 | return -1; 31 | } 32 | 33 | std::cerr << "directory given by user passed validation: " << mydir << "\n"; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/snippet/validators_input_directory.out: -------------------------------------------------------------------------------- 1 | Test 2 | ==== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/validators_input_directory.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/validators_input_file.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char const ** argv) 8 | { 9 | sharg::parser myparser{"Test", argc, argv}; // initialize 10 | 11 | //! [validator_call] 12 | std::filesystem::path myfile{}; 13 | 14 | myparser.add_option(myfile, 15 | sharg::config{.short_id = 'f', 16 | .long_id = "file", 17 | .description = "The input file containing the sequences.", 18 | .validator = sharg::input_file_validator{{"fa", "fasta"}}}); 19 | //! [validator_call] 20 | 21 | // an exception will be thrown if the user specifies a filename 22 | // that does not have one of the extensions ["fa","fasta"] or if the file does not exist/is not readable. 23 | try 24 | { 25 | myparser.parse(); 26 | } 27 | catch (sharg::parser_error const & ext) // the user did something wrong 28 | { 29 | std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message 30 | return -1; 31 | } 32 | 33 | std::cerr << "filename given by user passed validation: " << myfile << "\n"; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/snippet/validators_input_file.out: -------------------------------------------------------------------------------- 1 | Test 2 | ==== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/validators_input_file.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/validators_input_file_ext_from_file.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | #include 8 | 9 | int main() 10 | { 11 | // Default constructed validator has an empty extension list. 12 | sharg::input_file_validator validator1{}; 13 | std::cerr << validator1.get_help_page_message() << '\n'; 14 | 15 | // Specify your own extensions for the input file. 16 | sharg::input_file_validator validator2{std::vector{std::string{"exe"}, std::string{"fasta"}}}; 17 | std::cerr << validator2.get_help_page_message() << '\n'; 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /test/snippet/validators_input_file_ext_from_file.err: -------------------------------------------------------------------------------- 1 | The input file must exist and read permissions must be granted. 2 | The input file must exist and read permissions must be granted. Valid file extensions are: [exe, fasta]. 3 | -------------------------------------------------------------------------------- /test/snippet/validators_input_file_ext_from_file.err.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/validators_output_directory.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char const ** argv) 8 | { 9 | sharg::parser myparser{"Test", argc, argv}; // initialize 10 | 11 | //! [validator_call] 12 | std::filesystem::path mydir{}; 13 | 14 | myparser.add_option(mydir, 15 | sharg::config{.short_id = 'd', 16 | .long_id = "dir", 17 | .description = "The output directory for storing the files.", 18 | .validator = sharg::output_directory_validator{}}); 19 | //! [validator_call] 20 | 21 | // an exception will be thrown if the user specifies a directory that cannot be created by the filesystem either 22 | // because the parent path does not exists or the path has insufficient write permissions. 23 | try 24 | { 25 | myparser.parse(); 26 | } 27 | catch (sharg::parser_error const & ext) // the user did something wrong 28 | { 29 | std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message 30 | return -1; 31 | } 32 | 33 | std::cerr << "directory given by user passed validation: " << mydir << "\n"; 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /test/snippet/validators_output_directory.out: -------------------------------------------------------------------------------- 1 | Test 2 | ==== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/validators_output_directory.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/validators_output_file.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | int main(int argc, char const ** argv) 8 | { 9 | sharg::parser myparser{"Test", argc, argv}; // initialize 10 | 11 | //! [validator_call] 12 | std::filesystem::path myfile{}; 13 | 14 | // Use the sharg::output_file_open_options to indicate that you allow overwriting existing output files, ... 15 | myparser.add_option( 16 | myfile, 17 | sharg::config{.short_id = 'f', 18 | .long_id = "file", 19 | .description = "Output file containing the processed sequences.", 20 | .validator = sharg::output_file_validator{sharg::output_file_open_options::open_or_create, 21 | {"fa", "fasta"}}}); 22 | 23 | // ... or that you will throw a sharg::validation_error if the user specified output file already exists 24 | // No sharg::output_file_open_options is passed: The default sharg::output_file_open_options::create_new is used. 25 | // Possible extensions can also be passed as separate arguments. 26 | myparser.add_option(myfile, 27 | sharg::config{.short_id = 'g', 28 | .long_id = "file2", 29 | .description = "Output file containing the processed sequences.", 30 | .validator = sharg::output_file_validator{"fa", "fasta"}}); 31 | //! [validator_call] 32 | 33 | // an exception will be thrown if the user specifies a filename 34 | // that does not have one of the extensions ["fa","fasta"], 35 | // if the file already exists, or if the file is not writable. 36 | try 37 | { 38 | myparser.parse(); 39 | } 40 | catch (sharg::parser_error const & ext) // the user did something wrong 41 | { 42 | std::cerr << "[PARSER ERROR] " << ext.what() << "\n"; // customize your error message 43 | return -1; 44 | } 45 | 46 | std::cerr << "filename given by user passed validation: " << myfile << "\n"; 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /test/snippet/validators_output_file.out: -------------------------------------------------------------------------------- 1 | Test 2 | ==== 3 | Try -h or --help for more information. 4 | -------------------------------------------------------------------------------- /test/snippet/validators_output_file.out.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/snippet/validators_output_file_ext_from_file.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: CC0-1.0 4 | 5 | #include 6 | 7 | #include 8 | 9 | int main() 10 | { 11 | // Default constructed validator has an empty extension list. 12 | sharg::output_file_validator validator1{}; 13 | std::cerr << validator1.get_help_page_message() << '\n'; 14 | 15 | // Specify your own extensions for the output file. 16 | sharg::output_file_validator validator2{sharg::output_file_open_options::create_new, 17 | std::vector{std::string{"exe"}, std::string{"fasta"}}}; 18 | std::cerr << validator2.get_help_page_message() << '\n'; 19 | 20 | // If you do not pass the output_file_open_options, the default of create_new is used. 21 | sharg::output_file_validator validator3{std::vector{std::string{"exe"}, std::string{"fasta"}}}; 22 | std::cerr << validator3.get_help_page_message() << '\n'; 23 | 24 | // Instead of passing a std::vector, you can also pass each extension as separate argument. 25 | sharg::output_file_validator validator4{"exe", "fasta"}; 26 | std::cerr << validator4.get_help_page_message() << '\n'; 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /test/snippet/validators_output_file_ext_from_file.err: -------------------------------------------------------------------------------- 1 | The output file must not exist already and write permissions must be granted. 2 | The output file must not exist already and write permissions must be granted. Valid file extensions are: [exe, fasta]. 3 | The output file must not exist already and write permissions must be granted. Valid file extensions are: [exe, fasta]. 4 | The output file must not exist already and write permissions must be granted. Valid file extensions are: [exe, fasta]. 5 | -------------------------------------------------------------------------------- /test/snippet/validators_output_file_ext_from_file.err.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | SPDX-License-Identifier: CC0-1.0 4 | -------------------------------------------------------------------------------- /test/unit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | cmake_minimum_required (VERSION 3.12) 6 | project (sharg_test_unit CXX) 7 | 8 | include (../sharg-test.cmake) 9 | include (GoogleTest OPTIONAL) 10 | 11 | CPMGetPackage (googletest) 12 | 13 | include (diagnostics/list_missing_unit_tests) 14 | include (diagnostics/list_unused_unit_tests) 15 | include (include_dependencies/add_include_dependencies) 16 | 17 | option (SHARG_VERBOSE_TESTS "Run each test case individually" OFF) 18 | option (SHARG_USE_INCLUDE_DEPENDENCIES 19 | "Build tests in an hierarchical order (by an include graph, i.e. tests with less dependencies are build first)" 20 | OFF) 21 | 22 | macro (sharg_test unit_test_cpp) 23 | cmake_parse_arguments (SHARG_TEST "" "" "CYCLIC_DEPENDING_INCLUDES" ${ARGN}) 24 | 25 | file (RELATIVE_PATH unit_test "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_LIST_DIR}/${unit_test_cpp}") 26 | sharg_test_component (target "${unit_test}" TARGET_NAME) 27 | sharg_test_component (test_name "${unit_test}" TEST_NAME) 28 | 29 | add_executable (${target} ${unit_test_cpp}) 30 | target_link_libraries (${target} sharg::test::unit) 31 | add_include_dependencies (${target} "${SHARG_TEST_CYCLIC_DEPENDING_INCLUDES}") 32 | collect_used_test (${target}) 33 | if (SHARG_VERBOSE_TESTS) 34 | gtest_discover_tests ( 35 | ${target} 36 | TEST_PREFIX "${test_name}::" 37 | PROPERTIES 38 | TIMEOUT "30") 39 | else () 40 | add_test (NAME "${test_name}" COMMAND ${target}) 41 | endif () 42 | 43 | unset (unit_test) 44 | unset (target) 45 | unset (test_name) 46 | endmacro () 47 | 48 | add_subdirectories () 49 | 50 | list_missing_unit_tests () 51 | list_unused_unit_tests () 52 | -------------------------------------------------------------------------------- /test/unit/README.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | # API Test 8 | 9 | Here are test files for API tests, i.e. the internal functions of the app are executed with different input parameters. 10 | The test then validates whether the functions work correctly. 11 | Attention: The default `make` target does not build tests. 12 | Please invoke the build with `make unit_test` or use `make test` to build and run all kinds of tests. 13 | -------------------------------------------------------------------------------- /test/unit/detail/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | find_path (SHARG_TEST_LICENSE_DIR 6 | NAMES LICENSE.md 7 | HINTS "${SHARG_CLONE_DIR}") 8 | 9 | add_definitions (-DSHARG_TEST_LICENSE_DIR="${SHARG_TEST_LICENSE_DIR}") 10 | 11 | sharg_test (format_help_test.cpp CYCLIC_DEPENDING_INCLUDES include-sharg-detail-format_html.hpp 12 | include-sharg-detail-format_man.hpp) 13 | sharg_test (format_html_test.cpp CYCLIC_DEPENDING_INCLUDES include-sharg-detail-format_help.hpp 14 | include-sharg-detail-format_man.hpp) 15 | sharg_test (format_man_test.cpp) 16 | sharg_test (format_ctd_test.cpp) 17 | sharg_test (format_cwl_test.cpp) 18 | sharg_test (safe_filesystem_entry_test.cpp) 19 | sharg_test (type_name_as_string_test.cpp) 20 | sharg_test (version_check_debug_test.cpp) 21 | sharg_test (version_check_release_test.cpp) 22 | 23 | file (DOWNLOAD https://raw.githubusercontent.com/seqan/seqan3/main/include/seqan3/version.hpp 24 | ${CMAKE_BINARY_DIR}/include/seqan3/version.hpp) 25 | sharg_test (seqan3_test.cpp) 26 | target_include_directories (seqan3_test SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/include) 27 | -------------------------------------------------------------------------------- /test/unit/detail/safe_filesystem_entry_test.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | TEST(safe_filesystem_entry, file) 13 | { 14 | sharg::test::tmp_filename tmp_file{"dummy.txt"}; 15 | std::filesystem::path const & my_file = tmp_file.get_path(); 16 | { 17 | std::ofstream file{my_file}; 18 | EXPECT_TRUE(std::filesystem::exists(my_file)); 19 | sharg::detail::safe_filesystem_entry file_guard{my_file}; 20 | } 21 | 22 | EXPECT_FALSE(std::filesystem::exists(my_file)); 23 | } 24 | 25 | TEST(safe_filesystem_entry, file_already_removed) 26 | { 27 | sharg::test::tmp_filename tmp_file{"dummy.txt"}; 28 | std::filesystem::path const & my_file = tmp_file.get_path(); 29 | { 30 | EXPECT_FALSE(std::filesystem::exists(my_file)); 31 | sharg::detail::safe_filesystem_entry file_guard{my_file}; 32 | } 33 | 34 | EXPECT_FALSE(std::filesystem::exists(my_file)); 35 | } 36 | 37 | TEST(safe_filesystem_entry, directory) 38 | { 39 | sharg::test::tmp_filename tmp_file{"dummy.txt"}; 40 | std::filesystem::path const & my_dir = tmp_file.get_path(); 41 | { 42 | std::filesystem::create_directory(my_dir); 43 | EXPECT_TRUE(std::filesystem::exists(my_dir)); 44 | sharg::detail::safe_filesystem_entry dir_guard{my_dir}; 45 | } 46 | 47 | EXPECT_FALSE(std::filesystem::exists(my_dir)); 48 | } 49 | 50 | TEST(safe_filesystem_entry, directory_already_removed) 51 | { 52 | sharg::test::tmp_filename tmp_file{"dummy.txt"}; 53 | std::filesystem::path const & my_dir = tmp_file.get_path(); 54 | { 55 | EXPECT_FALSE(std::filesystem::exists(my_dir)); 56 | sharg::detail::safe_filesystem_entry dir_guard{my_dir}; 57 | } 58 | 59 | EXPECT_FALSE(std::filesystem::exists(my_dir)); 60 | } 61 | 62 | TEST(safe_filesystem_entry, remove) 63 | { 64 | sharg::test::tmp_filename tmp_file{"dummy.txt"}; 65 | std::filesystem::path const & my_file = tmp_file.get_path(); 66 | { 67 | std::ofstream file{my_file}; 68 | EXPECT_TRUE(std::filesystem::exists(my_file)); 69 | sharg::detail::safe_filesystem_entry file_guard{my_file}; 70 | EXPECT_TRUE(file_guard.remove()); 71 | } 72 | 73 | EXPECT_FALSE(std::filesystem::exists(my_file)); 74 | } 75 | 76 | TEST(safe_filesystem_entry, remove_all) 77 | { 78 | sharg::test::tmp_filename tmp_file{"dummy.txt"}; 79 | std::filesystem::path const & my_dir = tmp_file.get_path(); 80 | { 81 | std::filesystem::create_directory(my_dir); 82 | EXPECT_TRUE(std::filesystem::exists(my_dir)); 83 | sharg::detail::safe_filesystem_entry dir_guard{my_dir}; 84 | EXPECT_TRUE(dir_guard.remove_all()); 85 | } 86 | 87 | EXPECT_FALSE(std::filesystem::exists(my_dir)); 88 | } 89 | -------------------------------------------------------------------------------- /test/unit/detail/seqan3_test.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #if !__has_include() 11 | # error "seqan3/version.hpp is not available" 12 | #endif 13 | 14 | class seqan3_test : public sharg::test::test_fixture 15 | { 16 | protected: 17 | static inline std::string version_str_with_seqan3 = 18 | version_str() + " SeqAn version: " + seqan3::seqan3_version_cstring + '\n'; 19 | }; 20 | 21 | TEST_F(seqan3_test, version_string) 22 | { 23 | auto parser = get_parser("-h"); 24 | std::string expected = "test_parser\n" 25 | "===========\n" 26 | "\nOPTIONS\n\n" 27 | + basic_options_str + '\n' + version_str_with_seqan3; 28 | EXPECT_EQ(get_parse_cout_on_exit(parser), expected); 29 | } 30 | -------------------------------------------------------------------------------- /test/unit/detail/type_name_as_string_test.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | 11 | // Some test namespace to check if namespace information are preserved within the naming. 12 | namespace foo 13 | { 14 | 15 | template 16 | struct bar 17 | {}; 18 | 19 | } // namespace foo 20 | 21 | // Some types to test if type inspection works as expected. 22 | // Note that the returned name might differ between compiler vendors and thus must be adapted accordingly 23 | // in case this tests fails for those vendors. 24 | using reflection_types = ::testing::Types const &, 30 | foo::bar>>; 31 | 32 | template 33 | class type_inspection : public ::testing::Test 34 | { 35 | public: 36 | // Returns the name of the type according to the list of names defined above. 37 | std::string const expected_name() const 38 | { 39 | if constexpr (std::same_as) 40 | return "char"; 41 | else if constexpr (std::same_as) 42 | return "char16_t const"; 43 | else if constexpr (std::same_as) 44 | return "char32_t &"; 45 | else if constexpr (std::same_as) 46 | return "short*"; 47 | else if constexpr (std::same_as) 48 | return "double const* const"; 49 | else if constexpr (std::same_as const &>) 50 | return "foo::bar const &"; 51 | else if constexpr (std::same_as>>) 52 | #ifdef _LIBCPP_VERSION 53 | return "foo::bar>"; 54 | #else 55 | return "foo::bar >"; 56 | #endif 57 | else 58 | throw std::runtime_error{"Encountered unknown type in test."}; 59 | } 60 | }; 61 | 62 | // Register test. 63 | TYPED_TEST_SUITE(type_inspection, reflection_types, ); 64 | 65 | TYPED_TEST(type_inspection, type_name_as_string) 66 | { 67 | EXPECT_EQ(sharg::detail::type_name_as_string, this->expected_name()); 68 | } 69 | -------------------------------------------------------------------------------- /test/unit/detail/version_check_debug_test.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | #if defined(NDEBUG) 6 | # undef NDEBUG // test in debug mode 7 | #endif 8 | 9 | #include "version_check_test.hpp" 10 | -------------------------------------------------------------------------------- /test/unit/detail/version_check_release_test.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2006-2024, Knut Reinert & Freie Universität Berlin 2 | // SPDX-FileCopyrightText: 2016-2024, Knut Reinert & MPI für molekulare Genetik 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | #if !defined(NDEBUG) 6 | # define NDEBUG // test in release mode 7 | #endif 8 | 9 | #include "version_check_test.hpp" 10 | -------------------------------------------------------------------------------- /test/unit/parser/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | sharg_test (enumeration_names_test.cpp) 6 | sharg_test (format_parse_test.cpp) 7 | sharg_test (format_parse_validators_test.cpp) 8 | sharg_test (parser_design_error_test.cpp) 9 | sharg_test (subcommand_test.cpp) 10 | -------------------------------------------------------------------------------- /test/unit/std/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | sharg_test (charconv_float_test.cpp) 6 | sharg_test (charconv_int_test.cpp) 7 | -------------------------------------------------------------------------------- /test/unit/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2006-2024 Knut Reinert & Freie Universität Berlin 2 | # SPDX-FileCopyrightText: 2016-2024 Knut Reinert & MPI für molekulare Genetik 3 | # SPDX-License-Identifier: BSD-3-Clause 4 | 5 | sharg_test (file_access_test.cpp) 6 | sharg_test (tmp_filename_test.cpp) 7 | --------------------------------------------------------------------------------