ocaml / ocaml/dune

Allow CLI arguments when using dune build

Open
#5,692 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

cli
Dominant language
OCaml
Stars
1.9k
Forks
500
Avg merge
15h 21m
Merged PRs (30d)
277

Description

Desired Behavior

Currently, dune exec allows the use of -- to provide the rest of the arguments to the executable. This is a nice feature since I don't have to write

dune build
./path/to/main.exe <args>

Is there a reason why this behaviour doesn't exist for dune build?
The first example that comes to my mind is dune runtest. This is an alias for dune build @runtest

Example

Let's take an alcostest file:

(* Build with `ocamlbuild -pkg alcotest simple.byte` *)

(* A module with functions to test *)
module To_test = struct
  let lowercase = String.lowercase_ascii
end

(* The tests *)
let test_lowercase1 () =
  Alcotest.(check string) "same string" "hello!" (To_test.lowercase "hELLO!")

let test_lowercase2 () =
  Alcotest.(check string) "same string" "hello!" (To_test.lowercase "hello!")

(* Run it *)
let () =
  let open Alcotest in
  run "Utils"
    [
      ("case1", [ test_case "Lower case" `Quick test_lowercase1 ]);
      ("case2", [ test_case "Lower case" `Quick test_lowercase2 ]);
    ]

Running dune runtest will result in:

❯ dune runtest
Testing `Utils'.
This run has ID `RO6YPVEX'.

  [OK]          case1          0   Lower case.
  [OK]          case2          0   Lower case.

Full test results in `~/dune_test/_build/default/tests/_build/_tests/Utils'.
Test Successful in 0.000s. 2 tests run.

Now if I just want to execute case1 I have to write

dune exec -- tests/main.exe test "case1"

Resulting in:

❯ dune exec -- tests/main.exe test "case1"
Testing `Utils'.
This run has ID `E674JOW4'.

  [OK]          case1          0   Lower case.
  [SKIP]        case2          0   Lower case.

Full test results in `~/dune_test/_build/_tests/Utils'.
Test Successful in 0.000s. 1 test run.

I'd like to be able to write:

dune runtest -- "case1"

Is there a reason why this is not possible right now?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing how the dune exec command parses arguments after -- with how dune build and the runtest alias handle command-line arguments. Confirm the intended behavior using the issue's dune runtest -- "case1" example; done means the command forwards those arguments to the test executable while preserving existing build and alias behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
build-system, cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.