From 5cbf391a046fdcdd9626c3f9075c79edebf67d0d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sat, 30 Jun 2018 17:15:06 +0700 Subject: [PATCH] Add a test suite for workspaces Signed-off-by: Rudi Grinberg --- test/blackbox-tests/dune.inc | 14 ++++- .../test-cases/workspaces/custom-profile/dune | 3 + .../workspaces/custom-profile/dune-workspace | 3 + .../custom-workspace/dune-workspace.dev | 3 + .../workspaces/dune-no-version/dune-workspace | 1 + .../jbuilder-default-name/jbuild-workspace | 1 + .../test-cases/workspaces/opam/dune-workspace | 8 +++ .../test-cases/workspaces/run.t | 63 +++++++++++++++++++ .../test-cases/workspaces/targets-native/dune | 2 + .../workspaces/targets-native/dune-workspace | 3 + .../workspaces/targets-native/foo.ml | 1 + 11 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 test/blackbox-tests/test-cases/workspaces/custom-profile/dune create mode 100644 test/blackbox-tests/test-cases/workspaces/custom-profile/dune-workspace create mode 100644 test/blackbox-tests/test-cases/workspaces/custom-workspace/dune-workspace.dev create mode 100644 test/blackbox-tests/test-cases/workspaces/dune-no-version/dune-workspace create mode 100644 test/blackbox-tests/test-cases/workspaces/jbuilder-default-name/jbuild-workspace create mode 100644 test/blackbox-tests/test-cases/workspaces/opam/dune-workspace create mode 100644 test/blackbox-tests/test-cases/workspaces/run.t create mode 100644 test/blackbox-tests/test-cases/workspaces/targets-native/dune create mode 100644 test/blackbox-tests/test-cases/workspaces/targets-native/dune-workspace create mode 100644 test/blackbox-tests/test-cases/workspaces/targets-native/foo.ml diff --git a/test/blackbox-tests/dune.inc b/test/blackbox-tests/dune.inc index 3ab73034..28390f9e 100644 --- a/test/blackbox-tests/dune.inc +++ b/test/blackbox-tests/dune.inc @@ -579,6 +579,14 @@ test-cases/windows-diff (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) +(alias + (name workspaces) + (deps (package dune) (source_tree test-cases/workspaces)) + (action + (chdir + test-cases/workspaces + (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected))))) + (alias (name runtest) (deps @@ -648,7 +656,8 @@ (alias syntax-versioning) (alias use-meta) (alias utop) - (alias windows-diff))) + (alias windows-diff) + (alias workspaces))) (alias (name runtest-no-deps) @@ -710,7 +719,8 @@ (alias select) (alias syntax-versioning) (alias use-meta) - (alias windows-diff))) + (alias windows-diff) + (alias workspaces))) (alias (name runtest-disabled) (deps (alias reason))) diff --git a/test/blackbox-tests/test-cases/workspaces/custom-profile/dune b/test/blackbox-tests/test-cases/workspaces/custom-profile/dune new file mode 100644 index 00000000..1517a8a5 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/custom-profile/dune @@ -0,0 +1,3 @@ +(alias + (name runtest) + (action (echo "build profile: %{build_profile}"))) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/custom-profile/dune-workspace b/test/blackbox-tests/test-cases/workspaces/custom-profile/dune-workspace new file mode 100644 index 00000000..84bdee13 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/custom-profile/dune-workspace @@ -0,0 +1,3 @@ +(lang dune 1.0) + +(context (default (profile foobar))) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/custom-workspace/dune-workspace.dev b/test/blackbox-tests/test-cases/workspaces/custom-workspace/dune-workspace.dev new file mode 100644 index 00000000..a27d9ccd --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/custom-workspace/dune-workspace.dev @@ -0,0 +1,3 @@ +(lang dune 1.0) + +(context (does-not-exist)) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/dune-no-version/dune-workspace b/test/blackbox-tests/test-cases/workspaces/dune-no-version/dune-workspace new file mode 100644 index 00000000..b4454ea8 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/dune-no-version/dune-workspace @@ -0,0 +1 @@ +(context (default)) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/jbuilder-default-name/jbuild-workspace b/test/blackbox-tests/test-cases/workspaces/jbuilder-default-name/jbuild-workspace new file mode 100644 index 00000000..4554f70b --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/jbuilder-default-name/jbuild-workspace @@ -0,0 +1 @@ +(context (does-not-exist)) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/opam/dune-workspace b/test/blackbox-tests/test-cases/workspaces/opam/dune-workspace new file mode 100644 index 00000000..a0ae01c8 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/opam/dune-workspace @@ -0,0 +1,8 @@ +(lang dune 1.0) + +(context + (opam + (switch foo-switch) + (name foo-name) + (profile foo-profile) + (merlin false))) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/run.t b/test/blackbox-tests/test-cases/workspaces/run.t new file mode 100644 index 00000000..f4747357 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/run.t @@ -0,0 +1,63 @@ +jbuild still discovers workspaces as usual + + $ jbuilder build --root jbuilder-default-name + File "jbuild-workspace", line 1, characters 10-24: + Error: Unknown constructor does-not-exist + [1] + +and dune ignores this file: + + $ dune build --root jbuilder-default-name + Entering directory 'jbuilder-default-name' + +dune uses a versioned file. If the version is missing, then we get an error. + + $ dune build --root dune-no-version + File "dune-workspace", line 1, characters 0-19: + Error: Invalid first line, expected: (lang ) + [1] + +analogously, jbuilder will ignore it + + $ jbuilder build --root dune-no-version + Entering directory 'dune-no-version' + +specifying the workspace file is possible: + + $ dune build --root custom-workspace --workspace custom-workspace/dune-workspace.dev + Error: exception Sys_error("custom-workspace/dune-workspace.dev: No such file or directory") + Backtrace: + Raised by primitive operation at file "pervasives.ml", line 389, characters 28-54 + Called from file "src/stdune/io.ml", line 15, characters 15-35 + Called from file "src/main.ml", line 61, characters 8-36 + Called from file "src/main.ml", line 270, characters 12-56 + Called from file "bin/main.ml", line 756, characters 7-29 + Called from file "vendor/cmdliner/src/cmdliner_term.ml", line 27, characters 19-24 + Called from file "vendor/cmdliner/src/cmdliner.ml", line 106, characters 32-39 + Called from file "vendor/cmdliner/src/cmdliner.ml", line 136, characters 18-36 + Called from file "vendor/cmdliner/src/cmdliner.ml", line 251, characters 22-48 + Called from file "bin/main.ml", line 1562, characters 10-51 + [1] + +Workspaces let you set custom profiles + + $ dune runtest --root custom-profile + Info: creating file dune-project with this contents: (lang dune 1.0) + Entering directory 'custom-profile' + build profile: foobar + +A workspace context can ve defined using an opam switch. Note that this test is +a bit limited since we can't mock opam switches. + + $ dune build --root opam --display quiet 2>&1 | grep -v "opam (internal)\|To make opam select\|OPAMSWITCH" + Entering directory 'opam' + +Workspaces also allow you to set "target" for cross compilation. This feature is +a bit hard to test since it requires mocking more than one context. But we can +see how we can set a "native" target. Which is the default. + + $ dune exec ./foo.exe --root targets-native + Info: creating file dune-project with this contents: (lang dune 1.0) + Entering directory 'targets-native' + Entering directory 'targets-native' + message from targets-native test diff --git a/test/blackbox-tests/test-cases/workspaces/targets-native/dune b/test/blackbox-tests/test-cases/workspaces/targets-native/dune new file mode 100644 index 00000000..285ef0c0 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/targets-native/dune @@ -0,0 +1,2 @@ + +(executable (name foo)) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/targets-native/dune-workspace b/test/blackbox-tests/test-cases/workspaces/targets-native/dune-workspace new file mode 100644 index 00000000..1cab60b7 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/targets-native/dune-workspace @@ -0,0 +1,3 @@ +(lang dune 1.0) + +(context (default (targets native))) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/workspaces/targets-native/foo.ml b/test/blackbox-tests/test-cases/workspaces/targets-native/foo.ml new file mode 100644 index 00000000..8ade8dc3 --- /dev/null +++ b/test/blackbox-tests/test-cases/workspaces/targets-native/foo.ml @@ -0,0 +1 @@ +print_endline "message from targets-native test";;