This commit is contained in:
swrup 2025-11-11 02:07:51 +01:00
parent aa2ff7b2f0
commit 2f3113f55d
11742 changed files with 1223940 additions and 0 deletions

View file

@ -0,0 +1,32 @@
When dune subst is called on a file larger than 16MiB, it should not crash.
See #9538.
$ cat > create.ml << EOF
> let () = Unix.truncate "large.dat" 0x1_00_00_00
> EOF
$ touch large.dat
$ ocaml unix.cma create.ml
$ rm create.ml
$ cat > dune-project << EOF
> (lang dune 1.0)
> (name project)
> (package
> (name project))
> EOF
This test uses subst, which needs a git repository:
$ git init
Initialized empty Git repository in $TESTCASE_ROOT/.git/
$ git add dune-project
$ git add large.dat
$ git commit -m create | tail -n 3
2 files changed, 4 insertions(+)
create mode 100644 dune-project
create mode 100644 large.dat
$ dune subst
Warning: Ignoring large file: large.dat
Hint: Dune has been built as a 32-bit binary so the maximum size "dune subst"
can operate on is 16MiB.

View file

@ -0,0 +1,23 @@
$ . ../git-helpers.sh
dune subst should not fail when encountering broken symlinks.
See #9593.
$ cat > dune-project << EOF
> (lang dune 1.0)
> (name proj)
> (package
> (name proj))
> EOF
$ ln -s nonexistent broken
This test requires a git repository, otherwise `dune subst` does nothing.
$ git init -q
$ git add dune-project broken
$ git commit -m create |grep -v root-commit
2 files changed, 5 insertions(+)
create mode 120000 broken
create mode 100644 dune-project
$ dune subst

View file

