From d5df4a568552a569b959c52ab7e990476f62982e Mon Sep 17 00:00:00 2001 From: Friedrich Rober Date: Thu, 14 Dec 2023 16:59:31 +0100 Subject: [PATCH] Add doc tests --- .github/workflows/CI.yml | 1 + .gitignore | 4 +++- dev/tests_doc/README.md | 9 +++++++++ dev/tests_doc/processTests.sh | 37 +++++++++++++++++++++++++++++++++++ makedoc.g | 3 +++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 dev/tests_doc/README.md create mode 100755 dev/tests_doc/processTests.sh diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index d93ae12..919f109 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -34,6 +34,7 @@ jobs: GAPBRANCH: ${{ matrix.gap-branch }} GAP_PKGS_TO_BUILD: "io profiling grape cohomolo" - uses: gap-actions/build-pkg@v1 + - uses: gap-actions/build-pkg-docs@v1 - uses: gap-actions/run-pkg-tests@v2 - uses: gap-actions/process-coverage@v2 - uses: codecov/codecov-action@v3 diff --git a/.gitignore b/.gitignore index 950d0ab..8bec6f5 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,6 @@ /gh-pages/ -_dev \ No newline at end of file +_dev + +/tst/files/doc/ diff --git a/dev/tests_doc/README.md b/dev/tests_doc/README.md new file mode 100644 index 0000000..056c6ef --- /dev/null +++ b/dev/tests_doc/README.md @@ -0,0 +1,9 @@ +# Introduction +The files in this directory are used to post-process test files +that are extracted from the documentation examples. + +# Main Files +- `processTests.sh` : processes all doc tests and moves them into `tst/files/doc`. + +# Instructions +In order to post-process the tests and move them into `tst/files/doc` automatically, one needs to execute `processTests.sh` from any place. diff --git a/dev/tests_doc/processTests.sh b/dev/tests_doc/processTests.sh new file mode 100755 index 0000000..2327872 --- /dev/null +++ b/dev/tests_doc/processTests.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# go to root of repo +script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +cd $script_dir/../.. +echo "Working in folder $(pwd)" + +# get operating system +unameOut="$(uname -s)" +case "${unameOut}" in + Linux*) machine=Linux;; + Darwin*) machine=Mac;; + CYGWIN*) machine=Cygwin;; + MINGW*) machine=MinGw;; + *) machine="UNKNOWN:${unameOut}" +esac + + +# Post-processing for the extracted examples from the documentation. +# - Add a "\n" to all Print executions. +# - Move files into test_dir +test_dir="tst/files/doc" +mkdir -p $test_dir +files=($(ls -1 tst/lins*.tst)) +echo "Found ${#files[@]} test file(s)" +for file in ${files[@]}; do + echo "Processing $file" + if [ "${machine}" == "Mac" ]; then + sed -i "" 's|Print(\(.*\));|Print(\1, \"\\n\");|g' $file + elif [ "${machine}" == "Linux" ]; then + sed -i 's|Print(\(.*\));|Print(\1, \"\\n\");|g' $file + else + echo "ERROR: Unsupported operating system ${machine}" + exit 1 + fi; + mv $file $test_dir/${file#"tst/"} +done diff --git a/makedoc.g b/makedoc.g index 4588a7c..fe4d4bb 100644 --- a/makedoc.g +++ b/makedoc.g @@ -25,4 +25,7 @@ AutoDoc( rec( scaffold := rec( "license.xml", ], ), + extract_examples := true, autodoc := true ) ); + +Exec("dev/tests_doc/processTests.sh");