From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id YDgcI2CVVGDsEAAA0tVLHw (envelope-from ) for ; Fri, 19 Mar 2021 12:13:20 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id +KbYHmCVVGAkTwAAB5/wlQ (envelope-from ) for ; Fri, 19 Mar 2021 12:13:20 +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 C808E19155 for ; Fri, 19 Mar 2021 13:13:19 +0100 (CET) Received: from localhost ([::1]:53866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lNE0E-0006cN-KZ for larch@yhetil.org; Fri, 19 Mar 2021 08:13:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44576) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNDxO-0004yJ-SU for emacs-orgmode@gnu.org; Fri, 19 Mar 2021 08:10:25 -0400 Received: from ciao.gmane.io ([116.202.254.214]:34144) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lNDxK-00016b-6f for emacs-orgmode@gnu.org; Fri, 19 Mar 2021 08:10:20 -0400 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lNDxF-00023d-Tn for emacs-orgmode@gnu.org; Fri, 19 Mar 2021 13:10:13 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Maxim Nikulin Subject: Re: [PATCH] Re: Bug: Plain https links with brackets are not recognised [9.4.4 (release_9.4.4-625-g763c7a @ /home/yantar92/.emacs.d/straight/build/org/)] Date: Fri, 19 Mar 2021 19:10:07 +0700 Message-ID: References: <87pn03g3rr.fsf@localhost> <87sg4zu47p.fsf@kyleam.com> <87k0qbk4rq.fsf@localhost> <87h7lfk4mz.fsf@localhost> <8735wvuvi3.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 In-Reply-To: <8735wvuvi3.fsf@localhost> Content-Language: en-US Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 28 X-Spam_score: 2.8 X-Spam_bar: ++ X-Spam_report: (2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, NICE_REPLY_A=-0.001, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 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" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1616155999; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Zrbul4nY0crEB8GLFe9Kz24ogZ+AthBT5adsSwOsDss=; b=iIQ5v5CT6LnlOSSExXt4bAHpJY+xss9LAzutnhkw00Zo8aLs2kP+q2O/erwTUbGCj8VWpj Hl1n27UQo788SAhOnlv0IMJjPgMKVUQ5ko2Fofax1Mk68YaeZnNdtCAttmzPWfLHdYwDVW 9eH/VCtMWiasrL4cnNWbTqOT1jEtNNxWQY+dr205BXDfbzUxFk+fuEAcDfcGw5IaG1KaLK 83WSw92FrHY/foRsEyIikkNb5sgo+Zgs9ZegjXUSGrfXQ6h83oHGlBDKWw2OvPgfVK6uCS 5I4oooDDQxvIIZp8MyXrr0uXutDrB69rZNOON66CrLsNYtBUdLn+cAHQGHQt+Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1616155999; a=rsa-sha256; cv=none; b=sQSM2vcVKfHUh8WNmJC5IznMOO8QP8/dlzyRE6JPf9ztDQ4XDQ0y2yMevfVIejF+PfzscP NtdhI9HAzK+6yZhusC4lvtbpqLZADIaPo3U7xBuG6bvH+BUbCOUW/r63DiLYUrz3WH7Yj/ HGwC1jj7VioPz+519bDhzMzD4J5GjwgCAUicUHw83QhToUUWj3w5CZ3Dlga7mJS2QLHnvx MsjxUKgDe+THqE/cmurCryEIjr4Rn6N3JsjVozecOqG7Kdc650ke5Bgxiapr8niuFpZrys /XPf+Jsfu8A/efZbMWrjQz9o2lqyo7Iv5lRqaGdIowQ2umYb/0Z5LWEowVdkOA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -1.81 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: C808E19155 X-Spam-Score: -1.81 X-Migadu-Scanner: scn0.migadu.com X-TUID: G7KOekH8esNs On 16/03/2021 19:35, Ihor Radchenko wrote: > +;;; Link regexps > + > +(ert-deftest test-ol/plain-link-re () > + "Test `org-link-plain-re'." > + (should > + (equal > + '("https" "//example.com/qwe()") > + (org-test-with-temp-text > + "(Some text in parenthesis followed by link with brackets https://example.com/qwe())" > + (list (org-element-property :type (org-element-link-parser)) > + (org-element-property :path (org-element-link-parser)))))) > + (should > + (equal > + '("https" "//doi.org/10.1016/0160-791x(79)90023-x") > + (org-test-with-temp-text > + "https://doi.org/10.1016/0160-791x(79)90023-x" > + (list (org-element-property :type (org-element-link-parser)) > + (org-element-property :path (org-element-link-parser)))))) To be clear, I do not ask for any changes. It is great to have some tests even in the current form. I just have never tried ert before, so I have some questions. Am I right that just one failure will be reported if a change in the regexp causes problems with several test inputs? I am afraid, it is rather inconvenient since this tests are rather for quality of heuristics than exact requirements. To find proper balance of accuracy and speed/regexp complexity, it is better to have all failures at once. I am looking up for a feature like EXPECT_EQ (delayed failure) in addition to strict ASSERT_EQ in googletest or at least like TestCase.subTest in puthon unittest. For this particular case even parametrized tests are enough (googletest, pytest). I have tried implement something similar to illustrate my expectations. I think, for experienced lisp programmers the code looks ugly (defmacro test-ol/deftest-parametrized (prefix func &rest cases) (declare (indent 2)) (cons #'progn (mapcar (lambda (case) (pcase-let ((`(,id ,docstring ,expect ,arguments) case)) (let ((test (intern (concat prefix "--" id))) (exp (if (and expect (listp expect)) `'(,@expect) expect)) (args (if (listp arguments) arguments (list arguments)))) `(ert-deftest ,test () ,docstring (should (equal ,exp ,(cons func args))))))) cases))) (defun test-ol/match-link-plain (text) (and (string-match org-link-plain-re text) (mapcar (lambda (i) (match-string-no-properties i text)) ;; Currently there is a useless additional group ;; and I think it should cause failure. ;; (number-sequence 1 (- (/ (length (match-data)) 2) 1) 1) '(1 2)))) (test-ol/deftest-parametrized "test-ol/org-link-plain-re" test-ol/match-link-plain ("sheme-only" "No match without host or path" nil "Secure https: connection") ("scheme-slashes" "Questionable case with no host or path" ("file" "///") "Use file:/// for local files") ("simple-link" "Simple link" ("https" "//orgmode.org/") "Link https://orgmode.org/ to Org site") ("false-match" "Failure example: unexpected match" nil "Valid file:///bin/bash link") ("failed-match" "Failure example: host-path is too short to match" ("https" "a") "file:a") ("a-typo" "Failure example: slashes missed in expectation" ("http" "www.gnu.org") "http://www.gnu.org/")) (ert t) In my opinion, test report is acceptable FFF... F test-ol/org-link-plain-re--a-typo Failure example: slashes missed in expectation (ert-test-failed ((should (equal '("http" "www.gnu.org") (test-ol/match-link-plain "http://www.gnu.org/"))) :form (equal ("http" "www.gnu.org") ("http" "//www.gnu.org/")) :value nil :explanation (list-elt 1 (arrays-of-different-length 11 14 "www.gnu.org" "//www.gnu.org/" first-mismatch-at 0)))) F test-ol/org-link-plain-re--failed-match Failure example: host-path is too short to match (ert-test-failed ((should (equal '("https" "a") (test-ol/match-link-plain "file:a"))) :form (equal ("https" "a") nil) :value nil :explanation (different-types ("https" "a") nil))) F test-ol/org-link-plain-re--false-match Failure example: unexpected match (ert-test-failed ((should (equal nil (test-ol/match-link-plain "Valid file:///bin/bash link"))) :form (equal nil ("file" "///bin/bash")) :value nil :explanation (different-types nil ("file" "///bin/bash")))) I do not know if it is possible to implement "might" (in addition to "should") that using restart or some other technique will prevent immediate abandoning of the test but will mark whole test as failed at the end. Actually I hope to get response that I am trying to reinvent a wheel and org or emacs has an established way to write tests feeding the same function with list of cases and to get all failures in a reasonably readable report.