From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxim Cournoyer Newsgroups: gmane.lisp.guile.bugs Subject: bug#66046: [PATCH v3 2/3] tests: Add new compile-file tests. Date: Wed, 22 Nov 2023 11:17:51 -0500 Message-ID: <20231122161801.32398-2-maxim.cournoyer@gmail.com> References: <20231122161801.32398-1-maxim.cournoyer@gmail.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4486"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Timothy Sample , Amirouche , Maxim Cournoyer , Daphne Preston-Kendal To: 66046@debbugs.gnu.org Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Wed Nov 22 17:19:23 2023 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1r5pwg-0000xk-J5 for guile-bugs@m.gmane-mx.org; Wed, 22 Nov 2023 17:19:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5pwL-0003RF-Ux; Wed, 22 Nov 2023 11:19:01 -0500 Original-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 1r5pwJ-0003QQ-5D for bug-guile@gnu.org; Wed, 22 Nov 2023 11:18:59 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r5pwI-00039a-TH for bug-guile@gnu.org; Wed, 22 Nov 2023 11:18:58 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r5pwM-0007Wm-5X for bug-guile@gnu.org; Wed, 22 Nov 2023 11:19:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 22 Nov 2023 16:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66046 X-GNU-PR-Package: guile Original-Received: via spool by 66046-submit@debbugs.gnu.org id=B66046.170066989928862 (code B ref 66046); Wed, 22 Nov 2023 16:19:02 +0000 Original-Received: (at 66046) by debbugs.gnu.org; 22 Nov 2023 16:18:19 +0000 Original-Received: from localhost ([127.0.0.1]:59765 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r5pve-0007VQ-Ly for submit@debbugs.gnu.org; Wed, 22 Nov 2023 11:18:19 -0500 Original-Received: from mail-qv1-xf30.google.com ([2607:f8b0:4864:20::f30]:57836) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r5pva-0007Un-Sd for 66046@debbugs.gnu.org; Wed, 22 Nov 2023 11:18:15 -0500 Original-Received: by mail-qv1-xf30.google.com with SMTP id 6a1803df08f44-677fe97ddf8so27588426d6.3 for <66046@debbugs.gnu.org>; Wed, 22 Nov 2023 08:18:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700669886; x=1701274686; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3evInoajaUu4MlpHeBtuNd4sid+gn8/R1yE+pSupXUM=; b=hA41x65O339Z/GQJXXDXXWLF+6bZPAFcEj+EJcSwoepsuY87iS/Dj9a4z9awe62B7E oYGHiY1yv0CIu4Gnm+yrt1+QR12kDFsfPLjVD1hdIx/5hctjVgh5B7tQ8fV8jrY4VCQJ P68ndHECZv19Ddljmavd75J8nyERbiwXmD/tdV4NPZTE2JS+Ler3WBf6N6IxBQaUpll3 jj0CnxL5zPkICvAwPSphhyarIb7V9KOEWAcqVEL0FtRnwSFK1vcplWCmEXlAvqa/g+qj 26wkAy8XtmOJWfgpN42GQmZaZ1qrCDbjMEwMA4D8e5f8qV4CPt7bWL2TgNd1HzzqCKua FpNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700669886; x=1701274686; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3evInoajaUu4MlpHeBtuNd4sid+gn8/R1yE+pSupXUM=; b=FyY43IUbhNsrD4NijVCvFGzPYg6nJgBBnPG6jYB8VXog8Qi2eQJw5F3ejTNFOhLVdd 7WBMRUtyV97egk+dc07VG1fiYXIIUQPzMMx/WDOcp5ITSA4QRpuoOT0mVjqFL9bwJmUL 9DR4zxuW7HSj20dks5fHyuLoYrsJ8bUmJOCQLUuCqoH+VaneGcXhOmhhTC5d6MwhYyDj MQBvGtE6ktfoSZ+nBw+j+VWSJ38V/5skzytpAZafj2BuDlyOaLXPzWv5WE0ZnUvaCWKh x8TKBUS532jwl/MWPgnC6g751O4sp9x5Gw/zIors7viLAjfZghCvZqCpzgZwgsfdye3h wphw== X-Gm-Message-State: AOJu0YzmV35BDLwiXxV8J6OjSucEQcre/Mfyr1nA+dlBcrQsoZ4Xdtwy K7YAQA/OJdWVxufQt0ok9tHkxoJkMv4= X-Google-Smtp-Source: AGHT+IHvcWvM8T5cWqFZuTTmHiS5n9Y1OWhclam8O+SGPBiBRiq4s9G/bzKeZZYdhR9y+/iG9uV3Lg== X-Received: by 2002:a05:6214:27c8:b0:679:5f50:6a63 with SMTP id ge8-20020a05621427c800b006795f506a63mr3072431qvb.26.1700669885706; Wed, 22 Nov 2023 08:18:05 -0800 (PST) Original-Received: from localhost.localdomain (dsl-205-233-124-102.b2b2c.ca. [205.233.124.102]) by smtp.gmail.com with ESMTPSA id s18-20020ad45012000000b00677f33079casm4929450qvo.40.2023.11.22.08.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 08:18:05 -0800 (PST) X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231122161801.32398-1-maxim.cournoyer@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10710 Archived-At: Add a test for bug #66046. To run just the compiler tests: ./meta/guile -L test-suite -L . test-suite/tests/compiler.test * test-suite/tests/compiler.test (with-temporary-directory): New syntax. (delete-file-recursively): New procedure. ("compile-file: relative include works") ("compile-file: relative include works with load path canonicalization"): New tests. --- (no changes since v1) test-suite/tests/compiler.test | 82 +++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/test-suite/tests/compiler.test b/test-suite/tests/compiler.test index a018e0c41..79aee1a0e 100644 --- a/test-suite/tests/compiler.test +++ b/test-suite/tests/compiler.test @@ -1,5 +1,5 @@ ;;;; compiler.test --- tests for the compiler -*- scheme -*- -;;;; Copyright (C) 2008-2014, 2018, 2021-2022 Free Software Foundation, Inc. +;;;; Copyright (C) 2008-2014, 2018, 2021-2023 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -18,15 +18,50 @@ (define-module (tests compiler) #:use-module (test-suite lib) #:use-module (test-suite guile-test) + #:use-module (ice-9 ftw) #:use-module (system base compile) #:use-module ((language tree-il) #:select (tree-il-src call-args)) #:use-module ((system vm loader) #:select (load-thunk-from-memory)) - #:use-module ((system vm program) #:select (program-sources source:addr))) + #:use-module ((system vm program) #:select (program-sources source:addr)) + #:use-module (srfi srfi-26)) (define read-and-compile (@@ (system base compile) read-and-compile)) +;;; Based on 'with-directory-excursion', from (guix build utils). +(define-syntax-rule (with-temporary-directory body ...) + "Run BODY with DIR as the process's current directory." + (let ((init (getcwd)) + (dir (mkdtemp "tempdir.XXXXXX"))) + (dynamic-wind + (lambda () + (chdir dir)) + (lambda () + body ...) + (lambda () + (chdir init) + (delete-file-recursively dir))))) + +;;; XXX: Adapted from (guix build utils). +(define* (delete-file-recursively dir) + "Delete DIR recursively, like `rm -rf', without following symlinks." + (file-system-fold (const #t) ;enter + (lambda (file stat result) ; leaf + (delete-file file)) + (const #t) ; down + (lambda (dir stat result) ; up + (rmdir dir)) + (const #t) ; skip + (lambda (file stat errno result) + (format (current-error-port) + "warning: failed to delete ~a: ~a~%" + file (strerror errno))) + #t + dir + + ;; Don't follow symlinks. + lstat)) (with-test-prefix "basic" @@ -434,3 +469,46 @@ (set! proc ((load-thunk-from-memory bytecode))) (procedure? proc))) (pass-if-equal "proc executes" 42 (proc)))) + +(with-test-prefix "compile-file" + ;; Setup test library sources in a temporary directory. + (let ((hello-sexp '(define-library (hello) + (import (scheme base) + (scheme write)) + (export hello) + (include "hello/hello-impl.scm"))) + (hello-impl-sexp '(begin + (include "../external/nothing.scm") + (include "body.scm"))) + (hello-body-sexp '(define (hello) + (display "hello!\n")))) + (with-temporary-directory + (mkdir "module") + (call-with-output-file "module/hello.scm" + (cut write hello-sexp <>)) + (mkdir "module/hello") + (call-with-output-file "module/hello/hello-impl.scm" + (cut write hello-impl-sexp <>)) + (call-with-output-file "module/hello/body.scm" + (cut write hello-body-sexp <>)) + (mkdir "module/external") + (call-with-output-file "module/external/nothing.scm" (const #t)) + (mkdir "build") + (chdir "build") + + (pass-if "relative include works" + (compile-file "../module/hello.scm" #:output-file "hello.go") + #t) + + ;; This used to fail, because compile-file's #:canonicalization + ;; defaults to 'relative, which causes 'scm_relativize_path' to + ;; strip the prefix not in the load path, to avoid baking an + ;; invalid source file reference in the byte compiled output file + ;; (see: https://bugs.gnu.org/66046). This was fixed by having a + ;; '%file-port-stripped-prefixes' fluid to preserve the stripped + ;; prefix, to be used by 'include' to reconstruct the original + ;; complete relative file name. + (pass-if "relative include works with load path canonicalization" + (add-to-load-path (string-append (getcwd) "/../module")) + (compile-file "../module/hello.scm" #:output-file "hello.go") + #t)))) -- 2.41.0