From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id sNESESRgtGOeFQAAbAwnHQ (envelope-from ) for ; Tue, 03 Jan 2023 18:04:36 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id uCgtECRgtGMGPAAAG6o9tA (envelope-from ) for ; Tue, 03 Jan 2023 18:04:36 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E4444299F3 for ; Tue, 3 Jan 2023 18:04:35 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pCkhp-0001vU-8F; Tue, 03 Jan 2023 12:04:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pCkhn-0001uW-Eg for guix-patches@gnu.org; Tue, 03 Jan 2023 12:04:03 -0500 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pCkhn-0000zu-5A for guix-patches@gnu.org; Tue, 03 Jan 2023 12:04:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pCkhn-0003Gw-0v for guix-patches@gnu.org; Tue, 03 Jan 2023 12:04:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#60520] [PATCH 4/4] refresh: Add CLI tests. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 03 Jan 2023 17:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60520 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 60520@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 60520-submit@debbugs.gnu.org id=B60520.167276542012528 (code B ref 60520); Tue, 03 Jan 2023 17:04:02 +0000 Received: (at 60520) by debbugs.gnu.org; 3 Jan 2023 17:03:40 +0000 Received: from localhost ([127.0.0.1]:46601 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pCkhP-0003Fu-CT for submit@debbugs.gnu.org; Tue, 03 Jan 2023 12:03:40 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54944) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pCkhJ-0003F5-G6 for 60520@debbugs.gnu.org; Tue, 03 Jan 2023 12:03:35 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pCkhE-0000x7-A9; Tue, 03 Jan 2023 12:03:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=b5vnk9vausKntvza+Mf3MXBsw9FqBiYCRdXC6y9B1/U=; b=iRbcfBApMVuoHhAzo0ux hlnhTOmpmNZh+NDyonSJcSoBD17y3crpjuuYps0H1vr2vPViNxxIiVmOgNERNM+30V32pHFHBHEom eBHTH5DsOQorXuF2ZC4WnokR5kbLb8ELMjhEvH6tRxCPiiW2tmSFTMoUzi2rsI3IQlUch1e9rNy8n Ssm1r1KzGOTM30qpgrl8No3Uvkxb2eHz5qNtE6dCfC6v+3T4s0FFt1jHgMJ4DJRLpwqoekhneEhH4 iyyADOn2NKl6ZnlPkRBT6MuN6dyCBT7eVWt6hp5P90f9RdUqkX5KJFViTzzVa6tgBFoI5ZkZK4Oqf dT41yuzKhSsy7A==; Received: from [193.50.110.60] (helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pCkhD-000697-H3; Tue, 03 Jan 2023 12:03:28 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Tue, 3 Jan 2023 18:03:19 +0100 Message-Id: <20230103170319.16637-4-ludo@gnu.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230103170319.16637-1-ludo@gnu.org> References: <20230103170319.16637-1-ludo@gnu.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1672765476; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=b5vnk9vausKntvza+Mf3MXBsw9FqBiYCRdXC6y9B1/U=; b=Ek+azhsZ6D+hXwcZ2/a7TJalRHZZsOXjt3Fg4JGFfCaWUnJNQpV8hk2jXl/jwKO93GHqSM q3pnHvAHTnP5w/BUiI63K7ac1E/TI9xHjA4D54REcAacFEbkbtDjU5JkAr+E9i4v4SmVRa eLqRXgVcSxaSTRcz3cSk9qeUP9szO8i6JMU+glwFWv+JOV94wkwvgrs5mMDkRtaQBP+2i7 JSmnblkkjBD2y33NlnZX90Q7id4Mge/xdA2Sz0wCNn8MWOUApwMa7nnOfU9YtkBurMr8/u 02ePi9XCjEoIqqQwbGltWy2oFjb2JvEn6ZmRgwZlTpCtNDsBunFqkg+IK2Aknw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=iRbcfBAp; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1672765476; a=rsa-sha256; cv=none; b=pi/mMZ31GObKOGCQyhelHLDXGOCbKuJWFK9NT/R2ooPshElybae1nQ5noJmRECldQI9nw3 2bakCZrNX1hRydh2nKiPbMqBC7pbUy0pD65e4PLEgGVdEGjKdeVUUmOUGTzENncOWudPDJ DyTHO/PVPV0DsKIvtRxNyyD8LKT20mtH/po+Bn1X1IEaBEzaMBp3zXgYD8ViPUkLiV8z1v 3DeiYeYn8yrCVI85zPdthWzfrR3iU3IBszrzGw1VHt1OIW+RegfSZ40KELaKARPfpj3q1g R6SUf9TXyl4r8ov4HG8+GbajKEpZ4sxtW3YprLXqtMM3ZN4bHmQN0yFuSOvUkw== X-Spam-Score: -2.96 X-Migadu-Queue-Id: E4444299F3 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=iRbcfBAp; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -2.96 X-TUID: iMMF/h3bEhbf * guix/import/test.scm, tests/guix-refresh.sh: New files. * Makefile.am (MODULES, SH_TESTS): Add them. --- Makefile.am | 4 +- guix/import/test.scm | 88 +++++++++++++++++++++++++++++++ tests/guix-refresh.sh | 117 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 guix/import/test.scm create mode 100644 tests/guix-refresh.sh diff --git a/Makefile.am b/Makefile.am index 8b026b6da6..d9d23eec88 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ # GNU Guix --- Functional package management for GNU -# Copyright © 2012-2022 Ludovic Courtès +# Copyright © 2012-2023 Ludovic Courtès # Copyright © 2013 Andreas Enge # Copyright © 2015, 2017 Alex Kost # Copyright © 2016, 2018 Mathieu Lirzin @@ -289,6 +289,7 @@ MODULES = \ guix/import/print.scm \ guix/import/pypi.scm \ guix/import/stackage.scm \ + guix/import/test.scm \ guix/import/texlive.scm \ guix/import/utils.scm \ guix/scripts.scm \ @@ -595,6 +596,7 @@ SH_TESTS = \ tests/guix-authenticate.sh \ tests/guix-environment.sh \ tests/guix-environment-container.sh \ + tests/guix-refresh.sh \ tests/guix-shell.sh \ tests/guix-shell-export-manifest.sh \ tests/guix-graph.sh \ diff --git a/guix/import/test.scm b/guix/import/test.scm new file mode 100644 index 0000000000..767dcd5b61 --- /dev/null +++ b/guix/import/test.scm @@ -0,0 +1,88 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2023 Ludovic Courtès +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix import test) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:use-module (web uri) + #:use-module (guix packages) + #:use-module (guix upstream) + #:use-module ((guix utils) #:select (version-prefix?)) + #:use-module (ice-9 vlist) + #:use-module (ice-9 match) + #:export (%test-updater)) + +;;; Commentary: +;;; +;;; This module defines a pseudo updater whose sole purpose is to allow +;;; testing of the whole 'guix refresh' command. +;;; +;;; Code: + +(define test-target-version + ;; VHash that maps package names to version/URL tuples. + (make-parameter + (or (and=> (getenv "GUIX_TEST_UPDATER_TARGETS") + (lambda (str) + (alist->vhash (call-with-input-string str read)))) + vlist-null))) + +(define (available-updates package) + "Return the list of available records for PACKAGE." + (vhash-fold* (lambda (version+updates result) + (match version+updates + ((version (updates ...)) + (if (version-prefix? version + (package-version package)) + (append (map (match-lambda + ((version url) + (upstream-source + (package (package-name package)) + (version version) + (urls (list url))))) + updates) + result) + result)))) + '() + (package-name package) + (test-target-version))) + +(define (test-package? package) + "Return true if PACKAGE has pseudo updates available." + (and (not (vlist-null? (test-target-version))) ;cheap test + (pair? (available-updates package)))) + +(define* (import-release package #:key (version #f)) + "Return the record denoting either the latest version of +PACKAGE or VERSION." + (match (available-updates package) + (() #f) + ((sources ...) + (if version + (find (lambda (source) + (string=? (upstream-source-version source) + version)) + sources) + (first sources))))) + +(define %test-updater + (upstream-updater + (name 'test) + (description "Pseudo updater for testing purposes.") + (pred test-package?) + (import import-release))) diff --git a/tests/guix-refresh.sh b/tests/guix-refresh.sh new file mode 100644 index 0000000000..de094a6c1d --- /dev/null +++ b/tests/guix-refresh.sh @@ -0,0 +1,117 @@ +# GNU Guix --- Functional package management for GNU +# Copyright © 2023 Ludovic Courtès +# +# This file is part of GNU Guix. +# +# GNU Guix is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or (at +# your option) any later version. +# +# GNU Guix is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Guix. If not, see . + +# +# Test the 'guix refresh' command-line utility. +# + +guix refresh --version + +manifest="t-guix-refresh-manifest-$$.scm" +module_dir="t-guix-refresh-modules-$$" +trap 'rm -f "$manifest"; rm -rf "$module_dir"' EXIT + +# Tell the 'test' updater what to simulate. +export GUIX_TEST_UPDATER_TARGETS +idutils_version="$(guix package -A ^idutils$ | cut -f2)" +GUIX_TEST_UPDATER_TARGETS=' + (("guile" "3" (("12.5" "file:///dev/null") + ("1.6.4" "file:///dev/null"))) + ("libreoffice" "" (("1.0" "file:///dev/null"))) + ("idutils" "" (("'$idutils_version'" "file:///dev/null"))) + ("the-test-package" "" (("5.5" "file://'$PWD/$module_dir'/source"))))' + +# No newer version available. +! guix refresh -t test idutils +case "$(guix refresh -t test idutils 2>&1)" in + *"$idutils_version"*"already the latest version"*) true;; + *) false;; +esac +! guix refresh -t test libreoffice +case "$(guix refresh -t test libreoffice 2>&1)" in + *"greater than the latest known version"*"1.0"*) true;; + *) false;; +esac + +# Various ways to specify packages. +cat > "$manifest" <manifest (list "guile@3.0")) +EOF +default_IFS="$IFS" +IFS=X +for spec in "guile" \ + "guile@3.0" \ + "-eX(@ (gnu packages guile) guile-3.0)" \ + "-mX$manifest" \ + "guileX-r" \ + "-sXcore" +do + guix refresh -t test $spec + case "$(guix refresh -t test $spec 2>&1)" in + *"would be upgraded"*"12.5"*) + true;; + *) + false;; + esac +done +IFS="$default_IFS" + +# Actually updating. +mkdir "$module_dir" +echo hello > "$module_dir/source" +cat > "$module_dir/sample.scm"<&1)" in + *"failed to find"*"2.0.0"*) true;; + *) false;; +esac +for spec in "guile=1.6.4" "guile@3=1.6.4" +do + guix refresh -t test "$spec" + case "$(guix refresh -t test "$spec" 2>&1)" in + *"would be downgraded"*"1.6.4"*) true;; + *) false;; + esac +done + +# Listing updaters. This should work whether or not networking is available. +guix refresh --list-updaters -- 2.38.1