Merge pull request #272088 from nbraud/mpvScripts/validate

mpvScripts: Add generic tests to all drvs

authored by Peder Bergebakken Sundt and committed by GitHub d914dcf6 b1417122

+59 -5
+56 -4
pkgs/applications/video/mpv/scripts/default.nix
··· 1 1 { lib 2 2 , callPackage 3 3 , config 4 + , runCommand 4 5 }: 5 6 6 - let buildLua = callPackage ./buildLua.nix { }; 7 - in lib.recurseIntoAttrs 8 - ({ 7 + let 8 + buildLua = callPackage ./buildLua.nix { }; 9 + 10 + unionOfDisjoints = lib.fold lib.attrsets.unionOfDisjoint {}; 11 + 12 + addTests = name: drv: let 13 + inherit (drv) scriptName; 14 + scriptPath = "share/mpv/scripts/${scriptName}"; 15 + fullScriptPath = "${drv}/${scriptPath}"; 16 + 17 + in drv.overrideAttrs (old: { passthru = (old.passthru or {}) // { tests = unionOfDisjoints [ 18 + (old.passthru.tests or {}) 19 + 20 + { 21 + scriptName-is-valid = runCommand "mpvScripts.${name}.passthru.tests.scriptName-is-valid" { 22 + meta.maintainers = with lib.maintainers; [ nicoo ]; 23 + preferLocalBuild = true; 24 + } '' 25 + if [ -e "${fullScriptPath}" ]; then 26 + touch $out 27 + else 28 + echo "mpvScripts.\"${name}\" does not contain a script named \"${scriptName}\"" >&2 29 + exit 1 30 + fi 31 + ''; 32 + } 33 + 34 + # can't check whether `fullScriptPath` is a directory, in pure-evaluation mode 35 + (with lib; optionalAttrs (! any (s: hasSuffix s drv.passthru.scriptName) [ ".js" ".lua" ".so" ]) { 36 + single-main-in-script-dir = runCommand "mpvScripts.${name}.passthru.tests.single-main-in-script-dir" { 37 + meta.maintainers = with lib.maintainers; [ nicoo ]; 38 + preferLocalBuild = true; 39 + } '' 40 + die() { 41 + echo "$@" >&2 42 + exit 1 43 + } 44 + 45 + cd "${drv}/${scriptPath}" # so the glob expands to filenames only 46 + mains=( main.* ) 47 + if [ "''${#mains[*]}" -eq 1 ]; then 48 + touch $out 49 + elif [ "''${#mains[*]}" -eq 0 ]; then 50 + die "'${scriptPath}' contains no 'main.*' file" 51 + else 52 + die "'${scriptPath}' contains multiple 'main.*' files:" "''${mains[*]}" 53 + fi 54 + ''; 55 + }) 56 + ]; }; }); 57 + in 58 + 59 + lib.recurseIntoAttrs 60 + (lib.mapAttrs addTests ({ 9 61 acompressor = callPackage ./acompressor.nix { inherit buildLua; }; 10 62 autocrop = callPackage ./autocrop.nix { }; 11 63 autodeint = callPackage ./autodeint.nix { }; ··· 29 81 vr-reversal = callPackage ./vr-reversal.nix { }; 30 82 webtorrent-mpv-hook = callPackage ./webtorrent-mpv-hook.nix { }; 31 83 } 32 - // (callPackage ./occivink.nix { inherit buildLua; })) 84 + // (callPackage ./occivink.nix { inherit buildLua; }))) 33 85 // lib.optionalAttrs config.allowAliases { 34 86 youtube-quality = throw "'youtube-quality' is no longer maintained, use 'quality-menu' instead"; # added 2023-07-14 35 87 }
+2
pkgs/applications/video/mpv/scripts/mpvacious.nix
··· 32 32 runHook postInstall 33 33 ''; 34 34 35 + passthru.scriptName = "mpvacious"; 36 + 35 37 meta = with lib; { 36 38 description = "Adds mpv keybindings to create Anki cards from movies and TV shows"; 37 39 homepage = "https://github.com/Ajatt-Tools/mpvacious";
+1 -1
pkgs/applications/video/mpv/scripts/simple-mpv-webui.nix
··· 13 13 }; 14 14 15 15 scriptPath = "."; 16 - passthru.scriptName = "webui.lua"; 16 + passthru.scriptName = "webui"; 17 17 18 18 meta = with lib; { 19 19 description = "A web based user interface with controls for the mpv mediaplayer";