Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split up tests #16

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/test/basic.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let block = Alcotest.of_pp Shark.Block.pp

let test_shark_block () =
let build_string_no_hash = "shark-build:gdal-env" in
let expect = Shark.Block.v ~alias:"gdal-env" ~body:"" `Build in
let test = Shark.Block.of_info_string ~body:"" build_string_no_hash in
Alcotest.(check (option block)) "same block" (Some expect) test;

let build_string_hash = "shark-build:gdal-env:abcdefg" in
let expect =
Shark.Block.v ~hash:"abcdefg" ~alias:"gdal-env" ~body:"" `Build
in
let test = Shark.Block.of_info_string ~body:"" build_string_hash in
Alcotest.(check (option block)) "same block hash" (Some expect) test;

let ocaml = "ocaml" in
let test = Shark.Block.of_info_string ~body:"" ocaml in
Alcotest.(check (option block)) "same default block" None test

let tests = [ ("shark blocks", `Quick, test_shark_block) ]
77 changes: 77 additions & 0 deletions src/test/command.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
let command = Alcotest.of_pp Shark.Command.pp

let test_python_command_module () =
let testcase = "python3 -m some.module.code arg1 arg2" in
let expected =
Shark.Command.v ~name:"some.module.code"
~args:[ "-m"; "some.module.code"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let test_python_command_direct () =
let testcase = "python3 some/module/code.py arg1 arg2" in
let expected =
Shark.Command.v ~name:"code.py"
~args:[ "some/module/code.py"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let test_rscript_command_basic () =
let testcase = "Rscript some/module/code.r arg1 arg2" in
let expected =
Shark.Command.v ~name:"code.r"
~args:[ "some/module/code.r"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let test_rscript_command_options () =
let testcase = "Rscript --no-environ --save some/module/code.r arg1 arg2" in
let expected =
Shark.Command.v ~name:"code.r"
~args:[ "--no-environ"; "--save"; "some/module/code.r"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let test_generic_command_basic () =
let testcase = "docker arg1 arg2" in
let expected =
Shark.Command.v ~name:"docker"
~args:[ "docker"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let test_generic_command_basic_with_prefix () =
let testcase = "$ docker arg1 arg2" in
let expected =
Shark.Command.v ~name:"docker"
~args:[ "$"; "docker"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let tests =
[
( "Basic python command parsing for module",
`Quick,
test_python_command_module );
("Basic python command parsing for file", `Quick, test_python_command_direct);
("Basic R command parsing", `Quick, test_rscript_command_basic);
( "Basic R command parsing with options",
`Quick,
test_rscript_command_options );
("Basic command parsing", `Quick, test_generic_command_basic);
( "Basic command parsing with prefix",
`Quick,
test_generic_command_basic_with_prefix );
]
107 changes: 1 addition & 106 deletions src/test/test.ml
Original file line number Diff line number Diff line change
@@ -1,113 +1,8 @@
module Basic = struct
let block = Alcotest.of_pp Shark.Block.pp

let test_shark_block () =
let build_string_no_hash = "shark-build:gdal-env" in
let expect = Shark.Block.v ~alias:"gdal-env" ~body:"" `Build in
let test = Shark.Block.of_info_string ~body:"" build_string_no_hash in
Alcotest.(check (option block)) "same block" (Some expect) test;

let build_string_hash = "shark-build:gdal-env:abcdefg" in
let expect =
Shark.Block.v ~hash:"abcdefg" ~alias:"gdal-env" ~body:"" `Build
in
let test = Shark.Block.of_info_string ~body:"" build_string_hash in
Alcotest.(check (option block)) "same block hash" (Some expect) test;

let ocaml = "ocaml" in
let test = Shark.Block.of_info_string ~body:"" ocaml in
Alcotest.(check (option block)) "same default block" None test

let tests = [ ("shark blocks", `Quick, test_shark_block) ]
end

module CommandParsing = struct
let command = Alcotest.of_pp Shark.Command.pp

let test_python_command_module () =
let testcase = "python3 -m some.module.code arg1 arg2" in
let expected =
Shark.Command.v ~name:"some.module.code"
~args:[ "-m"; "some.module.code"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let test_python_command_direct () =
let testcase = "python3 some/module/code.py arg1 arg2" in
let expected =
Shark.Command.v ~name:"code.py"
~args:[ "some/module/code.py"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let test_rscript_command_basic () =
let testcase = "Rscript some/module/code.r arg1 arg2" in
let expected =
Shark.Command.v ~name:"code.r"
~args:[ "some/module/code.r"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let test_rscript_command_options () =
let testcase = "Rscript --no-environ --save some/module/code.r arg1 arg2" in
let expected =
Shark.Command.v ~name:"code.r"
~args:[ "--no-environ"; "--save"; "some/module/code.r"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let test_generic_command_basic () =
let testcase = "docker arg1 arg2" in
let expected =
Shark.Command.v ~name:"docker"
~args:[ "docker"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let test_generic_command_basic_with_prefix () =
let testcase = "$ docker arg1 arg2" in
let expected =
Shark.Command.v ~name:"docker"
~args:[ "$"; "docker"; "arg1"; "arg2" ]
~file_args:[]
in
let test = Shark.Command.of_string testcase in
Alcotest.(check (option command)) "Command" test (Some expected)

let tests =
[
( "Basic python command parsing for module",
`Quick,
test_python_command_module );
( "Basic python command parsing for file",
`Quick,
test_python_command_direct );
("Basic R command parsing", `Quick, test_rscript_command_basic);
( "Basic R command parsing with options",
`Quick,
test_rscript_command_options );
("Basic command parsing", `Quick, test_generic_command_basic);
( "Basic command parsing with prefix",
`Quick,
test_generic_command_basic_with_prefix );
]
end

let () =
Alcotest.run "shark"
[
("basic", Basic.tests);
("command parsing", CommandParsing.tests);
("command parsing", Command.tests);
("datafile modeling", Datafile.tests);
("frontmatter parsing", Frontmatter.tests);
]
Loading