From 4c1dbd411cf9aa15d6aec2a801eae051b802b0ad Mon Sep 17 00:00:00 2001 From: Yutaro Taira <31821663+9sako6@users.noreply.github.com> Date: Tue, 28 Nov 2023 01:28:00 +0900 Subject: [PATCH] Add `test_` prefix to default test name in `dune init project` (#9257) Signed-off-by: Yutaro Taira <9sako6@gmail.com> Co-authored-by: Etienne Millon --- bin/dune_init.ml | 6 +- doc/changes/9257.md | 2 + doc/quick-start.rst | 6 +- .../test-cases/dune-init.t/run.t | 126 +++++++++--------- 4 files changed, 72 insertions(+), 68 deletions(-) create mode 100644 doc/changes/9257.md diff --git a/bin/dune_init.ml b/bin/dune_init.ml index 85bbb8cd9c8..885d2e49f45 100644 --- a/bin/dune_init.ml +++ b/bin/dune_init.ml @@ -464,10 +464,11 @@ module Component = struct } in let test_target = + let test_name = "test_" ^ Dune_lang.Atom.to_string common.name in test { context = { context with dir = Path.relative dir "test" } ; options = () - ; common + ; common = { common with name = Dune_lang.Atom.of_string test_name } } in let bin_target = @@ -494,10 +495,11 @@ module Component = struct } in let test_target = + let test_name = "test_" ^ Dune_lang.Atom.to_string common.name in test { context = { context with dir = Path.relative dir "test" } ; options = () - ; common + ; common = { common with name = Dune_lang.Atom.of_string test_name } } in lib_target @ test_target diff --git a/doc/changes/9257.md b/doc/changes/9257.md new file mode 100644 index 00000000000..b8baabdd59e --- /dev/null +++ b/doc/changes/9257.md @@ -0,0 +1,2 @@ +- Add `test_` prefix to default test name in `dune init project` (#9257, + fixes #9131, @9sako6) diff --git a/doc/quick-start.rst b/doc/quick-start.rst index 5a665c1f261..aeb825835eb 100644 --- a/doc/quick-start.rst +++ b/doc/quick-start.rst @@ -50,7 +50,7 @@ This creates a project directory that includes the following contents: ├── dune-project ├── test │ ├── dune - │ └── project_name.ml + │ └── test_project_name.ml ├── lib │   └── dune ├── bin @@ -93,7 +93,7 @@ which you can dive deeper into Dune's capabilities: authors and maintainers. Open this in your editor to fill in the placeholder values. See :ref:`dune-project` for details. * The ``test`` directory contains a skeleton for your project's tests. Add to - the tests by editing ``test/project_name.ml``. See :ref:`writing-tests` for + the tests by editing ``test/test_project_name.ml``. See :ref:`writing-tests` for details on testing. * The ``lib`` directory will hold the library you write to provide your executable's core functionality. Add modules to your library by creating new @@ -133,7 +133,7 @@ This creates a project directory that includes the following contents: │   └── dune ├── test │ ├── dune - │ └── project_name.ml + │ └── test_project_name.ml └── project_name.opam Now, enter your project's directory: diff --git a/test/blackbox-tests/test-cases/dune-init.t/run.t b/test/blackbox-tests/test-cases/dune-init.t/run.t index cb8141899ac..4d2bdfaa672 100644 --- a/test/blackbox-tests/test-cases/dune-init.t/run.t +++ b/test/blackbox-tests/test-cases/dune-init.t/run.t @@ -292,37 +292,37 @@ Initializing executable projects We can init a new executable project: - $ dune init proj test_exec_proj - Entering directory 'test_exec_proj' - Success: initialized project component named test_exec_proj - Leaving directory 'test_exec_proj' + $ dune init proj new_exec_proj + Entering directory 'new_exec_proj' + Success: initialized project component named new_exec_proj + Leaving directory 'new_exec_proj' The generated project contains all expected sub-components: - $ ls test_exec_proj/** - test_exec_proj/dune-project - test_exec_proj/test_exec_proj.opam + $ ls new_exec_proj/** + new_exec_proj/dune-project + new_exec_proj/new_exec_proj.opam - test_exec_proj/_build: + new_exec_proj/_build: log - test_exec_proj/bin: + new_exec_proj/bin: dune main.ml - test_exec_proj/lib: + new_exec_proj/lib: dune - test_exec_proj/test: + new_exec_proj/test: dune - test_exec_proj.ml + test_new_exec_proj.ml In particular, the dune-project file has the expected content: - $ cat test_exec_proj/dune-project | sed 's/dune [0-9].[0-9]*/dune $version/g' + $ cat new_exec_proj/dune-project | sed 's/dune [0-9].[0-9]*/dune $version/g' (lang dune $version) - (name test_exec_proj) + (name new_exec_proj) (generate_opam_files true) @@ -338,7 +338,7 @@ In particular, the dune-project file has the expected content: (documentation https://url/to/documentation) (package - (name test_exec_proj) + (name new_exec_proj) (synopsis "A short synopsis") (description "A longer description") (depends ocaml dune) @@ -349,13 +349,13 @@ In particular, the dune-project file has the expected content: We can build the project: - $ dune build --root test_exec_proj - Entering directory 'test_exec_proj' - Leaving directory 'test_exec_proj' + $ dune build --root new_exec_proj + Entering directory 'new_exec_proj' + Leaving directory 'new_exec_proj' And the opam file will be generated as expected - $ cat test_exec_proj/test_exec_proj.opam | sed 's/"dune"/$dune/' + $ cat new_exec_proj/new_exec_proj.opam | sed 's/"dune"/$dune/' # This file is generated by dune, edit dune-project instead opam-version: "2.0" synopsis: "A short synopsis" @@ -390,49 +390,49 @@ And the opam file will be generated as expected We can build and run the resulting executable: - $ dune exec --root test_exec_proj ./bin/main.exe - Entering directory 'test_exec_proj' - Leaving directory 'test_exec_proj' + $ dune exec --root new_exec_proj ./bin/main.exe + Entering directory 'new_exec_proj' + Leaving directory 'new_exec_proj' Hello, World! We can build and run the project's tests: - $ dune exec --root test_exec_proj ./test/test_exec_proj.exe - Entering directory 'test_exec_proj' - Leaving directory 'test_exec_proj' + $ dune exec --root new_exec_proj ./test/test_new_exec_proj.exe + Entering directory 'new_exec_proj' + Leaving directory 'new_exec_proj' Initializing library projects ================================ We can init a new library project: - $ dune init proj test_lib_proj --kind lib - Entering directory 'test_lib_proj' - Success: initialized project component named test_lib_proj - Leaving directory 'test_lib_proj' + $ dune init proj new_lib_proj --kind lib + Entering directory 'new_lib_proj' + Success: initialized project component named new_lib_proj + Leaving directory 'new_lib_proj' The generated project contains all expected sub-components: - $ ls test_lib_proj/** - test_lib_proj/dune-project - test_lib_proj/test_lib_proj.opam + $ ls new_lib_proj/** + new_lib_proj/dune-project + new_lib_proj/new_lib_proj.opam - test_lib_proj/_build: + new_lib_proj/_build: log - test_lib_proj/lib: + new_lib_proj/lib: dune - test_lib_proj/test: + new_lib_proj/test: dune - test_lib_proj.ml + test_new_lib_proj.ml In particular, the dune-project file has the expected content: - $ cat test_lib_proj/dune-project | sed 's/dune [0-9].[0-9]*/dune $version/g' + $ cat new_lib_proj/dune-project | sed 's/dune [0-9].[0-9]*/dune $version/g' (lang dune $version) - (name test_lib_proj) + (name new_lib_proj) (generate_opam_files true) @@ -448,7 +448,7 @@ In particular, the dune-project file has the expected content: (documentation https://url/to/documentation) (package - (name test_lib_proj) + (name new_lib_proj) (synopsis "A short synopsis") (description "A longer description") (depends ocaml dune) @@ -459,13 +459,13 @@ In particular, the dune-project file has the expected content: We can build and install the project: - $ dune build --root test_lib_proj @install - Entering directory 'test_lib_proj' - Leaving directory 'test_lib_proj' + $ dune build --root new_lib_proj @install + Entering directory 'new_lib_proj' + Leaving directory 'new_lib_proj' And the opam file will be generated as expected - $ cat test_lib_proj/test_lib_proj.opam + $ cat new_lib_proj/new_lib_proj.opam # This file is generated by dune, edit dune-project instead opam-version: "2.0" synopsis: "A short synopsis" @@ -500,45 +500,45 @@ And the opam file will be generated as expected And we we can run the tests: - $ dune runtest --root test_lib_proj --display short - Entering directory 'test_lib_proj' - ocamlc test/.test_lib_proj.eobjs/byte/dune__exe__Test_lib_proj.{cmi,cmti} - ocamlopt test/.test_lib_proj.eobjs/native/dune__exe__Test_lib_proj.{cmx,o} - ocamlopt test/test_lib_proj.exe - test_lib_proj alias test/runtest - Leaving directory 'test_lib_proj' + $ dune runtest --root new_lib_proj --display short + Entering directory 'new_lib_proj' + ocamlc test/.test_new_lib_proj.eobjs/byte/dune__exe__Test_new_lib_proj.{cmi,cmti} + ocamlopt test/.test_new_lib_proj.eobjs/native/dune__exe__Test_new_lib_proj.{cmx,o} + ocamlopt test/test_new_lib_proj.exe + test_new_lib_proj alias test/runtest + Leaving directory 'new_lib_proj' Initializing projects using Esy =============================== We can init a project using Esy: - $ dune init proj test_esy_proj --pkg esy - Entering directory 'test_esy_proj' - Success: initialized project component named test_esy_proj - Leaving directory 'test_esy_proj' + $ dune init proj new_esy_proj --pkg esy + Entering directory 'new_esy_proj' + Success: initialized project component named new_esy_proj + Leaving directory 'new_esy_proj' The esy project contains all expected sub-components: - $ ls test_esy_proj/** - test_esy_proj/dune-project - test_esy_proj/package.json + $ ls new_esy_proj/** + new_esy_proj/dune-project + new_esy_proj/package.json - test_esy_proj/_build: + new_esy_proj/_build: log - test_esy_proj/bin: + new_esy_proj/bin: dune main.ml - test_esy_proj/lib: + new_esy_proj/lib: dune - test_esy_proj/test: + new_esy_proj/test: dune - test_esy_proj.ml + test_new_esy_proj.ml And the dune-project file does NOT specify generation of an opam file: - $ cat test_esy_proj/dune-project | grep "generate_opam_files" + $ cat new_esy_proj/dune-project | grep "generate_opam_files" (generate_opam_files false)