Skip to content

Commit

Permalink
fix: use files instead of stdout (tmp)
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne Marais <[email protected]>
  • Loading branch information
maiste committed Jun 26, 2024
1 parent c888d2c commit e55994a
Show file tree
Hide file tree
Showing 28 changed files with 270 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Test that section pforms are substituted with absolute paths.
$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (install (progn
> (run echo --prefix %{prefix})
> (run echo --prefix=%{prefix})))
> (run sh -c "echo --prefix %{prefix} > %{etc}/cmd-output")
> (run sh -c "echo --prefix=%{prefix} >> %{etc}/cmd-output")))
> EOF

$ cat >dune-project <<EOF
Expand All @@ -21,6 +21,8 @@ Test that section pforms are substituted with absolute paths.

Note that currently dune incorrectly substitutes relative paths for pforms that
appear in string interpolations.
$ dune build 2>&1 | strip_sandbox

$ dune build ; \
> show_pkg_output test | strip_sandbox
--prefix $SANDBOX/_private/default/.pkg/test/target
$SANDBOX/_private/default/.pkg/test/target
9 changes: 6 additions & 3 deletions test/blackbox-tests/test-cases/pkg/build-single-package.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Requesting to build a single package should not build unrelated things:

$ pkg() {
> make_lockpkg $1 <<EOF
> (build (run echo building $1))
> (build (run sh -c "echo building $1 > cat-output-$1"))
> (install (run cp "cat-output-$1" %{etc}))
> (version dev)
> EOF
> }
Expand All @@ -22,10 +23,12 @@ These two packages are independent:

We should only see the result of building "foo"

$ build_pkg foo
$ build_pkg foo ; \
> show_pkg_output foo "cat-output-foo"
building foo

We should only see the result of building "bar"

$ build_pkg bar
$ build_pkg bar ; \
> show_pkg_output bar "cat-output-bar"
building bar
6 changes: 4 additions & 2 deletions test/blackbox-tests/test-cases/pkg/command-from-user-path.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Create a directory containing a shell script and add the directory to PATH.
$ mkdir bin
$ cat > bin/hello <<EOF
> #!/bin/sh
> echo "Hello, World!"
> echo "Hello, World!" > cmd-output
> EOF
$ chmod a+x bin/hello
$ export PATH=$PATH:$PWD/bin
Expand All @@ -16,8 +16,10 @@ Create a lockdir with a lockfile that runs the shell script in a build command.
$ cat >dune.lock/test.pkg <<'EOF'
> (version 0.0.1)
> (build (run hello))
> (install (run cp "cmd-output" %{etc}))
> EOF

The build command is run from an environment including the custom PATH variable.
$ build_pkg test
$ build_pkg test ; \
> show_pkg_output test
Hello, World!
9 changes: 6 additions & 3 deletions test/blackbox-tests/test-cases/pkg/default-git-branch.t
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ This bug is reported in #10063
$ make_lockpkg foo <<EOF
> (source (fetch (url "git+file://$PWD/$src")))
> (version 0.0.1)
> (build (run cat file))
> (build (run sh -c "cat file > cmd-output"))
> (install (run cp "cmd-output" %{etc}))
> EOF

Build the package

$ build_pkg foo
$ build_pkg foo ; \
> show_pkg_output foo
branch 2

Change the default branch
Expand All @@ -41,5 +43,6 @@ Change the default branch

And now rebuild

