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,15 @@
(data_only_dirs foo_dir)
(library
(name dune_action_unit_tests)
(inline_tests
(deps some_dir/some_file))
(libraries
dune_action_plugin
ppx_expect.config
ppx_expect.config_types
base
ppx_inline_test.config
dune-glob)
(preprocess
(pps ppx_expect)))

View file

@ -0,0 +1,83 @@
open Dune_action_plugin.V1
module Glob = Dune_glob.V1
module Private = Dune_action_plugin.Private
let%expect_test _ =
try ignore @@ Path.of_string "/some/absolute/path" with
| Invalid_argument message ->
print_endline message;
[%expect
{| Path "/some/absolute/path" is absolute. All paths used with dune-action-plugin must be relative. |}]
;;
let%expect_test _ =
let action =
read_file ~path:(Path.of_string "some_dir/some_file") |> map ~f:print_endline
in
Private.do_run action;
[%expect
{|
Hello from foo!
|}]
;;
let%expect_test _ =
let action =
read_directory_with_glob ~glob:Glob.universal ~path:(Path.of_string "some_dir")
|> map ~f:(fun data -> String.concat "," data |> print_endline)
in
Private.do_run action;
[%expect
{|
some_file
|}]
;;
let%expect_test _ =
let action = write_file ~path:(Path.of_string "another_file") ~data:"Hello world!" in
Private.do_run action;
[%expect {| |}]
;;
let run_action_expect_throws action =
try
Private.do_run action;
print_endline "SHOULD BE UNREACHABLE"
with
| Private.Execution_error.E message -> print_endline message
;;
let%expect_test _ =
let action =
read_file ~path:(Path.of_string "file_that_does_not_exist") |> map ~f:ignore
in
run_action_expect_throws action;
[%expect {| read_file: open(file_that_does_not_exist): No such file or directory |}]
;;
let%expect_test _ =
let action =
read_directory_with_glob
~glob:Glob.universal
~path:(Path.of_string "directory_that_does_not_exist")
|> map ~f:ignore
in
run_action_expect_throws action;
[%expect
{|
read_directory: opendir(directory_that_does_not_exist): No such file or directory
|}]
;;
let%expect_test _ =
let action =
write_file
~path:(Path.of_string "directory_that_does_not_exist/some_file")
~data:"foo"
in
run_action_expect_throws action;
[%expect
{|
write_file: directory_that_does_not_exist/some_file: No such file or directory
|}]
;;

View file

@ -0,0 +1 @@
Hello from foo!