-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test of fake_git bash completion
- Loading branch information
Showing
7 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
(executable | ||
(public_name main) | ||
(public_name basic) | ||
(libraries climate)) | ||
|
||
(cram | ||
(deps main.exe)) | ||
(deps basic.exe)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
(executable | ||
(public_name fake_git) | ||
(libraries climate unix)) | ||
|
||
(cram | ||
(deps fake_git.exe)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
open Climate | ||
|
||
let ls dir = | ||
let dir_handle = Unix.opendir dir in | ||
let rec loop files = | ||
try | ||
let file = Unix.readdir dir_handle in | ||
loop (file :: files) | ||
with | ||
| End_of_file -> files | ||
in | ||
List.rev (loop []) | ||
;; | ||
|
||
(* Fake protocol for defining branches so the list of branches can be | ||
updated dynamically by tests. *) | ||
let list_branches () = | ||
ls "./.git/branches" | ||
|> List.filter (Fun.negate @@ String.starts_with ~prefix:".") | ||
|> List.sort String.compare | ||
;; | ||
|
||
let branch_conv = | ||
let open Arg_parser in | ||
{ string with | ||
default_value_name = "BRANCH" | ||
; completion = Some (Completion.reentrant_thunk list_branches) | ||
} | ||
;; | ||
|
||
(* A command which mixes reentrant completion with file completion *) | ||
let checkout = | ||
let open Arg_parser in | ||
let+ _create_branch = flag [ "b" ] | ||
and+ _branch_name = pos_req 0 branch_conv | ||
and+ _files = pos_right 1 file in | ||
() | ||
;; | ||
|
||
(* A command which mixes reentrant completion with a named argument | ||
with a value completed with an enum *) | ||
let log = | ||
let open Arg_parser in | ||
let+ _pretty = | ||
named_opt [ "pretty"; "p" ] (string_enum [ "full"; "fuller"; "short"; "oneline" ]) | ||
and+ _branch_name = pos_req 0 branch_conv in | ||
() | ||
;; | ||
|
||
(* A command which mixes positional arguments and subcommands *) | ||
let bisect op = | ||
let open Arg_parser in | ||
match op with | ||
| `Mark -> | ||
let+ _status = pos_opt 0 (string_enum [ "good"; "bad" ]) in | ||
() | ||
| `Start | `Reset -> unit | ||
;; | ||
|
||
let () = | ||
let open Command in | ||
group | ||
[ subcommand "checkout" (singleton checkout) | ||
; subcommand "log" (singleton log) | ||
; subcommand "bisect" | ||
@@ group | ||
~default_arg_parser:(bisect `Mark) | ||
[ subcommand "start" (singleton (bisect `Start)) | ||
; subcommand "reset" (singleton (bisect `Reset)) | ||
] | ||
; subcommand "completions" ~hidden:true print_completion_script_bash | ||
] | ||
|> run | ||
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
$ ./fake_git.exe completions --program-name=fake-git --global-symbol-prefix=_fake_git_ > completion.sh | ||
$ x() { ../print_completions.sh ./completion.sh _fake_git_complete "$1" "$2"; } | ||
|
||
Make a fake .git directory with some branches. | ||
$ mkdir -p .git/branches | ||
$ touch .git/branches/foo | ||
$ touch .git/branches/bar | ||
|
||
$ x "fake-git " \ | ||
> " ^" | ||
checkout | ||
log | ||
bisect | ||
|
||
$ x "fake-git checkout " \ | ||
> " ^" | ||
bar | ||
foo | ||
|
||
$ x "fake-git checkout foo " \ | ||
> " ^" | ||
.git | ||
completion.sh | ||
fake_git.exe | ||
|
||
$ x "fake-git checkout foo a.txt " \ | ||
> " ^" | ||
.git | ||
completion.sh | ||
fake_git.exe | ||
|
||
$ x "fake-git checkout foo a.txt " \ | ||
> " ^ " | ||
bar | ||
foo | ||
|
||
$ x "fake-git checkout foo a.txt " \ | ||
> " ^ " | ||
.git | ||
completion.sh | ||
fake_git.exe | ||
|
||
$ x "fake-git log " \ | ||
> " ^" | ||
bar | ||
foo | ||
|
||
$ x "fake-git log -" \ | ||
> " ^" | ||
--help | ||
--pretty | ||
-h | ||
-p | ||
|
||
$ x "fake-git log --" \ | ||
> " ^" | ||
--help | ||
--pretty | ||
|
||
$ x "fake-git log --pretty " \ | ||
> " ^" | ||
full | ||
fuller | ||
short | ||
oneline | ||
|
||
$ x "fake-git log --pretty f" \ | ||
> " ^" | ||
full | ||
fuller | ||
|
||
$ x "fake-git log --pretty full " \ | ||
> " ^" | ||
bar | ||
foo | ||
|
||
|
||
$ x "fake-git log --pretty full foo " \ | ||
> " ^" | ||
--help | ||
--pretty | ||
-h | ||
-p | ||
|
||
Test that positional arguments and subcommands are both listed. | ||
$ x "fake-git bisect " \ | ||
> " ^" | ||
start | ||
reset | ||
good | ||
bad | ||
|
||
$ x "fake-git bisect -" \ | ||
> " ^" | ||
--help | ||
-h | ||
|
||
$ x "fake-git bisect start " \ | ||
> " ^" | ||
--help | ||
-h |