Skip to content

Commit

Permalink
Merge PR #9 (@smondet, Fix output_as_string)
Browse files Browse the repository at this point in the history
  • Loading branch information
smondet committed Oct 11, 2016
2 parents f22331f + e608c69 commit c0facff
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
3 changes: 1 addition & 2 deletions src/lib/language.ml
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ let rec to_shell: type a. _ -> a t -> string =
| Literal lit ->
Literal.to_shell lit
| Output_as_string e ->
sprintf "\"$( { %s || %s ; } | od -t o1 -An -v | tr -d ' \\n' )\""
(continue e) params.die_command
sprintf "\"$( { %s ; } | od -t o1 -An -v | tr -d ' \\n' )\"" (continue e)
| Feed (string, e) ->
sprintf {sh| %s | %s |sh}
(continue string |> expand_octal) (continue e)
Expand Down
58 changes: 43 additions & 15 deletions src/test/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,6 @@ let tests =
return 10;
];
);
exits 77 Construct.( (* 77 Is the value of ~exit_with in the call
to with_trap *)
let tmp = "/tmp/test_trapping" in
let cat_tmp = exec ["cat"; tmp] in
seq [
exec ["rm"; "-f"; tmp];
if_then_else
(* cat <absent-file> |> to_string should abort the script: *)
(cat_tmp |> output_as_string <$> string "nnnn")
(return 11)
(return 12);
return 13;
];
);
begin
let minus_f = "one \nwith \\ spaces and \ttabs -dashes -- " in
let make ret minus_g single =
Expand Down Expand Up @@ -264,7 +250,49 @@ let tests =
(return 22)
);
]
end
end;
exits 11 Construct.(
let tmp = "/tmp/test_error_in_output_as_string" in
let cat_tmp = exec ["cat"; tmp] in
seq [
exec ["rm"; "-f"; tmp];
if_then_else
(* cat <absent-file> |> to_string does not abort the script: *)
(cat_tmp |> output_as_string =$= string "")
(return 11)
(return 12);
];
);
exits 11 Construct.(
let tmp = "/tmp/test_error_in_output_as_string" in
let cat_tmp = exec ["cat"; tmp] in
seq [
exec ["rm"; "-f"; tmp];
if_then_else
(seq [printf "aaa"; cat_tmp] |> output_as_string =$= string "aaa")
(return 11)
(return 12);
];
);
exits 77 Construct.(
let tmp = "/tmp/test_error_in_output_as_string" in
let cat_tmp = exec ["cat"; tmp] in
let succeed_or_die ut =
if_then_else (succeeds ut)
nop
(seq [
printf "Failure !";
fail;
]) in
seq [
exec ["rm"; "-f"; tmp];
if_then_else
(seq [printf "aaa"; cat_tmp] |> succeed_or_die
|> output_as_string =$= string "aaa")
(return 11)
(return 12);
];
);
]


Expand Down

0 comments on commit c0facff

Please sign in to comment.