$ build_pkg foo
$ build_pkg foo ; \
> show_pkg_output foo
branch 1
15 changes: 12 additions & 3 deletions test/blackbox-tests/test-cases/pkg/different-dune-in-path.t
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Make lockfiles for the packages.
> (build
> (run dune build -p %{pkg-self:name} @install))
>
> (install
> (run sh -c "test -f cmd-output && cp cmd-output %{etc} || true"))
>
> (source
> (fetch
> (url $PWD/foo.tar.gz)))
Expand All @@ -55,6 +58,9 @@ Make lockfiles for the packages.
> ; Exercise that the dune exe can be located when it's launched by a subprocess.
> (run sh -c "dune build -p %{pkg-self:name} @install"))
>
> (install
> (run sh -c "test -f cmd-output && cp cmd-output %{etc} || true"))
>
> (source
> (fetch
> (url $PWD/bar.tar.gz)))
Expand All @@ -69,13 +75,16 @@ Make a fake dune exe:
$ mkdir bin
$ cat > bin/dune <<EOF
> #!/bin/sh
> echo "Fake dune! (args: \$@)"
> echo "Fake dune! (args: \$@)" > cmd-output
> EOF
$ chmod a+x bin/dune

$ dune clean

Try building in an environment where `dune` refers to the fake dune.
$ DUNE=$(which dune) # otherwise we would start by running the wrong dune
$ PATH=$PWD/bin:$PATH $DUNE build
Fake dune! (args: build -p bar @install)
$ PATH=$PWD/bin:$PATH $DUNE build ; \
> show_pkg_output foo ; \
> show_pkg_output bar
Fake dune! (args: build -p foo @install)
Fake dune! (args: build -p bar @install)
6 changes: 4 additions & 2 deletions test/blackbox-tests/test-cases/pkg/git-source.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ Test fetching from git
$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (source (fetch (url "git+file://$MYGITREPO")))
> (build (run cat foo))
> (build (run sh -c "cat foo > cmd-output"))
> (install (run cp cmd-output %{etc}))
> EOF

$ build_pkg test
$ build_pkg test ; \
> show_pkg_output test
hello world
11 changes: 11 additions & 0 deletions test/blackbox-tests/test-cases/pkg/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ show_pkg_targets() {
find $pkg_root/$1/target | sort | sed "s#$pkg_root/$1/target##"
}

show_pkg_output() {
if [ "$#" -eq "1" ]
then
output="cmd-output"
else
output="$2"
fi
cat "_build/_private/default/.pkg/$1/target/etc/$output"
}


