Skip to content

Commit

Permalink
chore: reformat sandboxing tests (ocaml#9042)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg authored Oct 30, 2023
1 parent 2665816 commit 76ec458
Showing 1 changed file with 79 additions and 62 deletions.
141 changes: 79 additions & 62 deletions test/blackbox-tests/test-cases/sandboxing.t
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ If an action [chdir]s to a non-existing directory, it is created.
$ echo '(lang dune 2.6)' > dune-project
$ cat > dune <<EOF
> (rule
> (targets t)
> (deps (sandbox none))
> (action (chdir dir (progn (no-infer (write-file file hi)) (write-file ../t hi)))))
> (targets t)
> (deps (sandbox none))
> (action
> (chdir dir
> (progn
> (no-infer (write-file file hi))
> (write-file ../t hi)))))
> EOF
$ dune build t
$ cat _build/default/dir/file
Expand All @@ -138,9 +142,14 @@ re-created in the build directory.

$ cat > dune <<EOF
> (rule
> (targets t)
> (deps (sandbox always))
> (action (chdir dir (progn (run true) (no-infer (write-file file hi)) (write-file ../t hi)))))
> (targets t)
> (deps (sandbox always))
> (action
> (chdir dir
> (progn
> (run true)
> (no-infer (write-file file hi))
> (write-file ../t hi)))))
> EOF
$ dune build t
$ cat _build/default/dir/file
Expand All @@ -153,42 +162,50 @@ Show errors when [chdir]ing outside of the build directory.

$ cat > dune <<EOF
> (rule
> (targets t)
> (deps (sandbox none))
> (action (chdir /dir (progn (no-infer (write-file file hi)) (write-file ../t hi)))))
> (targets t)
> (deps (sandbox none))
> (action
> (chdir /dir
> (progn
> (no-infer (write-file file hi))
> (write-file ../t hi)))))
> EOF
$ dune build t
File "dune", line 4, characters 17-21:
4 | (action (chdir /dir (progn (no-infer (write-file file hi)) (write-file ../t hi)))))
^^^^
File "dune", line 5, characters 9-13:
5 | (chdir /dir
^^^^
Error: Directory /dir is outside the build directory. This is not allowed.
[1]

$ cat > dune <<EOF
> (rule
> (targets t)
> (deps (sandbox none))
> (action (chdir ../../dir (progn (no-infer (write-file file hi)) (write-file ../t hi)))))
> (targets t)
> (deps (sandbox none))
> (action (chdir ../../dir (progn (no-infer (write-file file hi)) (write-file ../t hi)))))
> EOF
$ dune build t
File "dune", line 4, characters 17-26:
4 | (action (chdir ../../dir (progn (no-infer (write-file file hi)) (write-file ../t hi)))))
^^^^^^^^^
File "dune", line 4, characters 16-25:
4 | (action (chdir ../../dir (progn (no-infer (write-file file hi)) (write-file ../t hi)))))
^^^^^^^^^
Error: Directory
$TESTCASE_ROOT/../../dir
is outside the build directory. This is not allowed.
[1]

$ cat > dune <<EOF
> (rule
> (targets t)
> (deps (sandbox none))
> (action (chdir ../dir (progn (no-infer (write-file file hi)) (write-file ../t hi)))))
> (targets t)
> (deps (sandbox none))
> (action
> (chdir ../dir
> (progn
> (no-infer (write-file file hi))
> (write-file ../t hi)))))
> EOF
$ dune build t
File "dune", line 4, characters 17-23:
4 | (action (chdir ../dir (progn (no-infer (write-file file hi)) (write-file ../t hi)))))
^^^^^^
File "dune", line 5, characters 9-15:
5 | (chdir ../dir
^^^^^^
Error: Directory
$TESTCASE_ROOT/../dir
is outside the build directory. This is not allowed.
Expand All @@ -201,9 +218,9 @@ Sandboxing with hard links correctly resolves (follows) symbolic links.

$ cat > dune <<EOF
> (rule
> (targets t)
> (deps link)
> (action (bash "cp %{deps} t; dune_cmd stat kind %{deps}")))
> (targets t)
> (deps link)
> (action (bash "cp %{deps} t; dune_cmd stat kind %{deps}")))
> EOF

The action observed [link] as a regular file with the right contents.
Expand Down Expand Up @@ -261,13 +278,13 @@ Now let's see what happens if the the symbolic link is produced by a rule.