@ -0,0 +1,62 @@
dune subst should not fail when adding the version field in opam files
$ cat > dune-project << EOF
> (lang dune 3.19)
> (name test)
> (version 0.1)
> (generate_opam_files)
> (package (name test) (allow_empty))
> EOF
$ dune build
$ cat test.opam
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1"
depends: [
"dune" {>= "3.19"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
x-maintenance-intent: ["(latest)"]
$ dune subst
$ cat test.opam
version: "0.1"
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
version: "0.1"
depends: [
"dune" {>= "3.19"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
x-maintenance-intent: ["(latest)"]

View file

@ -0,0 +1,8 @@
(cram
(applies_to 32bit)
(enabled_if
(not %{arch_sixtyfour})))
(cram
(applies_to :whole_subtree)
(deps %{bin:git} ../git-helpers.sh))

View file

@ -0,0 +1,37 @@
$ . ../git-helpers.sh
Read from dune-project package stanza
-------------------------------------
And without an opam file preset.
$ cat > dune-project <<EOF
> (lang dune 2.0)
> (name foo)
> (package (name foo) (authors "John Doe <john@doe.com>"))
> EOF
$ X=%%; cat > file.ml <<EOF
> let name = "${X}NAME${X}"
> let authors = "${X}PKG_AUTHORS${X}"
> let version = "${X}VERSION${X}"
> EOF
$ git init --quiet
$ git add .
$ git commit -am _ --quiet
$ git tag -a 1.0 -m 1.0
$ dune subst
$ cat file.ml
let name = "foo"
let authors = "John Doe <john@doe.com>"
let version = "1.0"
$ cat dune-project
(lang dune 2.0)
(name foo)
(version 1.0)
(package (name foo) (authors "John Doe <john@doe.com>"))
$ rm -rf .git

View file

@ -0,0 +1,18 @@
$ . ../git-helpers.sh
Running `dune subst` in a subfolder of a Git repository should work.
Regression test for https://github.com/ocaml/dune/issues/11045
$ git init --quiet
$ dune init proj subfolder
Entering directory 'subfolder'
Success: initialized project component named subfolder
Leaving directory 'subfolder'
$ unset INSIDE_DUNE
`dune subst` requires at least one commit in the repository.
$ git add -A && git commit --quiet --message "Initial commit"
$ cd subfolder
$ dune subst

View file

@ -0,0 +1,4 @@
Running `dune subst` should succeed in an empty directory.
Regression test for https://github.com/ocaml/dune/issues/11200
$ dune subst

View file

@ -0,0 +1,13 @@
Running `dune subst` should succeed in a directory containing just a `.opam` file.
Regression test for https://github.com/ocaml/dune/issues/11290
$ cat > foo.opam << EOF
> authors: [ "John Doe <john@doe.com>" ]
> EOF
$ dune subst
File ".", line 1, characters 0-0:
Error: There is no dune-project file in the current directory, please add one
with a (name <name>) field in it.
Hint: 'dune subst' must be executed from the root of the project.
[1]

View file

@ -0,0 +1,14 @@
$ . ../git-helpers.sh
subst assumes that dune-project always exists:
$ git init -q
$ touch foo
$ git add -A
$ git commit -m "test" -q
$ dune subst
File ".", line 1, characters 0-0:
Error: There is no dune-project file in the current directory, please add one
with a (name <name>) field in it.
Hint: 'dune subst' must be executed from the root of the project.
[1]

View file

@ -0,0 +1,30 @@
$ . ../../git-helpers.sh
This test checks that `dune subst` adds a `version:` field to opam files.
$ cat > dune-project << EOF
> (lang dune 3.0)
> (name pkg)
> EOF
$ cat > pkg.opam << EOF
> opam-version: "2.0"
> EOF
Git setup is required for dune subst:
$ git init -q
$ git add dune-project pkg.opam
$ git commit -m message|grep -v root-commit
2 files changed, 3 insertions(+)
create mode 100644 dune-project
create mode 100644 pkg.opam
$ git tag -a 1.2.3 -m 'tag message'
$ dune subst
Subst adds a version number based on the git commit:
$ cat pkg.opam
version: "1.2.3"
opam-version: "2.0"

View file

@ -0,0 +1,34 @@
$ . ../../git-helpers.sh
`dune subst` should work for opam files in opam subdirectory.
See #9862.
$ cat > dune-project << EOF
> (lang dune 3.8)
> (name pkg)
> (opam_file_location inside_opam_directory)
> (package (name pkg))
> EOF
$ mkdir opam
$ cat > opam/pkg.opam << EOF
> opam-version: "2.0"
> EOF
Git setup is required for dune subst:
$ git init -q
$ git add dune-project opam/pkg.opam
$ git commit -m message|grep -v root-commit
2 files changed, 5 insertions(+)
create mode 100644 dune-project
create mode 100644 opam/pkg.opam
$ git tag -a 1.2.3 -m 'tag message'
$ dune subst
Subst adds a version number based on the git commit:
$ cat opam/pkg.opam
version: "1.2.3"
opam-version: "2.0"

View file

@ -0,0 +1,36 @@
$ . ../git-helpers.sh
dune subst requires that the project name must exist as a package. However, dune
doesn't verify that this is the case
$ cat > dune-project <<EOF
> (lang dune 2.0)
> (name bar)
> (package (name foo) (authors "John Doe <john@doe.com>"))
> (package (name baz) (authors "John Doe <john@doe.com>"))
> EOF
$ X=%%; cat > file.ml <<EOF
> let name = "${X}NAME${X}"
> let authors = "${X}PKG_AUTHORS${X}"
> let version = "${X}VERSION${X}"
> EOF
$ git init --quiet
$ git add .
$ git commit -am _ --quiet
$ git tag -a 1.0 -m 1.0
$ dune build @all
$ dune subst
File "dune-project", line 2, characters 6-9:
2 | (name bar)
^^^
Error: Package bar doesn't exist.
[1]
$ cat file.ml
let name = "dune"
let authors = "Jane Street Group, LLC <opensource@janestreet.com>"
let version = "3.20.2"

View file

@ -0,0 +1,139 @@
$ . ../git-helpers.sh
Project with opam files
-----------------------
$ cat > dune-project <<EOF
> (lang dune 1.0)
> (name foo)
> EOF
$ X=%%; cat > file.ml <<EOF
> let name = "${X}NAME${X}"
> let authors = "${X}PKG_AUTHORS${X}"
> let version = "${X}VERSION${X}"
> EOF
$ echo 'authors: [ "John Doe <john@doe.com>" ]' > foo.opam
$ git init --quiet
$ git add .
$ git commit -am _ --quiet
$ git tag -a 1.0 -m 1.0
$ dune subst
$ cat file.ml
let name = "foo"
let authors = "John Doe <john@doe.com>"
let version = "1.0"
$ cat dune-project
(lang dune 1.0)
(name foo)
(version 1.0)
$ rm -rf .git
Read from dune-project package stanza
-------------------------------------
And without an opam file preset.
$ rm -f foo.opam
$ cat > dune-project <<EOF
> (lang dune 2.0)
> (name foo)
> (package (name foo) (authors "John Doe <john@doe.com>"))
> EOF
$ X=%%; cat > file.ml <<EOF
> let name = "${X}NAME${X}"
> let authors = "${X}PKG_AUTHORS${X}"
> let version = "${X}VERSION${X}"
> EOF
$ git init --quiet
$ git add .
$ git commit -am _ --quiet
$ git tag -a 1.0 -m 1.0
$ dune subst
$ cat file.ml
let name = "foo"
let authors = "John Doe <john@doe.com>"
let version = "1.0"
$ cat dune-project
(lang dune 2.0)
(name foo)
(version 1.0)
(package (name foo) (authors "John Doe <john@doe.com>"))
$ rm -rf .git
Test subst and files with unicode (#3879)
-----------------------------------------
$ rm -f foo.opam
$ cat > dune-project <<EOF
> (lang dune 2.0)
> (name foo)
> (package (name foo) (authors "John Doe <john@doe.com>"))
> EOF
$ X=%%; cat > α-term.ml <<EOF
> let name = "${X}NAME${X}"
> let authors = "${X}PKG_AUTHORS${X}"
> let version = "${X}VERSION${X}"
> EOF
$ git init --quiet
$ git add .
$ git commit -am _ --quiet
$ git tag -a 1.0 -m 1.0
$ dune subst
$ cat α-term.ml
let name = "foo"
let authors = "John Doe <john@doe.com>"
let version = "1.0"
$ cat dune-project
(lang dune 2.0)
(name foo)
(version 1.0)
(package (name foo) (authors "John Doe <john@doe.com>"))
$ cat > dune-project <<EOF
> (lang dune 3.0)
> (name foo)
> (version 1.0)
> (package (name foo) (authors "John Doe <john@doe.com>"))
> (subst disabled)
> EOF
$ dune subst
File "dune-project", line 5, characters 7-15:
5 | (subst disabled)
^^^^^^^^
Error: 'dune subst' has been disabled in this project. Any use of it is
forbidden.
Hint: If you wish to re-enable it, change to (subst enabled) in the
dune-project file.
[1]
$ cat > dune-project <<EOF
> (lang dune 3.0)
> (name foo)
> (version 1.0)
> (package (name foo) (authors "John Doe <john@doe.com>"))
> (subst enabled)
> EOF
$ dune subst
$ rm -rf .git

View file

@ -0,0 +1,38 @@
$ . ../git-helpers.sh
Test subst and files with unicode (#3879)
-----------------------------------------
$ rm -f foo.opam
$ cat > dune-project <<EOF
> (lang dune 2.0)
> (name foo)
> (package (name foo) (authors "John Doe <john@doe.com>"))
> EOF
$ X=%%; cat > α-term.ml <<EOF
> let name = "${X}NAME${X}"
> let authors = "${X}PKG_AUTHORS${X}"
> let version = "${X}VERSION${X}"
> EOF
$ git init --quiet
$ git add .
$ git commit -am _ --quiet
$ git tag -a 1.0 -m 1.0
$ dune subst
$ cat α-term.ml
let name = "foo"
let authors = "John Doe <john@doe.com>"
let version = "1.0"
$ cat dune-project
(lang dune 2.0)
(name foo)
(version 1.0)
(package (name foo) (authors "John Doe <john@doe.com>"))
$ rm -rf .git

View file

@ -0,0 +1,34 @@
$ . ../git-helpers.sh
Project with opam files
-----------------------
$ cat > dune-project <<EOF
> (lang dune 1.0)
> (name foo)
> EOF
$ X=%%; cat > file.ml <<EOF
> let name = "${X}NAME${X}"
> let authors = "${X}PKG_AUTHORS${X}"
> let version = "${X}VERSION${X}"
> EOF
$ echo 'authors: [ "John Doe <john@doe.com>" ]' > foo.opam
$ git init --quiet
$ git add .
$ git commit -am _ --quiet
$ git tag -a 1.0 -m 1.0
$ dune subst
$ cat file.ml
let name = "foo"
let authors = "John Doe <john@doe.com>"
let version = "1.0"
$ cat dune-project
(lang dune 1.0)
(name foo)
(version 1.0)

View file

@ -0,0 +1,29 @@
Demonstrate $ dune subst without a git repository
$ cat > dune-project << EOF
> (lang dune 3.17)
> (name test)
> EOF
$ echo "dune" > README.md
$ dune subst
$ cat README.md
test
dune subst should take the project version from the dune-project file when
there is no vcs
$ cat > dune-project << EOF
> (lang dune 3.19)
> (name test)
> (version 0.1)
> EOF
$ echo "3.20.2" > README.md
$ dune subst
$ cat README.md
0.1