show_pkg_cookie() {
$dune internal dump $pkg_root/$1/target/cookie
}
Expand Down
6 changes: 4 additions & 2 deletions test/blackbox-tests/test-cases/pkg/installed-binary.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ Test that installed binaries are visible in dependent packages
$ cat >dune.lock/test.pkg <<EOF
> (version 0.0.1)
> (build
> (system "\| echo "#!/bin/sh\necho from test package" > foo;
> (system "\| echo "#!/bin/sh\necho \"from test package\" > cmd-output" > foo;
> "\| echo "echo from test package" >> foo;
> "\| chmod +x foo;
> "\| touch libxxx lib_rootxxx;
> "\| cat >test.install <<EOF
Expand All @@ -25,9 +26,10 @@ Test that installed binaries are visible in dependent packages
> (progn
> (run foo)
> (run mkdir -p %{prefix})))
> (install (run cp "cmd-output" %{etc}))
> EOF
$ build_pkg usetest
$ build_pkg usetest ; show_pkg_output usetest
from test package
$ show_pkg_targets test
Expand Down
21 changes: 14 additions & 7 deletions test/blackbox-tests/test-cases/pkg/lock-directory-selection.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ Test that dune can dynamically select a lockdir with a cond statement
$ mkrepo

$ mkpkg arm64-only <<EOF
> install: [ "echo" "arm64-only" ]
> build: [ "sh" "-c" " echo arm64-only > cmd-output-arm64"]
> install: [ "cp" "cmd-output-arm64" etc ]
> EOF

$ mkpkg linux-only <<EOF
> install: [ "echo" "linux-only" ]
> build: [ "sh" "-c" " echo linux-only > cmd-output-linux"]
> install: [ "cp" "cmd-output-linux" etc ]
> EOF

$ mkpkg macos-only <<EOF
> install: [ "echo" "macos-only" ]
> build: [ "sh" "-c" " echo macos-only > cmd-output-macos"]
> install: [ "cp" "cmd-output-macos" etc ]
> EOF

$ cat >dune-workspace <<EOF
Expand Down Expand Up @@ -76,12 +79,14 @@ are only dependent on on certain systems.

Build macos package on macos:
$ dune clean
$ DUNE_CONFIG__OS=macos DUNE_CONFIG__ARCH=arm64 dune build _build/_private/default/.pkg/macos-only/target/
$ DUNE_CONFIG__OS=macos DUNE_CONFIG__ARCH=arm64 dune build _build/_private/default/.pkg/macos-only/target/ && \
> show_pkg_output macos-only "cmd-output-macos"
macos-only

Build macos package on macos:
$ dune clean
$ DUNE_CONFIG__OS=macos DUNE_CONFIG__ARCH=amd64 dune build _build/_private/default/.pkg/macos-only/target/
$ DUNE_CONFIG__OS=macos DUNE_CONFIG__ARCH=amd64 dune build _build/_private/default/.pkg/macos-only/target/ && \
> show_pkg_output macos-only "cmd-output-macos"
macos-only

Build linux package on macos (will fail):
Expand All @@ -98,7 +103,8 @@ Build macos package on linux (will fail):

Build linux package on linux:
$ dune clean
$ DUNE_CONFIG__OS=linux DUNE_CONFIG__ARCH=amd64 dune build _build/_private/default/.pkg/linux-only/target/
$ DUNE_CONFIG__OS=linux DUNE_CONFIG__ARCH=amd64 dune build _build/_private/default/.pkg/linux-only/target/ && \
> show_pkg_output linux-only "cmd-output-linux"
linux-only

Try setting the os to one which doesn't have a corresponding lockdir:
Expand Down Expand Up @@ -133,5 +139,6 @@ Test that cond statements can have a default value:
Solution for dune.lock:
- linux-only.0.0.1
$ dune clean
$ dune build _build/_private/default/.pkg/linux-only/target/
$ dune build _build/_private/default/.pkg/linux-only/target/ && \
> show_pkg_output linux-only "cmd-output-linux"
linux-only
5 changes: 3 additions & 2 deletions test/blackbox-tests/test-cases/pkg/make.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ Build a package with make
$ cat >foo/Makefile <<EOF
> .DEFAULT: foo
> .PHONY: foo
> foo: ; @echo running makefile
> foo: ; @echo running makefile > cmd-output
> EOF
$ make_lockdir
$ cat >dune.lock/foo.pkg <<EOF
> (version 0.0.1)
> (build (run %{make}))
> (install (run cp "cmd-output" %{etc}))
> (source (copy $PWD/foo))
> EOF
$ build_pkg foo
$ build_pkg foo && show_pkg_output foo
running makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ In this test we test the translation of an opam package with only an install ste

Make a package with only an install step
$ mkpkg install-no-build <<EOF
> install: ["echo" "just installing"]
> install: [
> [ "sh" "-c" "echo just installing > cmd-output" ]
> [ "cp" "cmd-output" etc ]
> ]
> EOF

$ mkdir -p $mock_packages/install-no-build/install-no-build.0.0.1/
Expand All @@ -19,9 +22,11 @@ The lockfile should only contain an install step.
(version 0.0.1)

(install
(run echo "just installing"))
(progn
(run sh -c "echo just installing > cmd-output")
(run cp cmd-output %{etc})))

Building should only do the install step.

$ build_pkg install-no-build
$ build_pkg install-no-build && show_pkg_output install-no-build
just installing
10 changes: 7 additions & 3 deletions test/blackbox-tests/test-cases/pkg/opam-package-subst-patch.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Make a package with a substs and patches field field
$ mkpkg with-substs-and-patches <<EOF
> substs: ["foo.patch"]
> patches: ["foo.patch"]
> build: [ "sh" "-c" "[ -e foo.ml ] && cat foo.ml" ]
> build: [ "sh" "-c" "[ -e foo.ml ] && cat foo.ml > cmd-output" ]
> install: [ "cp" "cmd-output" etc ]
> EOF

$ opam_repo=$mock_packages/with-substs-and-patches/with-substs-and-patches.0.0.1
Expand All @@ -26,11 +27,14 @@ The lockfile should contain the substitute and patch actions.
$ cat dune.lock/with-substs-and-patches.pkg
(version 0.0.1)

(install
(run cp cmd-output %{etc}))

(build
(progn
(substitute foo.patch.in foo.patch)
(patch foo.patch)
(run sh -c "[ -e foo.ml ] && cat foo.ml")))
(run sh -c "[ -e foo.ml ] && cat foo.ml > cmd-output")))
(source (copy $TESTCASE_ROOT/source))

