Skip to content

Commit

Permalink
use birdie for snapshot testing help text
Browse files Browse the repository at this point in the history
  • Loading branch information
TanklesXL committed May 16, 2024
1 parent a4d489f commit 5000733
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 122 deletions.
24 changes: 24 additions & 0 deletions birdie_snapshots/cmd1_help.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
version: 1.1.5
title: cmd1 help
file: ./test/glint_test.gleam
test_name: help_test
---
Some awesome global help text!

Command: cmd1

This is cmd1

USAGE:
gleam run -m test cmd1 ( cmd3 | cmd4 ) [ ARGS ] [ --flag2=<INT> --flag5=<FLOAT_LIST> --global=<STRING> ]

FLAGS:
--flag2=<INT> This is flag2
--flag5=<FLOAT_LIST> This is flag5
--global=<STRING> This is a global flag
--help Print help information

SUBCOMMANDS:
cmd3 This is cmd3
cmd4 This is cmd4
18 changes: 18 additions & 0 deletions birdie_snapshots/cmd2_help.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
version: 1.1.5
title: cmd2 help
file: ./test/glint_test.gleam
test_name: help_test
---
Some awesome global help text!

Command: cmd2

This is cmd2

USAGE:
gleam run -m test cmd2 <arg1> <arg2> [ --global=<STRING> ]

FLAGS:
--global=<STRING> This is a global flag
--help Print help information
19 changes: 19 additions & 0 deletions birdie_snapshots/cmd3_help.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
version: 1.1.5
title: cmd3 help
file: ./test/glint_test.gleam
test_name: help_test
---
Some awesome global help text!

Command: cmd1 cmd3

This is cmd3

USAGE:
gleam run -m test cmd1 cmd3 <woo> [ 2 or more arguments ] [ --flag3=<BOOL> --global=<STRING> ]

FLAGS:
--flag3=<BOOL> This is flag3
--global=<STRING> This is a global flag
--help Print help information
19 changes: 19 additions & 0 deletions birdie_snapshots/cmd4_help.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
version: 1.1.5
title: cmd4 help
file: ./test/glint_test.gleam
test_name: help_test
---
Some awesome global help text!

Command: cmd1 cmd4

This is cmd4

USAGE:
gleam run -m test cmd1 cmd4 [ --flag4=<FLOAT> --global=<STRING> ]

FLAGS:
--flag4=<FLOAT> This is flag4
--global=<STRING> This is a global flag
--help Print help information
21 changes: 21 additions & 0 deletions birdie_snapshots/cmd6_help.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
version: 1.1.5
title: cmd6 help
file: ./test/glint_test.gleam
test_name: help_test
---
Some awesome global help text!

Command: cmd5 cmd6

This is cmd6

USAGE:
gleam run -m test cmd5 cmd6 ( cmd7 ) [ ARGS ] [ --global=<STRING> ]

FLAGS:
--global=<STRING> This is a global flag
--help Print help information

SUBCOMMANDS:
cmd7 This is cmd7
14 changes: 14 additions & 0 deletions birdie_snapshots/cmd7_help.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
version: 1.1.5
title: cmd7 help
file: ./test/glint_test.gleam
test_name: help_test
---
Some awesome global help text!

Command: cmd5 cmd6 cmd7

This is cmd7

USAGE:
gleam run -m test cmd5 cmd6 cmd7 [ ARGS ]
22 changes: 22 additions & 0 deletions birdie_snapshots/root_help.accepted
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
version: 1.1.5
title: root help
file: ./test/glint_test.gleam
test_name: help_test
---
Some awesome global help text!

This is the root command

USAGE:
gleam run -m test ( cmd1 | cmd2 | cmd5 ) <arg1> <arg2> [ ARGS ] [ --flag1=<STRING> --global=<STRING> ]

FLAGS:
--flag1=<STRING> This is flag1
--global=<STRING> This is a global flag
--help Print help information

SUBCOMMANDS:
cmd1 This is cmd1
cmd2 This is cmd2
cmd5
1 change: 1 addition & 0 deletions gleam.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ gleam_community_colour = "~> 1.0"
[dev-dependencies]
gleeunit = "~> 1.0"
argv = ">= 1.0.2 and < 2.0.0"
birdie = ">= 1.1.5 and < 2.0.0"
10 changes: 10 additions & 0 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,27 @@

