diff mbox series

[bug#59487,v2,1/2] build-system/dune: Automatically deduce test-target in most cases.

Message ID 20230111174003.2227-1-raingloom@riseup.net
State New
Headers show
Series [bug#59487,v2,1/2] build-system/dune: Automatically deduce test-target in most cases. | expand

Commit Message

Csepp Jan. 11, 2023, 5:40 p.m. UTC
From: raingloom <raingloom@riseup.net>

guix/build-system/dune.scm (dune-build): tests? defaults to #f.
guix/build/dune-build-system.scm (check): Missing test-target is auto-detected.
---
 guix/build-system/dune.scm       |  2 +-
 guix/build/dune-build-system.scm | 14 ++++++++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

Comments

pukkamustard Jan. 12, 2023, 3:42 p.m. UTC | #1
Thanks for this! I think it is a valuable improvement.

Csepp <raingloom@riseup.net> writes:

> From: raingloom <raingloom@riseup.net>
>
> guix/build-system/dune.scm (dune-build): tests? defaults to #f.

This should be: "test-target defaults to #f".

> +    (let ((program (if jbuild? "jbuilder" "dune"))
> +          (test-target (or test-target
> +                           (cond
> +                            ((file-exists? "tests") "tests")
> +                            ((file-exists? "test") "test")
> +                            (else ".")))))
> +      (apply invoke program "runtest"
> +             (append (if test-target (list test-target) '())
> +                     (if package (list "-p" package)
>                           dune-release-flags)
>                       test-flags))))
>    #t)

I think what Julien ment (and I agree) is that you can completely drop
the checks for the files/directories "tests" or "test" to exist.

In your patch, if test-target is #f and "test" or "tests" do not exist,
then the we will run:

`dune runtest -p package .`

but we could (and maybe should) run just:

`dune runtest -p package`

In fact, we should run this even if the "test" or "tests" directories
exist (otherwise we might miss running some tests placed in other
directories).

So this would be enough:

> +    (let ((program (if jbuild? "jbuilder" "dune")))
> +      (apply invoke program "runtest"
> +             (append (if test-target (list test-target) '())
> +                     (if package (list "-p" package)
>                           dune-release-flags)
>                       test-flags)))

Thinking of this, maybe we can drop the `test-target` argument
completely. wdyt?

-pukkamustard
pukkamustard Jan. 12, 2023, 6:44 p.m. UTC | #2
pukkamustard <pukkamustard@posteo.net> writes:

> Thinking of this, maybe we can drop the `test-target` argument
> completely. wdyt?

Yeah, I'm pretty sure we should drop the test-target argument. I don't
see any reason why it should be used with the dune build-system.

The two remaining packages that have a test-target that is not "test",
"tests" or "." (and do not have tests disabled):

- ocaml-frontc: Builds as expected when test-target is removed.
- ocaml-cohttp: test-target points to a test helper library, not the
  tests themselves. Removing the test-target runs the tests, which
  currently fail.

-pukkamustard
Csepp Jan. 12, 2023, 7:39 p.m. UTC | #3
pukkamustard <pukkamustard@posteo.net> writes:

> Thanks for this! I think it is a valuable improvement.
>
> Csepp <raingloom@riseup.net> writes:
>
>> From: raingloom <raingloom@riseup.net>
>>
>> guix/build-system/dune.scm (dune-build): tests? defaults to #f.
>
> This should be: "test-target defaults to #f".
>
>> +    (let ((program (if jbuild? "jbuilder" "dune"))
>> +          (test-target (or test-target
>> +                           (cond
>> +                            ((file-exists? "tests") "tests")
>> +                            ((file-exists? "test") "test")
>> +                            (else ".")))))
>> +      (apply invoke program "runtest"
>> +             (append (if test-target (list test-target) '())
>> +                     (if package (list "-p" package)
>>                           dune-release-flags)
>>                       test-flags))))
>>    #t)
>
> I think what Julien ment (and I agree) is that you can completely drop
> the checks for the files/directories "tests" or "test" to exist.
>
> In your patch, if test-target is #f and "test" or "tests" do not exist,
> then the we will run:
>
> `dune runtest -p package .`
>
> but we could (and maybe should) run just:
>
> `dune runtest -p package`
>
> In fact, we should run this even if the "test" or "tests" directories
> exist (otherwise we might miss running some tests placed in other
> directories).
>
> So this would be enough:
>
>> +    (let ((program (if jbuild? "jbuilder" "dune")))
>> +      (apply invoke program "runtest"
>> +             (append (if test-target (list test-target) '())
>> +                     (if package (list "-p" package)
>>                           dune-release-flags)
>>                       test-flags)))
>
> Thinking of this, maybe we can drop the `test-target` argument
> completely. wdyt?
>
> -pukkamustard

Hmm, makes sense.  I'll test what complete removal does.
Csepp Jan. 12, 2023, 9:20 p.m. UTC | #4
Csepp <raingloom@riseup.net> writes:

> pukkamustard <pukkamustard@posteo.net> writes:
>
>> Thanks for this! I think it is a valuable improvement.
>>
>> Csepp <raingloom@riseup.net> writes:
>>
>>> From: raingloom <raingloom@riseup.net>
>>>
>>> guix/build-system/dune.scm (dune-build): tests? defaults to #f.
>>
>> This should be: "test-target defaults to #f".
>>
>>> +    (let ((program (if jbuild? "jbuilder" "dune"))
>>> +          (test-target (or test-target
>>> +                           (cond
>>> +                            ((file-exists? "tests") "tests")
>>> +                            ((file-exists? "test") "test")
>>> +                            (else ".")))))
>>> +      (apply invoke program "runtest"
>>> +             (append (if test-target (list test-target) '())
>>> +                     (if package (list "-p" package)
>>>                           dune-release-flags)
>>>                       test-flags))))
>>>    #t)
>>
>> I think what Julien ment (and I agree) is that you can completely drop
>> the checks for the files/directories "tests" or "test" to exist.
>>
>> In your patch, if test-target is #f and "test" or "tests" do not exist,
>> then the we will run:
>>
>> `dune runtest -p package .`
>>
>> but we could (and maybe should) run just:
>>
>> `dune runtest -p package`
>>
>> In fact, we should run this even if the "test" or "tests" directories
>> exist (otherwise we might miss running some tests placed in other
>> directories).
>>
>> So this would be enough:
>>
>>> +    (let ((program (if jbuild? "jbuilder" "dune")))
>>> +      (apply invoke program "runtest"
>>> +             (append (if test-target (list test-target) '())
>>> +                     (if package (list "-p" package)
>>>                           dune-release-flags)
>>>                       test-flags)))
>>
>> Thinking of this, maybe we can drop the `test-target` argument
>> completely. wdyt?
>>
>> -pukkamustard
>
> Hmm, makes sense.  I'll test what complete removal does.

Well ocaml-ppxlib fails and I should be working my MirageOS thesis
stuff, so I'll leave this up to you.  Or I'll get back to it once I
figure out how cross-toolchains are supposed to work.
diff mbox series

Patch

diff --git a/guix/build-system/dune.scm b/guix/build-system/dune.scm
index 12100fd8e8..b531d3c337 100644
--- a/guix/build-system/dune.scm
+++ b/guix/build-system/dune.scm
@@ -107,7 +107,7 @@  (define* (dune-build name inputs
                      (dune-release-flags ''())
                      (tests? #t)
                      (test-flags ''())
-                     (test-target "test")
+                     (test-target #f)
                      (install-target "install")
                      (validate-runpath? #t)
                      (patch-shebangs? #t)
diff --git a/guix/build/dune-build-system.scm b/guix/build/dune-build-system.scm
index e9ccc71057..e1337a3f82 100644
--- a/guix/build/dune-build-system.scm
+++ b/guix/build/dune-build-system.scm
@@ -42,14 +42,20 @@  (define* (build #:key (build-flags '()) (jbuild? #f)
                    build-flags)))
   #t)
 
-(define* (check #:key (test-flags '()) (test-target "test") tests?
+(define* (check #:key (test-flags '()) (test-target #f) tests?
                 (jbuild? #f) (package #f) (dune-release-flags '())
                 #:allow-other-keys)
   "Test the given package."
   (when tests?
-    (let ((program (if jbuild? "jbuilder" "dune")))
-      (apply invoke program "runtest" test-target
-             (append (if package (list "-p" package)
+    (let ((program (if jbuild? "jbuilder" "dune"))
+          (test-target (or test-target
+                           (cond
+                            ((file-exists? "tests") "tests")
+                            ((file-exists? "test") "test")
+                            (else ".")))))
+      (apply invoke program "runtest"
+             (append (if test-target (list test-target) '())
+                     (if package (list "-p" package)
                          dune-release-flags)
                      test-flags))))
   #t)