$ mkdir source
Expand All @@ -51,5 +55,5 @@ The lockfile should contain the substitute and patch actions.

The file foo.ml should have been built:

$ build_pkg with-substs-and-patches
$ build_pkg with-substs-and-patches && show_pkg_output with-substs-and-patches
This is right
19 changes: 14 additions & 5 deletions test/blackbox-tests/test-cases/pkg/opam-package-with-build-env.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ file.
Make a package with a build-env field
$ mkpkg with-build-env <<'EOF'
> build-env: [ [ MY_ENV_VAR = "Hello from env var!" ] ]
> build: ["sh" "-c" "echo $MY_ENV_VAR"]
> install: ["sh" "-c" "echo $MY_ENV_VAR"]
> build: ["sh" "-c" "echo $MY_ENV_VAR > cmd-output-build"]
> install: [
> ["sh" "-c" "echo $MY_ENV_VAR > cmd-output-install"]
> ["cp" "cmd-output-build" etc]
> ["cp" "cmd-output-install" etc]
> ]
> EOF

$ solve with-build-env
Expand All @@ -22,15 +26,20 @@ The lockfile should contain a setenv action.
(install
(withenv
((= MY_ENV_VAR "Hello from env var!"))
(run sh -c "echo $MY_ENV_VAR")))
(progn
(run sh -c "echo $MY_ENV_VAR > cmd-output-install")
(run cp cmd-output-build %{etc})
(run cp cmd-output-install %{etc}))))

(build
(withenv
((= MY_ENV_VAR "Hello from env var!"))
(run sh -c "echo $MY_ENV_VAR")))
(run sh -c "echo $MY_ENV_VAR > cmd-output-build")))

This should print the value given in the build-env field.

$ MY_ENV_VAR="invisible" build_pkg with-build-env
$ MY_ENV_VAR="invisible" build_pkg with-build-env && \
> show_pkg_output with-build-env "cmd-output-build" && \
> show_pkg_output with-build-env "cmd-output-install"
Hello from env var!
Hello from env var!
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ lock file.
Make a package with a patch behind a filter
$ mkpkg with-patch-filter <<EOF
> patches: ["foo.patch" {switch = "foobar"}]
> build: ["cat" "foo.ml"]
> build: ["sh" "-c" "cat foo.ml > cmd-output"]
> install: ["cp" "cmd-output" etc]
> EOF

$ mkdir -p $mock_packages/with-patch-filter/with-patch-filter.0.0.1/files
Expand All @@ -33,18 +34,21 @@ The lockfile should contain the patch action with the appropriate filter.
$ cat dune.lock/with-patch-filter.pkg
(version 0.0.1)

(install
(run cp cmd-output %{etc}))

(build
(progn
(when
(= %{switch} foobar)
(patch foo.patch))
(run cat foo.ml)))
(run sh -c "cat foo.ml > cmd-output")))
(source (copy $TESTCASE_ROOT/source))

$ mkdir source
$ cat > source/foo.ml <<EOF
> This is right; the patch should never be applied.
> EOF

$ build_pkg with-patch-filter
$ build_pkg with-patch-filter && show_pkg_output with-patch-filter
This is right; the patch should never be applied.
Loading

0 comments on commit e55994a

Please sign in to comment.