$ cat > dune <<EOF
> (rule
> (deps file)
> (targets link)
> (action (bash "ln -s file link")))
> (deps file)
> (targets link)
> (action (run ln -s file link)))
> (rule
> (targets t)
> (deps link)
> (action (bash "cp %{deps} t; dune_cmd stat kind %{deps}")))
> (targets t)
> (deps link)
> (action (system "cp %{deps} t; dune_cmd stat kind %{deps}")))
> EOF

$ echo hi again > file
Expand All @@ -289,21 +306,21 @@ Test how Dune handles a loop with symbolic links.

$ cat > dune <<EOF
> (rule
> (targets link)
> (action (bash "ln -s link link")))
> (targets link)
> (action (bash "ln -s link link")))
> (rule
> (targets t)
> (deps link)
> (action (bash "cp %{deps} t; dune_cmd stat kind %{deps}")))
> (targets t)
> (deps link)
> (action (bash "cp %{deps} t; dune_cmd stat kind %{deps}")))
> EOF

This loop is caught immediately after running the rule that creates it.

$ dune build t --sandbox hardlink
File "dune", line 1, characters 0-59:
File "dune", line 1, characters 0-57:
1 | (rule
2 | (targets link)
3 | (action (bash "ln -s link link")))
2 | (targets link)
3 | (action (bash "ln -s link link")))
Error: Error trying to read targets after a rule was run:
- link: Cyclic symbolic link
[1]
Expand All @@ -313,13 +330,13 @@ which is circular.

$ cat > dune <<EOF
> (rule
> (deps $PWD/../link)
> (targets link)
> (action (bash "ln -s $PWD/../link link")))
> (deps $PWD/../link)
> (targets link)
> (action (run ln -s $PWD/../link link)))
> (rule
> (targets t)
> (deps link)
> (action (bash "cp %{deps} t; dune_cmd stat kind %{deps}")))
> (targets t)
> (deps link)
> (action (system "cp %{deps} t; dune_cmd stat kind %{deps}")))
> EOF

$ (cd ..; rm link; ln -s link link)
Expand All @@ -329,9 +346,9 @@ dependency.

$ dune build t --sandbox hardlink 2>&1 | grep -v "line 1"
1 | (rule
2 | (deps $TESTCASE_ROOT/test/../link)
3 | (targets link)
4 | (action (bash "ln -s $TESTCASE_ROOT/test/../link link")))
2 | (deps $TESTCASE_ROOT/test/../link)
3 | (targets link)
4 | (action (run ln -s $TESTCASE_ROOT/test/../link link)))
Error: File unavailable:
$TESTCASE_ROOT/test/../link
Cyclic symbolic link
Expand All @@ -340,28 +357,28 @@ So, it seems like we must play dirty to create a symbolic link loop.

$ cat > dune <<EOF
> (rule
> (targets link)
> (action (bash "ln -s $PWD/../link link")))
> (targets link)
> (action (run ln -s $PWD/../link link)))
> (rule
> (deps link (sandbox none))
> (targets dirty-rule)
> (action (bash "(cd $PWD/..; rm link; ln -s link link); touch dirty-rule")))
> (deps link (sandbox none))
> (targets dirty-rule)
> (action (system "(cd $PWD/..; rm link; ln -s link link); touch dirty-rule")))
> (rule
> (targets t)
> (deps link dirty-rule)
> (action (bash "cp %{deps} t; dune_cmd stat kind %{deps}")))
> (targets t)
> (deps link dirty-rule)
> (action (system "cp %{deps} t; dune_cmd stat kind %{deps}")))
> EOF

$ (cd ..; rm link; ln -s file link)

Finally, we get to see the error message printed out at sandbox creation.

$ dune build t --sandbox hardlink
File "dune", line 8, characters 0-106:
File "dune", line 8, characters 0-105:
8 | (rule
9 | (targets t)
10 | (deps link dirty-rule)
11 | (action (bash "cp %{deps} t; dune_cmd stat kind %{deps}")))
9 | (targets t)
10 | (deps link dirty-rule)
11 | (action (system "cp %{deps} t; dune_cmd stat kind %{deps}")))
Error: Sandbox creation error: cannot resolve symbolic link
"_build/default/link".
Reason: Too many indirections; is this a cyclic symbolic link?
Expand Down

0 comments on commit 76ec458

Please sign in to comment.