Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test_ prefix to default test name in dune init project #9257

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bin/dune_init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/9257.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add `test_` prefix to default test name in `dune init project` (#9257,
fixes #9131, @9sako6)
6 changes: 3 additions & 3 deletions doc/quick-start.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
126 changes: 63 additions & 63 deletions test/blackbox-tests/test-cases/dune-init.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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"
Expand Down Expand Up @@ -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)