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 v2 2/3] tests: Add new compile-file tests. Date: Wed, 22 Nov 2023 11:11:43 -0500 Message-ID: <20231122161204.26366-2-maxim.cournoyer@gmail.com> References: <20231122161204.26366-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="14489"; 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:13:33 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 1r5pr3-0003a1-Bw for guile-bugs@m.gmane-mx.org; Wed, 22 Nov 2023 17:13:33 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r5pqX-0002Ec-02; Wed, 22 Nov 2023 11:13: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 1r5pqV-0002E4-5I for bug-guile@gnu.org; Wed, 22 Nov 2023 11:12: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 1r5pqU-0002Dt-TY for bug-guile@gnu.org; Wed, 22 Nov 2023 11:12:58 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1r5pqY-0007LP-7O for bug-guile@gnu.org; Wed, 22 Nov 2023 11:13: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:13: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.170066954428166 (code B ref 66046); Wed, 22 Nov 2023 16:13:02 +0000 Original-Received: (at 66046) by debbugs.gnu.org; 22 Nov 2023 16:12:24 +0000 Original-Received: from localhost ([127.0.0.1]:59745 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r5ppw-0007KD-0v for submit@debbugs.gnu.org; Wed, 22 Nov 2023 11:12:24 -0500 Original-Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]:58809) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1r5pps-0007Jc-TJ for 66046@debbugs.gnu.org; Wed, 22 Nov 2023 11:12:21 -0500 Original-Received: by mail-qt1-x82b.google.com with SMTP id d75a77b69052e-41cd6e1d4fbso40236861cf.1 for <66046@debbugs.gnu.org>; Wed, 22 Nov 2023 08:12:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700669531; x=1701274331; 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=58oI9SllunaQP3TOW4qWNDVhjQenNZTXGnLoGKDYgMM=; b=LijUyKP8gOfayNmYa/AQlT7rbMi+v/Hb8A/lL5yXyqRg7qa3beeCu/qinEMfvuQIFf zlZ0q1zaIa/w3AyfjkVXuYjK5RnX7xHRZN74NUDnT9Y/3qEJX1CTEXOetnOD+1ecC8+o 9clDQzknMPV3kbLOo6SdLM4+pQ6kZCWzY1fKHvlb+XGrehI3WyJcx6bbCnYJoGl9yNqj 4VT9wiLJiTlBJlMNFybdAHR4IjJPMqDGgq/P6t7dgmfwOEh7OrRhDyDMQ+IRzDzkLC3t yiNYJ+gDBUUGVyiUPuU5AmkRQapSB4kZuzMTLQYzOwOjtbEnOJAGhYOivwkNMr5GkYTY CrQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700669531; x=1701274331; 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=58oI9SllunaQP3TOW4qWNDVhjQenNZTXGnLoGKDYgMM=; b=qMdewQOKaWoZbUyl3KPrSvWMkfTLLFfk/vEbQXilpzzd/yfCHP4qMW3y2VVnUm2RpG Xg/XqP3k9aIxdBvRjxkh5ilA19G/5whrBnE14ImJ2+tGNeKDfVYuGxXWRnoIs6pVClGY LW/pboLeyawFtx0A7AdlAs6KogBJph0wpB6FjqVD6Qny+CfWicdM0hRAbEiKV4tkv7Zd 1yDEJ6LHAI5BddB8iA7K8qQsROHU6kXx29NqEZm7LpAAd0zWljAAvr24DcVwki233m5P iFuN0x3gKQeisuRv+ztCS08DZnxCY6NS9L+h1lZ4UOHYPRrchOt/WfLKZLlQzRdFcNvd oYBA== X-Gm-Message-State: AOJu0Yy8iIBFwL0j9yL9mJo6rkwIg6LynzWrJ37n1rUtDpdZO6y0MVKZ KDyn9bljhJsQS41plrmPYYBtkC3AKO4= X-Google-Smtp-Source: AGHT+IEhrADEgDtsXttxg1f/HGiYYnqCyJwhwmYgfgQ2WmrOLyD0XeeBIQ7lQiGC6T1zec6NyVzrLA== X-Received: by 2002:ac8:5d4b:0:b0:41e:287d:f56a with SMTP id g11-20020ac85d4b000000b0041e287df56amr3829927qtx.47.1700669531537; Wed, 22 Nov 2023 08:12:11 -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 u7-20020ac87507000000b00419b9b1b0b0sm4516257qtq.56.2023.11.22.08.12.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 08:12:11 -0800 (PST) X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231122161204.26366-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:10708 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..ff923095a 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 caused '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 + ;; 'compilation-source-file' fluid that preserves the file name + ;; passed to 'compile-file', used by 'include' instead of the file + ;; name of the port. + (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