You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The short answer for why we need to do this is so we can consistently do
`#include "nix/..."`. Without this change, there are ways to still make
that work, but they are hacky, and they have downsides such as making it
harder to make sure headers from the wrong Nix library (e..g.
`libnixexpr` headers in `libnixutil`) aren't being used.
The C API alraedy used `nix_api_*`, so its headers are *not* put in
subdirectories accordingly.
Progress on #7876
We resisted doing this for a while because it would be annoying to not
have the header source file pairs close by / easy to change file
path/name from one to the other. But I am ameliorating that with
symlinks in the next commit.
Copy file name to clipboardexpand all lines: doc/manual/source/development/testing.md
+8-4
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks.
31
31
> ├── libexpr
32
32
> │ ├── meson.build
33
33
> │ ├── value/context.hh
34
-
> │ ├── value/context.cc
34
+
> │ ├── include/nix/value/context.cc
35
35
> │ …
36
36
> │
37
37
> ├── tests
@@ -46,8 +46,12 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks.
46
46
> │ │
47
47
> │ ├── libexpr-test-support
48
48
> │ │ ├── meson.build
49
+
> │ │ ├── include/nix
50
+
> │ │ │ ├── meson.build
51
+
> │ │ │ └── tests
52
+
> │ │ │ ├── value/context.hh
53
+
> │ │ │ …
49
54
> │ │ └── tests
50
-
> │ │ ├── value/context.hh
51
55
> │ │ ├── value/context.cc
52
56
> │ │ …
53
57
> │ │
@@ -59,15 +63,15 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks.
59
63
> ```
60
64
61
65
The tests for each Nix library (`libnixexpr`, `libnixstore`, etc..) live inside a directory `src/${library_name_without-nix}-test`.
62
-
Given an interface (header) and implementation pair in the original library, say, `src/libexpr/value/context.{hh,cc}`, we write tests for it in `src/libexpr-tests/value/context.cc`, and (possibly) declare/define additional interfaces for testing purposes in `src/libexpr-test-support/tests/value/context.{hh,cc}`.
66
+
Given an interface (header) and implementation pair in the original library, say, `src/libexpr/include/nix/value/context.hh` and `src/libexpr/value/context.cc`, we write tests for it in `src/libexpr-tests/value/context.cc`, and (possibly) declare/define additional interfaces for testing purposes in `src/libexpr-test-support/include/nix/tests/value/context.hh` and `src/libexpr-test-support/tests/value/context.cc`.
63
67
64
68
Data for unit tests is stored in a `data` subdir of the directory for each unit test executable.
65
69
For example, `libnixstore` code is in `src/libstore`, and its test data is in `src/libstore-tests/data`.
66
70
The path to the `src/${library_name_without-nix}-test/data` directory is passed to the unit test executable with the environment variable `_NIX_TEST_UNIT_DATA`.
67
71
Note that each executable only gets the data for its tests.
68
72
69
73
The unit test libraries are in `src/${library_name_without-nix}-test-support`.
70
-
All headers are in a `tests` subdirectory so they are included with `#include "tests/"`.
74
+
All headers are in a `tests` subdirectory so they are included with `#include "nix/tests/"`.
71
75
72
76
The use of all these separate directories for the unit tests might seem inconvenient, as for example the tests are not "right next to" the part of the code they are testing.
73
77
But organizing the tests this way has one big benefit:
0 commit comments