Skip to content

Commit

Permalink
Travis fixing, no_newline_sed #WIP
Browse files Browse the repository at this point in the history
Add downloader example test to the Travis script

This fixes issue #29.

The example had a bashism while using `sed`; cf. also #30.
  • Loading branch information
smondet committed Dec 20, 2016
1 parent 5424c72 commit a0dc746
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
21 changes: 14 additions & 7 deletions src/test/examples.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ let downloader () =
let options = List.concat_map regexp_list ~f:(fun r -> ["-e"; r]) in
string >> exec (["grep"; "-q"] @ options) |> succeeds in

let no_newline_sed ~input expr =
let with_potential_newline =
input >> exec ["sed"; expr]
|> output_as_string
in
with_potential_newline >> exec ["tr"; "-d"; "\\n"]
|> output_as_string
in

let module Unwrapper = struct

type cmd = unit t
Expand All @@ -80,8 +89,8 @@ let downloader () =
{extension = ext; verb; commands}

let remove_suffix v suf =
v >> exec ["sed"; sprintf "s:^\\(.*\\)%s$:\\1:" suf]
|> output_as_string
no_newline_sed ~input:v (sprintf "s:^\\(.*\\)%s$:\\1:" suf)


let to_switch name_variable t_list =
let make_case t =
Expand All @@ -92,7 +101,7 @@ let downloader () =
~name:(sprintf "%s-%s" t.verb t.extension)
(t.commands name_variable);
name_variable#set
(remove_suffix name_variable#get (sprintf "\\.%s" t.extension));
(remove_suffix name_variable#get (sprintf ".%s" t.extension));
] in
seq [
say [string "Extract loop: "; name_variable#get];
Expand Down Expand Up @@ -127,7 +136,7 @@ let downloader () =
make ~ext:"gpg" ~verb:"Decyphering" (fun name -> [
call [string "gpg";
string "--output";
(remove_suffix name#get "\\.gpg");
(remove_suffix name#get ".gpg");
string "-d"; name#get;];
]);
]
Expand All @@ -154,9 +163,7 @@ let downloader () =
if_seq (filename_ov =$= no_value)
~t:begin
let filename =
url >> exec ["sed"; "s:.*/\\([^\\?\\/]*\\)\\?.*:\\1:"]
|> output_as_string
in
no_newline_sed ~input:url "s:.*/\\([^\\?\\/]*\\)\\?.*:\\1:" in
let output_path =
string_concat [tmp_dir; string "/"; filename] in
[current_name#set output_path]
Expand Down
35 changes: 33 additions & 2 deletions tools/travis_ci_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,37 @@ make native
gennspio_test=_build/src/test/genspio-test.byte
genspio_examples=_build/src/test/genspio-examples.byte

$genspio_test
echo "================== TEST 0 ======================================================"
$gennspio_test

# We also run the example
# we get the script and then we test it

genspio_downloader=/tmp/genspio-downloader
$genspio_examples dl $genspio_downloader

sh $genspio_downloader -h

echo "================== TEST 1 ======================================================"
sh $genspio_downloader -c -t /tmp/test1 -f k3.0.0.tar.gz -u https://github.com/hammerlab/ketrew/archive/ketrew.3.0.0.tar.gz
ls -la /tmp/test1
test -f /tmp/test1/k3.0.0.tar
test -f /tmp/test1/ketrew-ketrew.3.0.0/README.md


echo "================== TEST 2 ======================================================"
sh $genspio_downloader -c -t /tmp/genstest2 -u https://www.dropbox.com/s/h16b8ak9smkgw3g/test.tar.gz.zip.bz2.tbz2?raw=1
ls -la /tmp/genstest2
test -f /tmp/genstest2/src/lib/EDSL.ml

echo "================== TEST 3 ======================================================"
# like -t /tmp/test2, without -c (which is fragile w.r.t. tar)
mkdir -p /tmp/test3
cd /tmp/test3
sh $genspio_downloader -u https://github.com/hammerlab/ketrew/archive/ketrew.3.0.0.tar.gz
ls -la /tmp/test3
test -f /tmp/test3/ketrew-ketrew.3.0.0/README.md




$genspio_examples dl -

0 comments on commit a0dc746

Please sign in to comment.