packages = [
{ name = "argv", version = "1.0.2", build_tools = ["gleam"], requirements = [], otp_app = "argv", source = "hex", outer_checksum = "BA1FF0929525DEBA1CE67256E5ADF77A7CDDFE729E3E3F57A5BDCAA031DED09D" },
{ name = "birdie", version = "1.1.5", build_tools = ["gleam"], requirements = ["argv", "filepath", "glance", "gleam_community_ansi", "gleam_erlang", "gleam_stdlib", "justin", "rank", "simplifile", "trie_again"], otp_app = "birdie", source = "hex", outer_checksum = "E1B6CB7B9EDE8F4C67F7E68C9FB45FBAA54881545F85D315D2B179560CC63F60" },
{ name = "filepath", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "filepath", source = "hex", outer_checksum = "EFB6FF65C98B2A16378ABC3EE2B14124168C0CE5201553DE652E2644DCFDB594" },
{ name = "glance", version = "0.11.0", build_tools = ["gleam"], requirements = ["gleam_stdlib", "glexer"], otp_app = "glance", source = "hex", outer_checksum = "8F3314D27773B7C3B9FB58D8C02C634290422CE531988C0394FA0DF8676B964D" },
{ name = "gleam_community_ansi", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_community_colour", "gleam_stdlib"], otp_app = "gleam_community_ansi", source = "hex", outer_checksum = "FE79E08BF97009729259B6357EC058315B6FBB916FAD1C2FF9355115FEB0D3A4" },
{ name = "gleam_community_colour", version = "1.4.0", build_tools = ["gleam"], requirements = ["gleam_json", "gleam_stdlib"], otp_app = "gleam_community_colour", source = "hex", outer_checksum = "795964217EBEDB3DA656F5EB8F67D7AD22872EB95182042D3E7AFEF32D3FD2FE" },
{ name = "gleam_erlang", version = "0.25.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_erlang", source = "hex", outer_checksum = "054D571A7092D2A9727B3E5D183B7507DAB0DA41556EC9133606F09C15497373" },
{ name = "gleam_json", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib", "thoas"], otp_app = "gleam_json", source = "hex", outer_checksum = "9063D14D25406326C0255BDA0021541E797D8A7A12573D849462CAFED459F6EB" },
{ name = "gleam_stdlib", version = "0.37.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "5398BD6C2ABA17338F676F42F404B9B7BABE1C8DC7380031ACB05BBE1BCF3742" },
{ name = "gleeunit", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "72CDC3D3F719478F26C4E2C5FED3E657AC81EC14A47D2D2DEBB8693CA3220C3B" },
{ name = "glexer", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "glexer", source = "hex", outer_checksum = "BD477AD657C2B637FEF75F2405FAEFFA533F277A74EF1A5E17B55B1178C228FB" },
{ name = "justin", version = "1.0.1", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "justin", source = "hex", outer_checksum = "7FA0C6DB78640C6DC5FBFD59BF3456009F3F8B485BF6825E97E1EB44E9A1E2CD" },
{ name = "rank", version = "1.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "rank", source = "hex", outer_checksum = "5660E361F0E49CBB714CC57CC4C89C63415D8986F05B2DA0C719D5642FAD91C9" },
{ name = "simplifile", version = "1.7.0", build_tools = ["gleam"], requirements = ["filepath", "gleam_stdlib"], otp_app = "simplifile", source = "hex", outer_checksum = "1D5DFA3A2F9319EC85825F6ED88B8E449F381B0D55A62F5E61424E748E7DDEB0" },
{ name = "snag", version = "0.3.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "snag", source = "hex", outer_checksum = "54D32E16E33655346AA3E66CBA7E191DE0A8793D2C05284E3EFB90AD2CE92BCC" },
{ name = "thoas", version = "1.2.0", build_tools = ["rebar3"], requirements = [], otp_app = "thoas", source = "hex", outer_checksum = "540C8CB7D9257F2AD0A14145DC23560F91ACDCA995F0CCBA779EB33AF5D859D1" },
{ name = "trie_again", version = "1.1.2", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "trie_again", source = "hex", outer_checksum = "5B19176F52B1BD98831B57FDC97BD1F88C8A403D6D8C63471407E78598E27184" },
]

[requirements]
argv = { version = ">= 1.0.2 and < 2.0.0" }
birdie = { version = ">= 1.1.5 and < 2.0.0"}
gleam_community_ansi = { version = "~> 1.0" }
gleam_community_colour = { version = "~> 1.0" }
gleam_stdlib = { version = "~> 0.36 or ~> 1.0" }
Expand Down
143 changes: 21 additions & 122 deletions test/glint_test.gleam
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import birdie
import gleam/result
import gleeunit
import gleeunit/should
import glint.{Help, Out}
Expand Down Expand Up @@ -192,149 +194,46 @@ pub fn help_test() {
glint.execute(cli, ["cmd2", "1", "2", "3"])
|> should.be_error()

let assert_unwrap_help = fn(res: Result(glint.Out(a), String)) -> String {
let assert Ok(Help(help)) = res
help
}

// help message for root command
glint.execute(cli, ["--help"])
|> should.equal(
Ok(Help(
"Some awesome global help text!
This is the root command
USAGE:
\tgleam run -m test ( cmd1 | cmd2 | cmd5 ) <arg1> <arg2> [ ARGS ] [ --flag1=<STRING> --global=<STRING> ]
FLAGS:
\t--flag1=<STRING>\t\tThis is flag1
\t--global=<STRING>\t\tThis is a global flag
\t--help\t\t\tPrint help information
SUBCOMMANDS:
\tcmd1\t\tThis is cmd1
\tcmd2\t\tThis is cmd2
\tcmd5",
)),
)
|> assert_unwrap_help
|> birdie.snap("root help")

// help message for command
glint.execute(cli, ["cmd1", "--help"])
|> should.equal(
Ok(Help(
"Some awesome global help text!
Command: cmd1
This is cmd1
USAGE:
\tgleam run -m test cmd1 ( cmd3 | cmd4 ) [ ARGS ] [ --flag2=<INT> --flag5=<FLOAT_LIST> --global=<STRING> ]
FLAGS:
\t--flag2=<INT>\t\tThis is flag2
\t--flag5=<FLOAT_LIST>\t\tThis is flag5
\t--global=<STRING>\t\tThis is a global flag
\t--help\t\t\tPrint help information
SUBCOMMANDS:
\tcmd3\t\tThis is cmd3
\tcmd4\t\tThis is cmd4",
)),
)
|> assert_unwrap_help
|> birdie.snap("cmd1 help")

// help message for nested command
glint.execute(cli, ["cmd1", "cmd4", "--help"])
|> should.equal(
Ok(Help(
"Some awesome global help text!
Command: cmd1 cmd4
This is cmd4
|> assert_unwrap_help
|> birdie.snap("cmd4 help")

USAGE:
\tgleam run -m test cmd1 cmd4 [ --flag4=<FLOAT> --global=<STRING> ]
FLAGS:
\t--flag4=<FLOAT>\t\tThis is flag4
\t--global=<STRING>\t\tThis is a global flag
\t--help\t\t\tPrint help information",
)),
)
// help message for command with no additional flags
glint.execute(cli, ["cmd2", "--help"])
|> should.equal(
Ok(Help(
"Some awesome global help text!
Command: cmd2
This is cmd2
USAGE:
\tgleam run -m test cmd2 <arg1> <arg2> [ --global=<STRING> ]
FLAGS:
\t--global=<STRING>\t\tThis is a global flag
\t--help\t\t\tPrint help information",
)),
)
|> assert_unwrap_help
|> birdie.snap("cmd2 help")

// help message for command with no additional flags
glint.execute(cli, ["cmd1", "cmd3", "--help"])
|> should.equal(
Ok(Help(
"Some awesome global help text!
Command: cmd1 cmd3
This is cmd3
USAGE:
\tgleam run -m test cmd1 cmd3 <woo> [ 2 or more arguments ] [ --flag3=<BOOL> --global=<STRING> ]
FLAGS:
\t--flag3=<BOOL>\t\tThis is flag3
\t--global=<STRING>\t\tThis is a global flag
\t--help\t\t\tPrint help information",
)),
)
|> assert_unwrap_help
|> birdie.snap("cmd3 help")

// help message for command a subcommand whose help was set with glint.path_help
glint.execute(cli, ["cmd5", "cmd6", "--help"])
|> should.equal(
Ok(Help(
"Some awesome global help text!
Command: cmd5 cmd6
This is cmd6
USAGE:
\tgleam run -m test cmd5 cmd6 ( cmd7 ) [ ARGS ] [ --global=<STRING> ]
FLAGS:
\t--global=<STRING>\t\tThis is a global flag
\t--help\t\t\tPrint help information
SUBCOMMANDS:
\tcmd7\t\tThis is cmd7",
)),
)
|> assert_unwrap_help
|> birdie.snap("cmd6 help")

// help message for command that had help_text set with glint.glint.path_help
// has no children or command runner set so no other details are available
glint.execute(cli, ["cmd5", "cmd6", "cmd7", "--help"])
|> should.equal(
Ok(Help(
"Some awesome global help text!
Command: cmd5 cmd6 cmd7
This is cmd7
USAGE:
\tgleam run -m test cmd5 cmd6 cmd7 [ ARGS ]",
)),
)
|> assert_unwrap_help
|> birdie.snap("cmd7 help")
}

pub fn global_and_group_flags_test() {
Expand Down

0 comments on commit 5000733

Please sign in to comment.