Skip to content

Commit adb3593

Browse files
committed
test(lib): share private only-packages fixture
Extract the repeated two-package project used by lib-private and libexec-private --only-packages tests into a shared helper parameterized by the macro under test and optional lib1 fields. Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
1 parent d899767 commit adb3593

3 files changed

Lines changed: 35 additions & 45 deletions

File tree

test/blackbox-tests/setup-script.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,37 @@ write_bin_pform_inline_tests_fixture() {
483483
: > testlib.ml
484484
}
485485

486+
make_private_only_packages_project() {
487+
local macro="$1"
488+
local lib1_extra="${2:-}"
489+
490+
mkdir lib-private-only-packages
491+
cd lib-private-only-packages || return
492+
mkdir lib1 lib2
493+
cat >dune-project <<-'EOF'
494+
(lang dune 2.8)
495+
(name lib-private-test)
496+
(package (name public_lib1))
497+
(package (name public_lib2))
498+
EOF
499+
{
500+
echo "(library"
501+
echo " (name lib1)"
502+
if [ -n "$lib1_extra" ]; then
503+
echo " ${lib1_extra}"
504+
fi
505+
echo " (public_name public_lib1))"
506+
} > lib1/dune
507+
touch lib1/lib1.ml
508+
cat >lib2/dune <<- EOF
509+
(library
510+
(name lib2)
511+
(public_name public_lib2))
512+
(rule
513+
(with-stdout-to lib2.ml (echo "let _ = {|%{${macro}:lib1:lib1.ml}|}")))
514+
EOF
515+
}
516+
486517
make_melange_virtual_time_project() {
487518
local vlib_public_name="$1"
488519
local impl_public_name="$2"

test/blackbox-tests/test-cases/lib.t

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -221,28 +221,7 @@ Testsuite for the %{lib...} and %{lib-private...} variable.
221221
In this test, two packages are defined in the same project, but we may not
222222
access the artifacts through %{lib-private}
223223

224-
$ mkdir lib-private-only-packages
225-
$ cd lib-private-only-packages
226-
$ mkdir lib1 lib2
227-
$ cat >dune-project <<EOF
228-
> (lang dune 2.8)
229-
> (name lib-private-test)
230-
> (package (name public_lib1))
231-
> (package (name public_lib2))
232-
> EOF
233-
$ cat >lib1/dune <<EOF
234-
> (library
235-
> (name lib1)
236-
> (public_name public_lib1))
237-
> EOF
238-
$ touch lib1/lib1.ml
239-
$ cat >lib2/dune <<EOF
240-
> (library
241-
> (name lib2)
242-
> (public_name public_lib2))
243-
> (rule
244-
> (with-stdout-to lib2.ml (echo "let _ = {|%{lib-private:lib1:lib1.ml}|}")))
245-
> EOF
224+
$ make_private_only_packages_project lib-private
246225

247226
The build works in development:
248227
$ dune build @install

test/blackbox-tests/test-cases/libexec.t

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -273,29 +273,9 @@ Testsuite for the %{libexec...} and %{libexec-private...} variable.
273273
In this test, two packages are defined in the same project, but we may not
274274
access the artifacts through %{libexec-private}
275275

276-
$ mkdir lib-private-only-packages
277-
$ cd lib-private-only-packages
278-
$ mkdir lib1 lib2
279-
$ cat >dune-project <<EOF
280-
> (lang dune 2.8)
281-
> (name lib-private-test)
282-
> (package (name public_lib1))
283-
> (package (name public_lib2))
284-
> EOF
285-
$ cat >lib1/dune <<EOF
286-
> (library
287-
> (name lib1)
288-
> (enabled_if (= %{context_name} host))
289-
> (public_name public_lib1))
290-
> EOF
291-
$ touch lib1/lib1.ml
292-
$ cat >lib2/dune <<EOF
293-
> (library
294-
> (name lib2)
295-
> (public_name public_lib2))
296-
> (rule
297-
> (with-stdout-to lib2.ml (echo "let _ = {|%{libexec-private:lib1:lib1.ml}|}")))
298-
> EOF
276+
$ make_private_only_packages_project \
277+
> libexec-private \
278+
> "(enabled_if (= %{context_name} host))"
299279
$ cat >dune <<EOF
300280
> (alias
301281
> (name host)

0 commit comments

Comments
 (0)