Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moyodiallo committed Sep 7, 2023
1 parent 86ba28c commit c339d01
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 1 deletion.
125 changes: 125 additions & 0 deletions tests/test_dune_constraints.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
Create a simple dune project: for testing opam-dune-lint, if dune constraint matches
the dune-project file


$ cat > dune-project << EOF
> (lang dune 2.7)
> (package
> (name test)
> (synopsis "Test package"))
> EOF

$ cat > test.opam << EOF
> # Preserve comments
> opam-version: "2.0"
> synopsis: "Test package"
> build: [
> ["dune" "build"]
> ]
> depends: [
> "ocamlfind" {>= "1.0"}
> "libfoo"
> ]
> EOF

$ cat > dune << EOF
> (executable
> (name main)
> (public_name main)
> (modules main)
> (libraries findlib fmt))
> (test
> (name test)
> (modules test)
> (libraries bos opam-state))
> EOF

$ touch main.ml test.ml
$ dune build

Replace all version numbers with "1.0" to get predictable output.

$ export OPAM_DUNE_LINT_TESTS=y

Check that the missing libraries get added:

$ opam-dune-lint -f
test.opam: changes needed:
"fmt" {>= "1.0"} [from /]
"bos" {with-test & >= "1.0"} [from /]
"opam-state" {with-test & >= "1.0"} [from /]
Note: version numbers are just suggestions based on the currently installed version.
Wrote "./test.opam"
Warning in test: The package has a dune-project file but no explicit dependency on dune was found.

$ cat test.opam | sed 's/= [^&)}]*/= */g'
# Preserve comments
opam-version: "2.0"
synopsis: "Test package"
build: [
["dune" "build"]
]
depends: [
"ocamlfind" {>= *}
"libfoo"
"fmt" {>= *}
"bos" {>= *& with-test}
"opam-state" {>= *& with-test}
]

$ cat > test.opam << EOF
> # Preserve comments
> opam-version: "2.0"
> synopsis: "Test package"
> build: [
> ["dune" "build"]
> ]
> depends: [
> "ocamlfind" {>= "1.0"}
> "libfoo"
> "dune" {> "2.7" & build}
> ]
> EOF
$ dune build

Check that the missing libraries get added:

$ opam-dune-lint -f
test.opam: changes needed:
"fmt" {>= "1.0"} [from /]
"bos" {with-test & >= "1.0"} [from /]
"opam-state" {with-test & >= "1.0"} [from /]
Note: version numbers are just suggestions based on the currently installed version.
Wrote "./test.opam"
Warning in test: The package tagged dune as a build dependency. Due to a bug in dune (https://github.com/ocaml/dune/issues/2147) this should never be the case. Please remove the {build} tag from its filter.

$ cat > test.opam << EOF
> # Preserve comments
> opam-version: "2.0"
> synopsis: "Test package"
> build: [
> ["dune" "build"]
> ]
> depends: [
> "ocamlfind" {>= "1.0"}
> "libfoo"
> "dune" {> "1.0" & build}
> ]
> EOF
$ dune build

Check that the missing libraries get added:

$ opam-dune-lint -f
test.opam: changes needed:
"fmt" {>= "1.0"} [from /]
"bos" {with-test & >= "1.0"} [from /]
"opam-state" {with-test & >= "1.0"} [from /]
Note: version numbers are just suggestions based on the currently installed version.
Wrote "./test.opam"
Warning in test: The package tagged dune as a build dependency. Due to a bug in dune (https://github.com/ocaml/dune/issues/2147) this should never be the case. Please remove the {build} tag from its filter.opam-dune-lint:
internal error, uncaught exception:
(Failure
"Error in test: Your dune-project file indicates that this package requires at least dune 2.7 but your opam file only requires dune >= 1.0. Please check which requirement is the right one, and fix the other.")

[125]
2 changes: 1 addition & 1 deletion tests/test_opam.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Create a simple dune project:
> depends: [
> "ocamlfind" {>= "1.0"}
> "libfoo"
> "dune" {>= "2.7"}
> ]
> EOF

Expand All @@ -43,7 +44,6 @@ Check that the missing libraries get added:

$ opam-dune-lint -f
test.opam: changes needed:
"dune" {>= "1.0"}
"fmt" {>= "1.0"} [from /]
"bos" {with-test & >= "1.0"} [from /]
"opam-state" {with-test & >= "1.0"} [from /]
Expand Down
92 changes: 92 additions & 0 deletions tests/test_opam_update.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
Create a simple dune project: testing if opam-dune-lint update opam files
using the dune-project file, before the linting process.

$ cat > dune-project << EOF
> (lang dune 2.7)
> (generate_opam_files true)
> (package
> (name test)
> (synopsis "Test package")
> (depends cmdliner))
> EOF

$ cat > dune << EOF
> (executable
> (name main)
> (public_name main)
> (modules main)
> (libraries findlib fmt))
> (test
> (name test)
> (modules test)
> (libraries bos opam-state))
> EOF

$ touch main.ml test.ml
$ dune build
$ cat test.opam
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "Test package"
depends: [
"dune" {>= "2.7"}
"cmdliner"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]

Replace all version numbers with "1.0" to get predictable output.

$ export OPAM_DUNE_LINT_TESTS=y

Check that the missing libraries get added:

$ opam-dune-lint -f
test.opam: changes needed:
"fmt" {>= "1.0"} [from /]
"ocamlfind" {>= "1.0"} [from /]
"bos" {with-test & >= "1.0"} [from /]
"opam-state" {with-test & >= "1.0"} [from /]
Note: version numbers are just suggestions based on the currently installed version.
Wrote "dune-project"

$ cat test.opam | sed 's/= [^&)}]*/= */g'
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis: "Test package"
depends: [
"dune" {>= *}
"opam-state" {>= *& with-test}
"bos" {>= *& with-test}
"ocamlfind" {>= *}
"fmt" {>= *}
"cmdliner"
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]

0 comments on commit c339d01

Please sign in to comment.