From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id uNw+HYMwkGEnZQAAgWs5BA (envelope-from ) for ; Sat, 13 Nov 2021 22:39:15 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id IBjwGIMwkGE1EwAAB5/wlQ (envelope-from ) for ; Sat, 13 Nov 2021 21:39:15 +0000 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 1C501327E8 for ; Sat, 13 Nov 2021 22:39:15 +0100 (CET) Received: from localhost ([::1]:51350 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mm0jx-0003XI-LU for larch@yhetil.org; Sat, 13 Nov 2021 16:39:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mm0jm-0003W3-Ph for bug-guix@gnu.org; Sat, 13 Nov 2021 16:39:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:36780) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mm0jm-0001im-Hj for bug-guix@gnu.org; Sat, 13 Nov 2021 16:39:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mm0jm-0003uC-7F for bug-guix@gnu.org; Sat, 13 Nov 2021 16:39:02 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#24937: [PATCH 1/2] =?UTF-8?q?tests:=20Factorize=20'file=3D=3F'.?= Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Sat, 13 Nov 2021 21:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24937 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 24937@debbugs.gnu.org Received: via spool by 24937-submit@debbugs.gnu.org id=B24937.163683948314932 (code B ref 24937); Sat, 13 Nov 2021 21:39:02 +0000 Received: (at 24937) by debbugs.gnu.org; 13 Nov 2021 21:38:03 +0000 Received: from localhost ([127.0.0.1]:48324 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mm0ip-0003sk-2E for submit@debbugs.gnu.org; Sat, 13 Nov 2021 16:38:03 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45512) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mm0im-0003s8-Fe for 24937@debbugs.gnu.org; Sat, 13 Nov 2021 16:38:01 -0500 Received: from [2001:470:142:3::e] (port=33780 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mm0if-0001f1-Sd; Sat, 13 Nov 2021 16:37:53 -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=FHqfOWStYk1HIj1WZ2uIv2f9VooCa9RpmIq3P6FYsRg=; b=NuGbXEEV0dnB2vm8wNVm n0RKAuOUvw6CIHPJOn0s7WWQUiFrFKLUSyWQZSEOYXmN9Vya5cSetsXrkGa2J5XACNryBUF2Atr0O ORdH0a4acU0Wqzz6hrV1K7W0cZZR2uItMZYw0LCUUxidCNqRSy6ISvj0Zu5m/7kN7wdJzvzl6ob1a XuycPHi6cmRc6NS/4GvaHcSFVydwlGd/ryRwXAroy6EA95zcFfX11fNmN+W1fPSJDKSiBF5AdB9jI 3pFB2rntB1ZKWD7WzISkwnbnCD1+iYktYmGcl/gKhQMOW4fBQ4oVuIp8gALoICFFUySXSMuMFrr4V E1C7pa+0TB7M6A==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:63350 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 1mm0if-0000wh-KE; Sat, 13 Nov 2021 16:37:53 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Sat, 13 Nov 2021 22:37:44 +0100 Message-Id: <20211113213745.2601-1-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <87v90wat9n.fsf@gnu.org> References: <87v90wat9n.fsf@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: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1636839555; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=FHqfOWStYk1HIj1WZ2uIv2f9VooCa9RpmIq3P6FYsRg=; b=BahtG7/c8tA27kq/DI4dDm9zCgeSf0VYpwovfzfuoPmOIOS5hGhAkGecBRfUoptkHmZ2t/ 0i0Z+GlRkXX/ppXYsvHRtBhHffNBE75wesVozCXZG3zhhCok4mVoas2X+30arQoMIRZmmP A31wfuFAhvFqJrA/89nmHd/Xd2eOVPFVliboZrst2EckCp4Gim8nMuoFNt5HHLSwK2fwKF zqt+k8g0k99ksV7w0CxEGmyIRiLEdRfUja+i1CkGhQtfvAPR6pEkATpnmyNSLxXUgnyuJs rGbNA99fuQvvGRyaN7uxpK0+N+nuzNsS4JLMU44L8tFEU1K6xdBrOqZolwQA5Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1636839555; a=rsa-sha256; cv=none; b=hxs8s8m7nBmkBgKCghvfbOe6qdfPy0QXToWDgeNBjcWbTtrs2vfG1RBqWhhjR8BLol3jJr Rl3g4FWAgHCBvuH/4IS4PDHJ7ceqvoSG74594ZAgkDY0ySl3cDMvngndfeuXEC+luOEM0x dr71HLA7sitMIkx9i7fplo6fZm7+Kg4C5gCNEIMXvm98fXSGrlho3MqALSv8wut8FxGj6I 2FDCipw9vuoVVDtUMWmvkpq4Zg9gMbLIZGjF4dw68xtJgDUgovKQ6PziCQ+EVibeZdgcXB y719WgpdJu8Oj8U+uF/2cFmwqQtBqw4cksoNvIGEAndT+lEhgH7RaiyDRAY+3Q== 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=NuGbXEEV; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Spam-Score: -1.34 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=NuGbXEEV; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Queue-Id: 1C501327E8 X-Spam-Score: -1.34 X-Migadu-Scanner: scn1.migadu.com X-TUID: Nb4H6WE3TuSx * guix/tests.scm (file=?): Add optional 'stat' parameter. Add fast patch comparing inode numbers. * tests/gexp.scm ("imported-files with file-like objects"): Remove 'file=?' procedure and use the one from (guix tests). --- guix/tests.scm | 30 +++++++++++++++++------------- tests/gexp.scm | 11 +++-------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/guix/tests.scm b/guix/tests.scm index fc3d521163..e1c194340c 100644 --- a/guix/tests.scm +++ b/guix/tests.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès +;;; Copyright © 2013-2021 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -182,18 +182,22 @@ (define (random-bytevector n) (loop (1+ i))) bv)))) -(define (file=? a b) - "Return true if files A and B have the same type and same content." - (and (eq? (stat:type (lstat a)) (stat:type (lstat b))) - (case (stat:type (lstat a)) - ((regular) - (equal? - (call-with-input-file a get-bytevector-all) - (call-with-input-file b get-bytevector-all))) - ((symlink) - (string=? (readlink a) (readlink b))) - (else - (error "what?" (lstat a)))))) +(define* (file=? a b #:optional (stat lstat)) + "Return true if files A and B have the same type and same content. Call +STAT to obtain file metadata." + (let ((sta (stat a)) (stb (stat b))) + (and (eq? (stat:type sta) (stat:type stb)) + (case (stat:type sta) + ((regular) + (or (and (= (stat:ino sta) (stat:ino stb)) + (= (stat:dev sta) (stat:dev stb))) + (equal? + (call-with-input-file a get-bytevector-all) + (call-with-input-file b get-bytevector-all)))) + ((symlink) + (string=? (readlink a) (readlink b))) + (else + (error "what?" (stat a))))))) (define (canonical-file? file) "Return #t if FILE is in the store, is read-only, and its mtime is 1." diff --git a/tests/gexp.scm b/tests/gexp.scm index 39a47d4e8c..0758a49f5f 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès +;;; Copyright © 2014-2021 Ludovic Courtès ;;; Copyright © 2021 Maxime Devos ;;; ;;; This file is part of GNU Guix. @@ -827,19 +827,14 @@ (define (canonical-file? file) (files -> `(("a/b/c" . ,q-scm) ("p/q" . ,plain))) (drv (imported-files files))) - (define (file=? file1 file2) - ;; Assume deduplication is in place. - (= (stat:ino (stat file1)) - (stat:ino (stat file2)))) - (mbegin %store-monad (built-derivations (list (pk 'drv drv))) (mlet %store-monad ((dir -> (derivation->output-path drv)) (plain* (text-file "foo" "bar!")) (q-scm* (interned-file q-scm "c"))) (return - (and (file=? (string-append dir "/a/b/c") q-scm*) - (file=? (string-append dir "/p/q") plain*))))))) + (and (file=? (string-append dir "/a/b/c") q-scm* stat) + (file=? (string-append dir "/p/q") plain* stat))))))) (test-equal "gexp-modules & ungexp" '((bar) (foo)) -- 2.33.0