From 08fa80c4f778f878b69ae00a8d23538dbf163b87 Mon Sep 17 00:00:00 2001 From: OPNA2608 Date: Thu, 13 Mar 2025 21:00:29 +0100 Subject: [PATCH] Re-Isearch: Add a VM test --- projects/Re-Isearch/default.nix | 3 +- projects/Re-Isearch/test.nix | 106 ++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 projects/Re-Isearch/test.nix diff --git a/projects/Re-Isearch/default.nix b/projects/Re-Isearch/default.nix index d4d53ba45..a401ce529 100644 --- a/projects/Re-Isearch/default.nix +++ b/projects/Re-Isearch/default.nix @@ -19,8 +19,7 @@ examples.re-isearch = { module = ./example.nix; description = ""; - # TODO: index and search a document (see `links.tests`) - tests.search-document = null; + tests.search-document = import ./test.nix args; }; links = { handbook = { diff --git a/projects/Re-Isearch/test.nix b/projects/Re-Isearch/test.nix new file mode 100644 index 000000000..6fcd501d9 --- /dev/null +++ b/projects/Re-Isearch/test.nix @@ -0,0 +1,106 @@ +{ + sources, + lib, + ... +}: +let + docDir = "documents"; + docPath = filename: "${docDir}/${filename}"; + docs = [ + /* + PDF support is not functional, it needs a custom pdftomemo binary from the in-tree xpdf version (/filters/xpdf-3.01-bsn). + + 1. This directory doesn't exist in the re-isearch version that's packaged in Nixpkgs. + 2. The xpdf version in Nixpkgs, which is newer than the one vendored here, is marked + insecure due to multiple unresolved CVEs. + + Leaving the following attrset here, in case PDF support can ever be securely enabled. + */ + /* + { + package = pkgs: pkgs.valgrind.doc; + file = "valgrind_manual.pdf"; + dir = "share/doc/valgrind"; + text = "The Valgrind tool suite provides"; + } + */ + { + package = pkgs: pkgs.man.doc; + file = "man-db-manual.ps"; + dir = "share/doc/man-db"; + text = "man-db originally started out life"; + } + { + package = pkgs: pkgs.nix.doc; + srcFile = "index.html"; + destFile = "nix-manual.html"; + dir = "share/doc/nix/manual"; + # Processing of HTML is very minimal, only certain tags & comments + text = "Nix Reference Manual"; + } + { + package = pkgs: pkgs.docbook2x; + srcFile = "de.xml"; + destFile = "docbook2x-xslt-de.xml"; + dir = "share/docbook2X/xslt/common/text"; + text = "Abbildungsverzeichnis"; + } + { + package = pkgs: pkgs.asymptote.doc; + srcFile = "refs.bib"; + destFile = "asymptote-refs.bib"; + dir = "share/doc/asymptote/examples"; + text = "vector graphics language"; + } + ]; +in +{ + name = "Re-Isearch-search-document"; + + nodes = { + machine = + { pkgs, lib, ... }: + { + imports = [ + sources.modules.ngipkgs + sources.modules.programs.re-isearch + sources.examples.Re-Isearch.re-isearch + ]; + + environment = { + systemPackages = with pkgs; [ + ghostscript_headless # ps2ascii on PATH for postscript support + ]; + etc = lib.attrsets.listToAttrs ( + map (details: { + name = docPath (details.file or details.destFile); + value = { + source = "${details.package pkgs}/${details.dir}/${(details.file or details.srcFile)}"; + }; + }) docs + ); + }; + }; + }; + + testScript = + { nodes, ... }: + '' + start_all() + + # Binary should work on a basic level + with subtest("Binaries are not broken"): + machine.succeed("Iindex -help | grep -q 'Usage is:'") + + # Index collected documents + with subtest("Indexing the collected documents works"): + machine.succeed("Iindex -d /root/re-isearch-db /etc/${docDir} >&2") + + # Search for unique strings in each document + ${lib.strings.concatMapStringsSep "\n" (details: '' + with subtest("Searching ${details.file or details.destFile} works"): + machine.succeed("Isearch -d /root/re-isearch-db -q '${details.text}' | tee /root/output >&2") + machine.succeed("grep -q '1 record of' /root/output") + '') docs} + ''; +}