at 23.05-pre 2.9 kB view raw
1 2import ./make-test-python.nix ({ pkgs, lib, ... }: let 3 manImplementations = [ 4 "mandoc" 5 "man-db" 6 ]; 7 8 machineNames = builtins.map machineSafe manImplementations; 9 10 makeConfig = useImpl: { 11 # Note: mandoc currently can't index symlinked section directories. 12 # So if a man section comes from one package exclusively (e. g. 13 # 1p from man-pages-posix and 2 from man-pages), it isn't searchable. 14 environment.systemPackages = [ 15 pkgs.man-pages 16 pkgs.openssl 17 pkgs.libunwind 18 ]; 19 20 documentation = { 21 enable = true; 22 nixos.enable = lib.mkForce true; 23 dev.enable = true; 24 man = { 25 enable = true; 26 generateCaches = true; 27 } // lib.listToAttrs (builtins.map (impl: { 28 name = impl; 29 value = { 30 enable = useImpl == impl; 31 }; 32 }) manImplementations); 33 }; 34 }; 35 36 machineSafe = builtins.replaceStrings [ "-" ] [ "_" ]; 37in { 38 name = "man"; 39 meta.maintainers = [ lib.maintainers.sternenseemann ]; 40 41 nodes = lib.listToAttrs (builtins.map (i: { 42 name = machineSafe i; 43 value = makeConfig i; 44 }) manImplementations); 45 46 testScript = '' 47 import re 48 start_all() 49 50 def match_man_k(page, section, haystack): 51 """ 52 Check if the man page {page}({section}) occurs in 53 the output of `man -k` given as haystack. Note: 54 This is not super reliable, e. g. it can't deal 55 with man pages that are in multiple sections. 56 """ 57 58 for line in haystack.split("\n"): 59 # man -k can look like this: 60 # page(3) - bla 61 # page (3) - bla 62 # pagea, pageb (3, 3P) - foo 63 # pagea, pageb, pagec(3) - bar 64 pages = line.split("(")[0] 65 sections = re.search("\\([a-zA-Z1-9, ]+\\)", line) 66 if sections is None: 67 continue 68 else: 69 sections = sections.group(0)[1:-1] 70 71 if page in pages and f'{section}' in sections: 72 return True 73 74 return False 75 76 '' + lib.concatMapStrings (machine: '' 77 with subtest("Test direct man page lookups in ${machine}"): 78 # man works 79 ${machine}.succeed("man man > /dev/null") 80 # devman works 81 ${machine}.succeed("man 3 libunwind > /dev/null") 82 # NixOS configuration man page is installed 83 ${machine}.succeed("man configuration.nix > /dev/null") 84 85 with subtest("Test generateCaches via man -k in ${machine}"): 86 expected = [ 87 ("openssl", "ssl", 3), 88 ("unwind", "libunwind", 3), 89 ("user", "useradd", 8), 90 ("user", "userdel", 8), 91 ("mem", "free", 3), 92 ("mem", "free", 1), 93 ] 94 95 for (keyword, page, section) in expected: 96 matches = ${machine}.succeed(f"man -k {keyword}") 97 if not match_man_k(page, section, matches): 98 raise Exception(f"{page}({section}) missing in matches: {matches}") 99 '') machineNames; 100})