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,3 @@
(cram
(deps
(package utop)))

View file

@ -0,0 +1,15 @@
This test makes sure that the utop subcommand does not load optional libraries.
$ mkdir testutop
$ cat <<EOF > testutop/dune
> (library
> (name testutop)
> (optional)
> (libraries does_not_exist))
> EOF
$ echo 'let run () = print_endline "this will never run"' > testutop/testutop.ml
$ echo "(lang dune 2.0)" > dune-project
$ echo 'let () = print_endline "No Error"' > init_test.ml
$ dune utop testutop -- init_test.ml
No Error

View file

@ -0,0 +1,25 @@
dune utop should read libraries in (subdir ..)
$ cat >dune-project <<EOF
> (lang dune 3.6)
> EOF
$ cat >dune <<EOF
> (data_only_dirs foo)
> (subdir foo
> (library
> (modules foolib)
> (name foolib)))
> EOF
$ mkdir foo
$ cat >foo/foolib.ml <<EOF
> let hw () = print_endline "foolib"
> EOF
$ cat >foo.ml <<EOF
> Foolib.hw ()
> EOF
$ dune utop . -- foo.ml
foolib

View file

@ -0,0 +1,3 @@
(library
(name forutop_impl_2)
(implements forutop))

View file

@ -0,0 +1 @@
let run () = print_endline "shouldn't be selected"

View file

@ -0,0 +1,3 @@
(library
(name forutop_impl)
(implements forutop))

View file

@ -0,0 +1 @@
let run () = print_endline "selected by default impl"

View file

@ -0,0 +1,4 @@
(library
(name forutop)
(virtual_modules forutop)
(default_implementation forutop_impl))

View file

@ -0,0 +1,2 @@
$ dune utop . init_forutop.ml
selected by default impl

View file

@ -0,0 +1 @@
(library (name mylib))

View file

@ -0,0 +1,7 @@
By default, dune utop tries to make a toplevel for the current directory:
$ echo 'Stdlib.exit 0;;' | dune utop . -- -init "" | grep -v 'version'
Enter "#help;;" for help.
Init file not found: "".
#

View file

@ -0,0 +1 @@
(library (name private_lib_a))

View file

@ -0,0 +1,14 @@
Utop will load libs recursively:
$ echo 'Stdlib.exit 0;;' | dune utop . -- -init "" | grep -v 'version'
Enter "#help;;" for help.
Init file not found: "".
#
The message where the library path does not exist is different:
$ dune utop does-not-exist . -- -init ""
Error: cannot find directory: does-not-exist
[1]

View file

@ -0,0 +1,3 @@
(executable
(name foo)
(libraries bar))

View file

@ -0,0 +1 @@
let run () = print_endline "loaded external library successfully"

View file

@ -0,0 +1,2 @@
(library
(name bar))

View file

@ -0,0 +1,3 @@
Running dune utop in a project with only executables loads external libraries
$ dune utop bin -- load_executable_libraries.ml
loaded external library successfully

View file

@ -0,0 +1,4 @@
(library
(name fooppx)
(kind ppx_rewriter)
(libraries ppxlib))

View file

@ -0,0 +1,10 @@
open Ppxlib
let rules =
let extension =
Extension.declare "foo" Expression Ast_pattern.__ (fun ~loc ~path:_ _ ->
Ast_builder.Default.estring ~loc "PPX extension")
in
[ Context_free.Rule.extension extension ]
let () = Ppxlib.Driver.register_transformation "rules" ~rules

View file

@ -0,0 +1,3 @@
Running dune utop with directory containing a PPX rewriter
$ dune utop ppx -- use_ppx.ml
PPX extension

View file

@ -0,0 +1,3 @@
let () =
Printf.printf "%s\n" [%foo];
exit 0

View file

@ -0,0 +1,2 @@
(library
(name forutop))

View file

@ -0,0 +1 @@
let run () = print_endline "hello in utop"

View file

@ -0,0 +1,2 @@
$ dune utop forutop -- init_forutop.ml
hello in utop

View file

@ -0,0 +1,5 @@
(library
(name forutop)
(foreign_stubs
(language c)
(names forutop_stubs)))

View file

@ -0,0 +1,2 @@
external hello_in_utop: unit -> string = "hello_in_utop"
let run () = print_endline (hello_in_utop ())

View file

@ -0,0 +1,6 @@
#include <caml/alloc.h>
value hello_in_utop(value v_unit)
{
return caml_copy_string("hello in utop");
}

View file

@ -0,0 +1,2 @@
$ dune utop forutop -- init_forutop.ml
hello in utop