From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id mMwEHgvEHWTQjgAASxT56A (envelope-from ) for ; Fri, 24 Mar 2023 16:38:51 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id YF/1HQvEHWRjqgAA9RJhRA (envelope-from ) for ; Fri, 24 Mar 2023 16:38:51 +0100 Received: from lists.gnu.org (unknown [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 DED6CA27E for ; Fri, 24 Mar 2023 16:38:50 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pfhgD-0001yu-5c; Fri, 24 Mar 2023 09:42:05 -0400 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 1pfhgA-0001ya-1O for emacs-orgmode@gnu.org; Fri, 24 Mar 2023 09:42:02 -0400 Received: from mout01.posteo.de ([185.67.36.65]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pfheQ-0003Rq-DM for emacs-orgmode@gnu.org; Fri, 24 Mar 2023 09:42:00 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 733FF24030F for ; Fri, 24 Mar 2023 14:39:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1679665187; bh=t8+buHwx04JurhN/CoehwEF6mgs6J7sKEeOoEdLaR8o=; h=From:To:Cc:Subject:Date:From; b=gCO1koSgGZICOYZ64vq3tHlrdYvD8Vr6GiTrcrwPDfSfnNoyCuw0DBOja/qI3bw8K HkkD4Of0/n/dbo2jRAA9+GGYgl05Xdd/ib6HSkOEMeNa2xStnvMLIxlypotKS3xHzg oSFiMG7sPqPYgeNV/Filk0etloCEp16HYzlIOj+kxubJkCtGmry+Eh9JLPNnOo4eC9 Hq9q7ycy90FMPHff7xgyYTEdSV9NR8h0iwMYF0EGSuKyUapGXKo4vC30aXAh/bQS7R WQJ5lhzi2GtGY63OjV6sDZ1q944QMmUK8RlN1ne0WlzkyPMCiCegowAg6wUm36NYjG 8chdW9UNubYFQ== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4PjdrF3TzVz6trV; Fri, 24 Mar 2023 11:34:53 +0100 (CET) From: Ihor Radchenko To: Bruno Barbier Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] Add tests for ob-haskell (GHCi) In-Reply-To: <87h6udozvh.fsf@localhost> References: <6416d214.5d0a0220.d9c1.54aa@mx.google.com> <875yaxvy93.fsf@localhost> <6416e4d9.df0a0220.ce03d.5c4b@mx.google.com> <87h6udozvh.fsf@localhost> Date: Fri, 24 Mar 2023 10:36:52 +0000 Message-ID: <87r0texwor.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@posteo.net; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN ARC-Seal: i=1; s=key1; d=yhetil.org; t=1679672331; a=rsa-sha256; cv=none; b=BQXGp89MrDbm8KJ/dOp8FSZCdxIhq2p3M0jQcQAeTaMT7luFmHI4s9eybGj6DVxDy+I6Se upjOaBpr5+eM0JzjhGLGedp1vsczqinOiXM/P2GmPzYYu5fd11kckMWjYFbbzI7mFE10sR yE02jqTNlpvdtu4jgMgV8jmBJiVhONvEzsz1PZYyizxcB/utxIyWo3jLdak311vvadhHYU w/HZLHNA9ufUGHokFeFFjGNlgNzNbQFDr9ooxYEIgYAJ/neIzTADHiKEjCwrOUsA1XYeda PWwTaq4B7powqkptIsIAWQDNHKG2yexiggXpoBiWJEqEw27ZUFgq/uX5jAhTBw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=gCO1koSg; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1679672331; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=MLYVdTt4Cl7VNuRpzQn4RQ2tSRKrIobebHIY9xhyO9E=; b=eK5LXL4Qo46vVY7BKpVd/9CI0xa3Dj28iT+4qG5wZ/YzY8epA01jcnh0EWUacpogWJ5kWp LvGgd2KYR1u1+R1RSI0ra/j76hvR2ReFQPT70lN3vB4mn1ySAYVTWE/U/7pzKxELWUauco Vu5C3oU5FHOXQSXTJ7DpNf/dJkFdbQ1tv0YdbJCtzBzWWhCYYUnjVWHibYuOyETbsRrwwS v6fUej6nTsqm9BuZu+1Ih9YwzBfmVctNzOVCVrG0+xlj/BEAXnpF0oivIhxIeZN1C3ViT2 +UsEy3R4Up/BOKk2jzV//lcTEbNQS8XJLJrrHlNo6M2iwlIVcEYcqW2hD5MKDA== Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=posteo.net header.s=2017 header.b=gCO1koSg; dmarc=pass (policy=none) header.from=posteo.net; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Scanner: scn1.migadu.com X-Migadu-Spam-Score: -3.75 X-Spam-Score: -3.75 X-Migadu-Queue-Id: DED6CA27E X-TUID: 1chtBmBuJi0K --=-=-= Content-Type: text/plain Ihor Radchenko writes: > We can try the attached patch. Yet another edge case in comint, it > appears. I investigated further and now applied a set of patches that improves prompt filtering in org-comint. https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=a8a516ba330fe8c435334030ffbe371b8c80c877 https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=866ed1a3c5c37cad243085f9a8fa904970e4d614 Further, I tried to incorporate Pareto's suggestion about secondary prompt and cleaned up the original GHCi tests. With the attached set of patches (first one is Bruno's original patch), I get all the tests reliably passing, except the tests left as :expected-result failed. The remaining tests fall into two categories: 1. Tests trying to test :results value vs. :results output in sessions. 2. Tests trying to test for multiple sessions not interfering each other. The first category of tests fails because `org-babel-interpret-haskell' simply cannot distinguish between :results value and :results output. Someone familiar with GHC should handle this problem. For example, by wrapping :results output code in such a way that output is discarded in the GHCi comint buffer. The second category of tests fails because haskell-mode uses a fixed "*haskell*" comint buffer name. As I suggested in another message, a viable approach could be renaming the original "*haskell*" buffer to something else in `org-babel-haskell-initiate-session'. Again, someone more familiar with haskell-mode should judge if such option is truly viable. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-ob-haskell-Add-tests-for-GHCi.patch Content-Transfer-Encoding: quoted-printable >From 1273b5b415fa420e718645452bc75bc7a9407af5 Mon Sep 17 00:00:00 2001 Message-Id: <1273b5b415fa420e718645452bc75bc7a9407af5.1679653723.git.yantar= 92@posteo.net> From: Bruno BARBIER Date: Fri, 18 Nov 2022 20:14:20 +0100 Subject: [PATCH 1/4] ob-haskell: Add tests for GHCi testing/lisp/test-ob-haskell-ghci.el: New file. --- testing/lisp/test-ob-haskell-ghci.el | 428 +++++++++++++++++++++++++++ 1 file changed, 428 insertions(+) create mode 100644 testing/lisp/test-ob-haskell-ghci.el diff --git a/testing/lisp/test-ob-haskell-ghci.el b/testing/lisp/test-ob-ha= skell-ghci.el new file mode 100644 index 000000000..4b1e4669b --- /dev/null +++ b/testing/lisp/test-ob-haskell-ghci.el @@ -0,0 +1,428 @@ +;;; test-ob-haskell-ghci.el --- tests for ob-haskell.el GHCi -*- lexical-= binding: t; -*- + +;; Copyright (c) 2023 Free Software Foundation, Inc. + +;; Authors: Bruno BARBIER + +;; This program 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. + +;; This program 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 this program. If not, see . + +;;; Commentary: +;; + +;;;; Useful references +;; +;; - https://orgmode.org/worg/org-contrib/babel/languages/lang-compat.html + +;;;; FIXME: Random failures +;; +;; To increase the chances of failure when running tests, you can use this= command line: +;; +;; (for I in 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 = 6 7 8 9 10; do make 'BTEST_OB_LANGUAGES=3Dhaskell' BTEST_RE=3D'haskell' tes= t-dirty & done) 2>&1 | grep FAILED +;; + +;;;; Status +;; +;; All the tests should succeed (except for random failures); those +;; flagged with ":expected-result :failed" are known +;; limitations/bugs. Tested with (2023-03-18): +;; +;; | emacs-version | 29.0.60 | +;; | org-version | main@4cad6c8ea (Mar 16 2023) | +;; | haskell-mode | master@20d4e23 (Mar 4 2023) | +;; | ghci | 9.0.2 | + + +;;; Code: +;; + +(require 'org-test "../testing/org-test") +(org-test-for-executable "ghci") +(unless (featurep 'haskell-mode) + (signal 'missing-test-dependency "haskell-mode")) + + +;;; Helpers +;; + +(defun test-ob-haskell-ghci--with-global-session-worker (todo) + "See `test-ob-haskell-ghci--with-global-session-worker'." + (when (get-buffer "*haskell*") + (error "A buffer named '*haskell*' exists. Can't safely test haskell = blocks")) + (unwind-protect (funcall todo) + ;; Kill the "*haskell*" buffer to not pollute other tests. + (when-let ((hb (get-buffer "*haskell*"))) + (with-current-buffer hb + (let ((kill-buffer-query-functions nil) + (kill-buffer-hook nil)) + (kill-buffer hb)))))) + +(defmacro test-ob-haskell-ghci-with-global-session (&rest body) + "Eval BODY in a new session, then destroy the session. +The library ob-haskell doesn't implement session yet. It will +always use a buffer named \"*haskell*\". We kill that buffer +after the source block execution. To be safe, we fail if such a +buffer already exists." + `(test-ob-haskell-ghci--with-global-session-worker (lambda () ,@body))) + +(defun test-ob-haskell-ghci (args content &optional preamble unprotected) + "Execute the code block CONTENT in a new GHCi session; return the result. +Add ARGS to the code block argument line. Insert PREAMBLE +before the code block. When UNPROTECTED is non-nil, don't control +which session is used (i.e. don't call +`test-ob-haskell-ghci--with-global-session-worker')." + (when (listp content) + (setq content (string-join content "\n"))) + (unless preamble + (setq preamble "")) + (let ((todo (lambda () + (org-test-with-temp-text + (concat preamble "\n" "#+begin_src haskell :compile n= o " + args "\n" "" content "\n#+end_src") + (org-babel-execute-src-block))))) + (if unprotected (funcall todo) + (test-ob-haskell-ghci-with-global-session (funcall todo))))) + + +;;; Tests + + +;;;; Temporary tests +;; + +(ert-deftest ob-haskell/check-version () + "Check GHCi version. +Only tested with GHCi 9.0.2." + (should (equal '("linux" "ghc" 9) (test-ob-haskell-ghci "" " +import System.Info +import Data.Version +(os, compilerName, (versionBranch fullCompilerVersion)!!0) +")))) + + +;;;; Hello Worlds. +;; + +(ert-deftest ob-haskell/hello-world-value-pure () + (should (equal "Hello World!" + (test-ob-haskell-ghci "" "\"Hello World!\"")))) + +(ert-deftest ob-haskell/hello-world-value-IO () + (should (equal "Hello World!" + (test-ob-haskell-ghci "" "return \"Hello World!\"")))) + +(ert-deftest ob-haskell/hello-world-output () + (should (equal "Hello World!" + (test-ob-haskell-ghci ":results output" "putStrLn \"Hello= World!\"")))) + +(ert-deftest ob-haskell/hello-world-output-nothing () + :expected-result :failed + (should (equal "" + (test-ob-haskell-ghci ":results output" "return \"Hello W= orld!\"")))) + +(ert-deftest ob-haskell/hello-world-output-multilines () + :expected-result :failed + (should (equal "Hello World!" + (test-ob-haskell-ghci ":results output" " +:{ +main :: IO () +main =3D putStrLn \"Hello World!\" +:} + +main +")))) + +;;;; Sessions +;; + +(ert-deftest ob-haskell/sessions-must-not-share-variables () + "Sessions must not share variables." + :expected-result :failed + (test-ob-haskell-ghci-with-global-session + (test-ob-haskell-ghci ":session s1" "x=3D2" nil :unprotected) + (should (equal 2 (test-ob-haskell-ghci ":session s1" "x" nil :unprotect= ed))) + (test-ob-haskell-ghci ":session s2" "x=3D3" nil :unprotected) + (should-not (equal 3 (test-ob-haskell-ghci ":session s1" "x" nil :unpro= tected))) + )) + +(ert-deftest ob-haskell/no-session-means-one-shot-sessions () + "When no session, use a new session." + :expected-result :failed + (test-ob-haskell-ghci-with-global-session + (test-ob-haskell-ghci "" "x=3D2" nil :unprotected) + (should-not (equal 2 (test-ob-haskell-ghci "" "x" nil :unprotected))))) + + +;;;; Values +;; + +(ert-deftest ob-haskell/value-is-the-last-expression () + "Return the value of the last expression." + (should (equal 3 (test-ob-haskell-ghci "" '("1" "1+1" "1+1+1")))) + (should (equal 3 (test-ob-haskell-ghci "" '("x=3D1" "y=3D1+1" "x+y"))))) + +(ert-deftest ob-haskell/value-is-the-last-expression-2 () + "Return the value of the last expression." + (should (equal 7 (test-ob-haskell-ghci "" " +putStrLn \"a string\" +return \"useless\" +3+4 +")))) + + + +(ert-deftest ob-haskell/eval-numbers () + "Evaluation of numbers." + (should (equal 7 (test-ob-haskell-ghci "" "7"))) + (should (equal 7.5 (test-ob-haskell-ghci "" "7.5"))) + (should (equal 10.0 (test-ob-haskell-ghci "" "10::Double"))) + (should (equal 10 (test-ob-haskell-ghci "" "10::Int")))) + + +(ert-deftest ob-haskell/eval-strings () + "Evaluation of strings." + (should (equal "a string" (test-ob-haskell-ghci "" "\"a string\"")))) + + +;;;; Local variables +(ert-deftest ob-haskell/let-one-line () + "Local definitions on one line." + (should (equal 6 (test-ob-haskell-ghci "" "let { x=3D2; y=3D3 } in x*y")= ))) + +(ert-deftest ob-haskell/let-multilines-1 () + "Local definitions on multiple lines." + :expected-result :failed + (should (equal 6 (test-ob-haskell-ghci "" " +:{ + let { x=3D2 + ; y=3D3 + } + in x*y +:} +")))) + +(ert-deftest ob-haskell/let-multilines-2 () + "Local definitions on multiple lines, relying on indentation." + :expected-result :failed + (should (equal 6 (test-ob-haskell-ghci "" " +:{ + let x=3D2 + y=3D3 + in x*y +:} +")))) + +;;;; Declarations with multiple lines. +(ert-deftest ob-haskell/decl-multilines-1 () + "A multiline declaration, then use it." + (should (equal 3 (test-ob-haskell-ghci "" " +:{ +let length' [] =3D 0 + length' (_:l) =3D 1 + length' l +:} +length' [1,2,3] +")))) + +(ert-deftest ob-haskell/decl-multilines-2 () + "A multiline declaration, then use it." + (should (equal 5 (test-ob-haskell-ghci "" " +:{ +length' :: [a] -> Int +length' [] =3D 0 +length' (_:l) =3D 1 + length' l +:} + +length' [1..5] +")))) + + +(ert-deftest ob-haskell/primes () + "From haskell.org.""" + :expected-result :failed + (should (equal '(2 3 5 7 11 13 17 19 23 29) + (test-ob-haskell-ghci "" " +:{ +primes =3D filterPrime [2..] where + filterPrime (p:xs) =3D + p : filterPrime [x | x <- xs, x `mod` p /=3D 0] +:} + +take 10 primes +")))) + +;;;; Lists +;; + +(ert-deftest ob-haskell/a-simple-list () + "Evaluation of list of values." + (should (equal '(1 2 3) (test-ob-haskell-ghci "" "[1,2,3]")))) + + +(ert-deftest ob-haskell/2D-lists () + "Evaluation of nested lists into a table." + (should (equal '((1 2 3) (4 5 6)) + (test-ob-haskell-ghci "" "[[1..3], [4..6]]")))) + +(ert-deftest ob-haskell/2D-lists-multilines () + "Evaluation of nested lists into a table, as multilines." + :expected-result :failed + (should (equal '((1 2 3) (4 5 6)) + (test-ob-haskell-ghci "" " +:{ +[ [1..3] +, [4..6] +, [7..9] +] +:} +")))) + + +;;;; Data tables +;; + +(ert-deftest ob-haskell/int-table-data () + "From worg: int-table-data." + (should (equal 10 (test-ob-haskell-ghci ":var t=3Dint-table-data" + "sum [sum r | r <- t]" + "#+name: int-table-data + | 1 | 2 | + | 3 | 4 |")))) + +(ert-deftest ob-haskell/float-table-data () + "From worg: float-table-data." + (should (equal 11.0 (test-ob-haskell-ghci ":var t=3Dfloat-table-data" + "sum [sum r | r <- t]" + "#+name: float-table-data + | 1.1 | 2.2 | + | 3.3 | 4.4 |")))) + +(ert-deftest ob-haskell/string-table-data () + "From worg: string-table-data." + (should (equal "abcd" (test-ob-haskell-ghci ":var t=3Dstring-table-data" + "concat [concat r | r <- t]" + "#+name: string-table-data + | a | b | + | c | d |")))) + + +;;;; Not define errors +;; + +(ert-deftest ob-haskell/not-defined () + "Evaluation of undefined variables." + (should (string-match "Variable not in scope" + (test-ob-haskell-ghci "" "notDefined :: IO Int")))) + +(ert-deftest ob-haskell/not-defined-then-defined-1 () + "Evaluation of undefined variables. +This is a valid haskell source, but, invalid when entered one +line at a time in GHCi." + (let ((r (test-ob-haskell-ghci "" " +v :: Int +v =3D 4 +"))) + (should (and r (string-match "Variable not in scope" r))))) + +(ert-deftest ob-haskell/not-defined-then-defined-1-fixed () + "Like not-defined-then-defined-1, but using the mutiline marks." + :expected-result :failed + (let ((r (test-ob-haskell-ghci "" " +:{ + v :: Int + v =3D 4 +:} +"))) + (should (eq nil r)))) + +(ert-deftest ob-haskell/not-defined-then-defined-1-fixed-2 () + "Like not-defined-then-defined-1, but using one line." + (should (eq nil (test-ob-haskell-ghci "" "v =3D 4 :: Int")))) + + + +(ert-deftest ob-haskell/not-defined-then-defined-2 () + "Evaluation of undefined variables, followed by a correct one." + ;; ghci output is: + ;; | :2:1-4: error: + ;; | =E2=80=A2 Variable not in scope: main :: IO () + ;; | =E2=80=A2 Perhaps you meant =E2=80=98min=E2=80=99 (imported fr= om Prelude) + ;; | Hello, World! + ;; and ob-haskell just reports the last line "Hello, World!". + (should (string-match "Variable not in scope" + (test-ob-haskell-ghci ":results output" " +main :: IO () +main =3D putStrLn \"Hello, World!\" +main +")))) + +;;;; Imports +;; + +(ert-deftest ob-haskell/import () + "Import and use library." + (should (equal 65 (test-ob-haskell-ghci "" " +import Data.IORef +r <- newIORef 65 +readIORef r +")))) + +(ert-deftest ob-haskell/import-with-vars () + "Import and use library with vars." + (should (equal 65 (test-ob-haskell-ghci ":var x=3D65" " +import Data.IORef +r <- newIORef x +readIORef r +")))) + +;;;; What is the result? +;; + +(ert-deftest ob-haskell/results-value-1 () + "Don't confuse output and values: nothing." + (should (equal nil (test-ob-haskell-ghci ":results value" "return ()")))) + +(ert-deftest ob-haskell/results-value-2 () + "Don't confuse output and values: a list." + (should (equal '(1 2) (test-ob-haskell-ghci ":results value" "return [1,= 2]")))) + +(ert-deftest ob-haskell/results-value-3 () + "Don't confuse output and values: nothing." + :expected-result :failed + (should (equal nil (test-ob-haskell-ghci ":results value" "putStrLn \"3\= "")))) + +(ert-deftest ob-haskell/results-value-4 () + "Don't confuse output and values: nothing." + :expected-result :failed + (should (equal nil (test-ob-haskell-ghci ":results value" " +putStrLn \"3\" +return () +")))) + + +;;;; GHCi commands +;; + +(ert-deftest ob-haskell/ghci-type () + "The ghci meta command ':type'." + (should (equal "3 :: Num p =3D> p" + (test-ob-haskell-ghci ":results output" ":type 3")))) + +(ert-deftest ob-haskell/ghci-info () + "The ghci meta command ':info' ." + (should (equal "repeat :: a -> [a] -- Defined in =E2=80=98GHC.List=E2= =80=99" + (test-ob-haskell-ghci ":results output" ":info repeat")))) + + +(provide 'test-ob-haskell-ghci) + +;;; test-ob-haskell-ghci.el ends here --=20 2.39.1 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-org-babel-haskell-initiate-session-Remove-secondary-.patch >From 0112cb1b2531a8defb51234844badc74dad07e5e Mon Sep 17 00:00:00 2001 Message-Id: <0112cb1b2531a8defb51234844badc74dad07e5e.1679653723.git.yantar92@posteo.net> In-Reply-To: <1273b5b415fa420e718645452bc75bc7a9407af5.1679653723.git.yantar92@posteo.net> References: <1273b5b415fa420e718645452bc75bc7a9407af5.1679653723.git.yantar92@posteo.net> From: Ihor Radchenko Date: Fri, 24 Mar 2023 11:20:22 +0100 Subject: [PATCH 2/4] org-babel-haskell-initiate-session: Remove secondary prompt * lisp/ob-haskell.el (org-babel-haskell-initiate-session): Set secondary prompt to "". If we do not do this, org-comint may treat secondary prompts as a part of output. --- lisp/ob-haskell.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el index 2b1441c2a..f4197654c 100644 --- a/lisp/ob-haskell.el +++ b/lisp/ob-haskell.el @@ -169,7 +169,14 @@ (defun org-babel-haskell-initiate-session (&optional _session _params) then create one. Return the initialized session." (org-require-package 'inf-haskell "haskell-mode") (or (get-buffer "*haskell*") - (save-window-excursion (run-haskell) (sleep-for 0.25) (current-buffer)))) + (save-window-excursion + (run-haskell) + (sleep-for 0.25) + ;; Disable secondary prompt. + (org-babel-comint-input-command + (current-buffer) + ":set prompt-cont \"\"") + (current-buffer)))) (defun org-babel-load-session:haskell (session body params) "Load BODY into SESSION." -- 2.39.1 --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0003-testing-lisp-test-ob-haskell-ghci.el-Fix-some-tests.patch Content-Transfer-Encoding: quoted-printable >From 99ffca55a5363a14f4f7df96348e2fdeeab68729 Mon Sep 17 00:00:00 2001 Message-Id: <99ffca55a5363a14f4f7df96348e2fdeeab68729.1679653723.git.yantar= 92@posteo.net> In-Reply-To: <1273b5b415fa420e718645452bc75bc7a9407af5.1679653723.git.yanta= r92@posteo.net> References: <1273b5b415fa420e718645452bc75bc7a9407af5.1679653723.git.yantar= 92@posteo.net> From: Ihor Radchenko Date: Fri, 24 Mar 2023 11:25:19 +0100 Subject: [PATCH 3/4] * testing/lisp/test-ob-haskell-ghci.el: Fix some tests (ob-haskell/2D-lists-multilines): (ob-haskell/ghci-info): Fix incorrect test assertions. --- testing/lisp/test-ob-haskell-ghci.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/testing/lisp/test-ob-haskell-ghci.el b/testing/lisp/test-ob-ha= skell-ghci.el index 4b1e4669b..99b2e1973 100644 --- a/testing/lisp/test-ob-haskell-ghci.el +++ b/testing/lisp/test-ob-haskell-ghci.el @@ -275,8 +275,7 @@ (ert-deftest ob-haskell/2D-lists () =20 (ert-deftest ob-haskell/2D-lists-multilines () "Evaluation of nested lists into a table, as multilines." - :expected-result :failed - (should (equal '((1 2 3) (4 5 6)) + (should (equal '((1 2 3) (4 5 6) (7 8 9)) (test-ob-haskell-ghci "" " :{ [ [1..3] @@ -419,8 +418,9 @@ (ert-deftest ob-haskell/ghci-type () =20 (ert-deftest ob-haskell/ghci-info () "The ghci meta command ':info' ." - (should (equal "repeat :: a -> [a] -- Defined in =E2=80=98GHC.List=E2= =80=99" - (test-ob-haskell-ghci ":results output" ":info repeat")))) + (should (string-match-p + "repeat :: a -> \\[a\\][ \t]+-- Defined in =E2=80=98GHC.List=E2= =80=99" + (test-ob-haskell-ghci ":results output" ":info repeat")))) =20 =20 (provide 'test-ob-haskell-ghci) --=20 2.39.1 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0004-testing-lisp-test-ob-haskell-ghci.el-Enable-fixed-te.patch >From eddff6135407975316dfecc8e10fb3e2be47f9ad Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: <1273b5b415fa420e718645452bc75bc7a9407af5.1679653723.git.yantar92@posteo.net> References: <1273b5b415fa420e718645452bc75bc7a9407af5.1679653723.git.yantar92@posteo.net> From: Ihor Radchenko Date: Fri, 24 Mar 2023 11:26:00 +0100 Subject: [PATCH 4/4] * testing/lisp/test-ob-haskell-ghci.el: Enable fixed tests (ob-haskell/hello-world-output-multilines): (ob-haskell/let-multilines-1): (ob-haskell/let-multilines-2): (ob-haskell/primes): (ob-haskell/not-defined-then-defined-1-fixed): Re-enable tests. --- testing/lisp/test-ob-haskell-ghci.el | 5 ----- 1 file changed, 5 deletions(-) diff --git a/testing/lisp/test-ob-haskell-ghci.el b/testing/lisp/test-ob-haskell-ghci.el index 99b2e1973..88f628b72 100644 --- a/testing/lisp/test-ob-haskell-ghci.el +++ b/testing/lisp/test-ob-haskell-ghci.el @@ -131,7 +131,6 @@ (ert-deftest ob-haskell/hello-world-output-nothing () (test-ob-haskell-ghci ":results output" "return \"Hello World!\"")))) (ert-deftest ob-haskell/hello-world-output-multilines () - :expected-result :failed (should (equal "Hello World!" (test-ob-haskell-ghci ":results output" " :{ @@ -201,7 +200,6 @@ (ert-deftest ob-haskell/let-one-line () (ert-deftest ob-haskell/let-multilines-1 () "Local definitions on multiple lines." - :expected-result :failed (should (equal 6 (test-ob-haskell-ghci "" " :{ let { x=2 @@ -213,7 +211,6 @@ (ert-deftest ob-haskell/let-multilines-1 () (ert-deftest ob-haskell/let-multilines-2 () "Local definitions on multiple lines, relying on indentation." - :expected-result :failed (should (equal 6 (test-ob-haskell-ghci "" " :{ let x=2 @@ -248,7 +245,6 @@ (ert-deftest ob-haskell/decl-multilines-2 () (ert-deftest ob-haskell/primes () "From haskell.org.""" - :expected-result :failed (should (equal '(2 3 5 7 11 13 17 19 23 29) (test-ob-haskell-ghci "" " :{ @@ -334,7 +330,6 @@ (ert-deftest ob-haskell/not-defined-then-defined-1 () (ert-deftest ob-haskell/not-defined-then-defined-1-fixed () "Like not-defined-then-defined-1, but using the mutiline marks." - :expected-result :failed (let ((r (test-ob-haskell-ghci "" " :{ v :: Int -- 2.39.1 --=-=-= Content-Type: text/plain -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at --=-=-=--