Skip to content

Commit

Permalink
reftest: add a test for git packages with submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Aug 16, 2024
1 parent 6fc00fd commit 1d62c4c
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/scripts/main/preamble.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ git config --global user.email "[email protected]"
git config --global user.name "Github Actions CI"
git config --global gc.autoDetach false
git config --global init.defaultBranch thisShouldNotHappen
git config --global protocol.file.allow always

if [ -d ~/opam-repository ]; then
OPAM_REPO_CACHE=file://$HOME/opam-repository
Expand Down
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ users)
* Add a test filtering mechanism [#6105 @Keryan-dev]
* Add a package fetching test [#6146 @rjbou]
* Add a test showing the behaviour of `opam switch list-available` [#6098 @kit-ty-kate]
* Add a test for git packages with submodules [#6132 @kit-ty-kate]

### Engine
* Add a test filtering mechanism [#6105 @Keryan-dev]
Expand All @@ -180,6 +181,7 @@ users)
* Update action cache to v4 [#6081 @rjbou]
* Update action checkout to v4 [#6081 @rjbou]
* Update action upload-artifact to v4 [#6081 @rjbou]
* Allow local git submodules (ignore CVE-2022-39253) [#6132 @kit-ty-kate]

## Doc
* Remove the ppa from the installation instructions on Ubuntu [#5988 @kit-ty-kate - fix #5987]
Expand Down
21 changes: 21 additions & 0 deletions tests/reftests/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,27 @@
%{targets}
(run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:filter-operators.test} %{read-lines:testing-env}))))

(rule
(alias reftest-git)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(action
(diff git.test git.out)))

(alias
(name reftest)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(deps (alias reftest-git)))

(rule
(targets git.out)
(deps root-N0REP0)
(enabled_if (and (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
(package opam)
(action
(with-stdout-to
%{targets}
(run ./run.exe %{exe:../../src/client/opamMain.exe.exe} %{dep:git.test} %{read-lines:testing-env}))))

(rule
(alias reftest-init-ocaml-eval-variables.unix)
(enabled_if (and (= %{os_type} "Unix") (or (<> %{env:TESTALL=1} 0) (= %{env:TESTN0REP0=0} 1))))
Expand Down
71 changes: 71 additions & 0 deletions tests/reftests/git.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
N0REP0
### : Check the bevahiour when presented with a broken submodule
### mkdir submodule
### git -C ./submodule init -q
### git -C ./submodule config core.autocrlf false
### touch ./submodule/some-file
### git -C ./submodule add ./some-file
### git -C ./submodule commit -qm "first commit"
### mkdir use-submodule
### git -C ./use-submodule init -q
### git -C ./use-submodule config core.autocrlf false
### git -C ./use-submodule submodule add ../submodule ./vendor
Cloning into '${BASEDIR}/use-submodule/vendor'...
done.
### git -C ./use-submodule commit -qm "first commit"
### <create-submodule-pkg.sh>
mkdir -p REPO/packages/submodule/submodule.1
ESCAPED_BASEDIR=$(printf '%s' "$BASEDIR" | sed 's/\\/\\\\/g')
cat > REPO/packages/submodule/submodule.1/opam << EOF
opam-version: "2.0"
build: ["ls" "vendor/some-file"]
url {
src: "git+file://${ESCAPED_BASEDIR}/use-submodule"
}
EOF
### sh ./create-submodule-pkg.sh
### opam update

<><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><><><>
[default] synchronised from file://${BASEDIR}/REPO
Now run 'opam upgrade' to apply any package updates.
### opam switch create submodule --empty
### opam install submodule
The following actions will be performed:
=== install 1 package
- install submodule 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> retrieved submodule.1 (git+file://${BASEDIR}/use-submodule)
-> installed submodule.1
Done.
### rm -r ./submodule
### opam remove submodule
The following actions will be performed:
=== remove 1 package
- remove submodule 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> removed submodule.1
Done.
### opam install submodule
The following actions will be performed:
=== install 1 package
- install submodule 1

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[WARNING] Git submodule update failed in ${BASEDIR}/OPAM/submodule/.opam-switch/sources/submodule.1
-> retrieved submodule.1 (git+file://${BASEDIR}/use-submodule)
[ERROR] The compilation of submodule.1 failed at "ls vendor/some-file".

##% output ###
# ls: cannot access 'vendor/some-file': No such file or directory



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
+- The following actions failed
| - build submodule 1
+-
- No changes have been performed
# Return code 31 #

0 comments on commit 1d62c4c

Please sign in to comment.