From 05f6f4a5419bc6b03f199794a400f7cf7a266475 Mon Sep 17 00:00:00 2001 From: Raja Boujbel Date: Fri, 25 Aug 2023 17:17:29 +0200 Subject: [PATCH] reftest: add env rewriting rules test for unix & windows --- tests/reftests/dune.inc | 21 ++++++++++ tests/reftests/env.unix.test | 79 +++++++++++++++++++++++++++++++++++ tests/reftests/env.win32.test | 79 +++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 tests/reftests/env.unix.test diff --git a/tests/reftests/dune.inc b/tests/reftests/dune.inc index b6bc9bce24a..499a554486b 100644 --- a/tests/reftests/dune.inc +++ b/tests/reftests/dune.inc @@ -467,6 +467,27 @@ %{targets} (run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:env.test} %{read-lines:testing-env})))) +(rule + (alias reftest-env.unix) + (enabled_if (= %{os_type} "Unix")) + (action + (diff env.unix.test env.unix.out))) + +(alias + (name reftest) + (enabled_if (= %{os_type} "Unix")) + (deps (alias reftest-env.unix))) + +(rule + (targets env.unix.out) + (deps root-N0REP0) + (enabled_if (= %{os_type} "Unix")) + (package opam) + (action + (with-stdout-to + %{targets} + (run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:env.unix.test} %{read-lines:testing-env})))) + (rule (alias reftest-env.win32) (enabled_if (= %{os_type} "Win32")) diff --git a/tests/reftests/env.unix.test b/tests/reftests/env.unix.test new file mode 100644 index 00000000000..a0ac3772789 --- /dev/null +++ b/tests/reftests/env.unix.test @@ -0,0 +1,79 @@ +N0REP0 +### : setenv & build env rewriting : +### opam switch create rewriting --empty +### +opam-version: "2.0" +setenv: [ A_ENVSET = "/a/given/path" ] +build-env: [ A_ENVBUILD = "/another/given/path" ] +build: [ "sh" "-c" "env | grep A_ENV" ] +### opam install absent-rewrite -vv | sed-cmd sh +The following actions will be performed: +=== install 1 package + - install absent-rewrite 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +Processing 2/3: [absent-rewrite: sh env | grep A_ENV] +sh "-c" "env | grep A_ENV" (CWD=${BASEDIR}/OPAM/rewriting/.opam-switch/build/absent-rewrite.1) +- A_ENVBUILD=/another/given/path +-> compiled absent-rewrite.1 +-> installed absent-rewrite.1 +Done. +### opam env | grep "A_ENV" +A_ENVSET='/a/given/path'; export A_ENVSET; +### opam-cat OPAM/rewriting/.opam-switch/packages/absent-rewrite.1/opam +build: ["sh" "-c" "env | grep A_ENV"] +build-env: A_ENVBUILD = "/another/given/path" +opam-version: "2.0" +setenv: A_ENVSET = "/a/given/path" +### +opam-version: "2.0" +setenv: [ R_ENVSET = "/a/given/path" ] +build-env: [ R_ENVBUILD = "/another/given/path" ] +build: [ "sh" "-c" "env | grep R_ENV" ] +x-allow-env-path-rewrite-on-windows: true +### opam install rewrite -vv | sed-cmd sh +The following actions will be performed: +=== install 1 package + - install rewrite 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +Processing 2/3: [rewrite: sh env | grep R_ENV] +sh "-c" "env | grep R_ENV" (CWD=${BASEDIR}/OPAM/rewriting/.opam-switch/build/rewrite.1) +- R_ENVBUILD=/another/given/path +-> compiled rewrite.1 +-> installed rewrite.1 +Done. +### opam env | grep "R_ENV" +R_ENVSET='/a/given/path'; export R_ENVSET; +### opam-cat OPAM/rewriting/.opam-switch/packages/rewrite.1/opam +build: ["sh" "-c" "env | grep R_ENV"] +build-env: R_ENVBUILD = "/another/given/path" +opam-version: "2.0" +setenv: R_ENVSET = "/a/given/path" +x-allow-env-path-rewrite-on-windows: true +### +opam-version: "2.0" +setenv: [ N_ENVSET = "/a/given/path" ] +build-env: [ N_ENVBUILD = "/another/given/path" ] +build: [ "sh" "-c" "env | grep N_ENV" ] +x-allow-env-path-rewrite-on-windows: false +### opam install no-rewrite -vv | sed-cmd sh +The following actions will be performed: +=== install 1 package + - install no-rewrite 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +Processing 2/3: [no-rewrite: sh env | grep N_ENV] +sh "-c" "env | grep N_ENV" (CWD=${BASEDIR}/OPAM/rewriting/.opam-switch/build/no-rewrite.1) +- N_ENVBUILD=/another/given/path +-> compiled no-rewrite.1 +-> installed no-rewrite.1 +Done. +### opam env | grep "N_ENV" +N_ENVSET='/a/given/path'; export N_ENVSET; +### opam-cat OPAM/rewriting/.opam-switch/packages/no-rewrite.1/opam +build: ["sh" "-c" "env | grep N_ENV"] +build-env: N_ENVBUILD = "/another/given/path" +opam-version: "2.0" +setenv: N_ENVSET = "/a/given/path" +x-allow-env-path-rewrite-on-windows: false diff --git a/tests/reftests/env.win32.test b/tests/reftests/env.win32.test index 93328aa3053..b8978f68790 100644 --- a/tests/reftests/env.win32.test +++ b/tests/reftests/env.win32.test @@ -14,3 +14,82 @@ The following actions will be performed: Done. ### opam env | grep 'Foo|FOO' | "SET " -> "" | "'" -> "" | '; .*' -> "" FOO=bar;foo +### : setenv & build env rewriting : +### opam switch create rewriting --empty +### +opam-version: "2.0" +setenv: [ A_ENVSET = "/a/given/path" ] +build-env: [ A_ENVBUILD = "/another/given/path" ] +build: [ "sh" "-c" "env | grep A_ENV" ] +### opam install absent-rewrite -vv | sed-cmd sh +The following actions will be performed: +=== install 1 package + - install absent-rewrite 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +Processing 2/3: [absent-rewrite: sh env | grep A_ENV] +sh "-c" "env | grep A_ENV" (CWD=${BASEDIR}/OPAM/rewriting/.opam-switch/build/absent-rewrite.1) +- A_ENVBUILD=/another/given/path +-> compiled absent-rewrite.1 +-> installed absent-rewrite.1 +Done. +### opam env | grep "A_ENV" +A_ENVSET='/a/given/path'; export A_ENVSET; +### opam-cat OPAM/rewriting/.opam-switch/packages/absent-rewrite.1/opam +build: ["sh" "-c" "env | grep A_ENV"] +build-env: A_ENVBUILD = "/another/given/path" +opam-version: "2.0" +setenv: A_ENVSET = "/a/given/path" +### +opam-version: "2.0" +setenv: [ R_ENVSET = "/a/given/path" ] +build-env: [ R_ENVBUILD = "/another/given/path" ] +build: [ "sh" "-c" "env | grep R_ENV" ] +x-allow-env-path-rewrite-on-windows: true +### opam install rewrite -vv | sed-cmd sh +The following actions will be performed: +=== install 1 package + - install rewrite 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +Processing 2/3: [rewrite: sh env | grep R_ENV] +sh "-c" "env | grep R_ENV" (CWD=${BASEDIR}/OPAM/rewriting/.opam-switch/build/rewrite.1) +- R_ENVBUILD=\another\given\path +-> compiled rewrite.1 +-> installed rewrite.1 +Done. +### opam env | grep "R_ENV" +R_ENVSET='\a\given\path'; export R_ENVSET; +### opam-cat OPAM/rewriting/.opam-switch/packages/rewrite.1/opam +build: ["sh" "-c" "env | grep R_ENV"] +build-env: R_ENVBUILD = "/another/given/path" +opam-version: "2.0" +setenv: R_ENVSET = "/a/given/path" +x-allow-env-path-rewrite-on-windows: true +### +opam-version: "2.0" +setenv: [ N_ENVSET = "/a/given/path" ] +build-env: [ N_ENVBUILD = "/another/given/path" ] +build: [ "sh" "-c" "env | grep N_ENV" ] +x-allow-env-path-rewrite-on-windows: false +### opam install no-rewrite -vv | sed-cmd sh +The following actions will be performed: +=== install 1 package + - install no-rewrite 1 + +<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> +Processing 2/3: [no-rewrite: sh env | grep N_ENV] +sh "-c" "env | grep N_ENV" (CWD=${BASEDIR}/OPAM/rewriting/.opam-switch/build/no-rewrite.1) +- N_ENVBUILD=/another/given/path +-> compiled no-rewrite.1 +-> installed no-rewrite.1 +Done. +### opam env | grep "N_ENV" +N_ENVSET='/a/given/path'; export N_ENVSET; +### opam-cat OPAM/rewriting/.opam-switch/packages/no-rewrite.1/opam +build: ["sh" "-c" "env | grep N_ENV"] +build-env: N_ENVBUILD = "/another/given/path" +opam-version: "2.0" +setenv: N_ENVSET = "/a/given/path" +x-allow-env-path-rewrite-on-windows: false +