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

test: add integration tests as example projects #37

Merged
merged 1 commit into from
Apr 20, 2023
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/target
target
Cargo.lock
.*

Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"rust-analyzer.imports.prefix": "crate",
"trailing-spaces.includeEmptyLines": false,
"editor.renderWhitespace": "all",
"git.ignoreLimitWarning": true
"git.ignoreLimitWarning": true,
"rust-analyzer.showUnlinkedFileNotification": false
}
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ keywords = ["cli", "macro", "clap"]
edition = "2021"
exclude = [".*", "rust-toolchain", "*.toml", "justfile"]

[lib]
doctest = false

[workspace]
members = ["impl"]

[dependencies]
clap = { version = "3.0.7", features = ["derive"] }
fncmd-impl = { path = "impl", version = "=1.3.0" }
once_cell = "1.9.0"

[workspace]
members = ["impl"]
once_cell = "1.9.0"
12 changes: 12 additions & 0 deletions examples/example-basic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "example-basic"
version = "0.0.0"
edition = "2021"

[dependencies]
fncmd = { path = "../.." }

[dev-dependencies]
trycmd = "0.14.16"

[workspace]
43 changes: 43 additions & 0 deletions examples/example-basic/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
```console
$ example-basic
? 2
error: The following required arguments were not provided:
<GREETING>

USAGE:
example-basic [OPTIONS] <GREETING> [NAME]

For more information try --help

```

```console
$ example-basic --help
example-basic 0.0.0
Prints greeting message

USAGE:
example-basic [OPTIONS] <GREETING> [NAME]

ARGS:
<GREETING> Greeting message
<NAME> Name of someone to greet

OPTIONS:
--bang Whether to use “!” instead of “.” at the end of the message
-h, --help Print help information
-V, --version Print version information

```

```console
$ example-basic Hello World
Hello, World.

```

```console
$ example-basic Hello --bang
Hello!

```
17 changes: 17 additions & 0 deletions examples/example-basic/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// Prints greeting message.
#[fncmd::fncmd]
fn main(
/// Greeting message.
greeting: String,
/// Name of someone to greet.
name: Option<String>,
/// Whether to use “!” instead of “.” at the end of the message.
#[opt]
bang: bool,
) {
if let Some(name) = name {
println!("{greeting}, {name}{}", if bang { "!" } else { "." });
} else {
println!("{greeting}{}", if bang { "!" } else { "." });
}
}
2 changes: 2 additions & 0 deletions examples/example-basic/tests/trycmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[test]
fn trycmd() { trycmd::TestCases::new().case("README.md"); }
12 changes: 12 additions & 0 deletions examples/example-subcmds/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "example-subcmds"
version = "0.0.0"
edition = "2021"

[dependencies]
fncmd = { path = "../.." }

[dev-dependencies]
trycmd = "0.14.16"

[workspace]
52 changes: 52 additions & 0 deletions examples/example-subcmds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
```console
$ example-subcmds
Top-level command is called.

```

```console
$ example-subcmds --help
example-subcmds 0.0.0

USAGE:
example-subcmds [SUBCOMMAND]

OPTIONS:
-h, --help Print help information
-V, --version Print version information

SUBCOMMANDS:
child
help Print this message or the help of the given subcommand(s)

```

```console
$ example-subcmds child
One-level-deep subcommand is called.

```

```console
$ example-subcmds child grandchild
Two-level-deep subcommand is called.

```

```console
$ example-subcmds orphan
? 2
error: Found argument 'orphan' which wasn't expected, or isn't valid in this context

USAGE:
example-subcmds [SUBCOMMAND]

For more information try --help

```

```console
$ example-subcmds-orphan
Top-level orphan command is called.

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
pub fn main() {
println!("Two-level-deep subcommand is called.");
}
4 changes: 4 additions & 0 deletions examples/example-subcmds/src/bin/example-subcmds-child.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
pub fn main() {
println!("One-level-deep subcommand is called.");
}
4 changes: 4 additions & 0 deletions examples/example-subcmds/src/bin/example-subcmds-orphan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
fn main() {
println!("Top-level orphan command is called.");
}
4 changes: 4 additions & 0 deletions examples/example-subcmds/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
fn main() {
println!("Top-level command is called.");
}
2 changes: 2 additions & 0 deletions examples/example-subcmds/tests/trycmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[test]
fn trycmd() { trycmd::TestCases::new().case("README.md"); }
12 changes: 12 additions & 0 deletions examples/example-subcmdsflat/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "example-subcmdsflat"
version = "0.0.0"
edition = "2021"

[dependencies]
fncmd = { path = "../.." }

[dev-dependencies]
trycmd = "0.14.16"

[workspace]
52 changes: 52 additions & 0 deletions examples/example-subcmdsflat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
```console
$ example-subcmdsflat
Top-level command is called.

```

```console
$ example-subcmdsflat --help
example-subcmdsflat 0.0.0

USAGE:
example-subcmdsflat [SUBCOMMAND]

OPTIONS:
-h, --help Print help information
-V, --version Print version information

SUBCOMMANDS:
child
help Print this message or the help of the given subcommand(s)

```

```console
$ example-subcmdsflat child
One-level-deep subcommand is called.

```

```console
$ example-subcmdsflat child grandchild
Two-level-deep subcommand is called.

```

```console
$ example-subcmdsflat orphan
? 2
error: Found argument 'orphan' which wasn't expected, or isn't valid in this context

USAGE:
example-subcmdsflat [SUBCOMMAND]

For more information try --help

```

```console
$ example-subcmdsflat-orphan
Top-level orphan command is called.

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
pub fn main() {
println!("Two-level-deep subcommand is called.");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
pub fn main() {
println!("One-level-deep subcommand is called.");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
fn main() {
println!("Top-level orphan command is called.");
}
4 changes: 4 additions & 0 deletions examples/example-subcmdsflat/src/bin/example-subcmdsflat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
fn main() {
println!("Top-level command is called.");
}
2 changes: 2 additions & 0 deletions examples/example-subcmdsflat/tests/trycmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[test]
fn trycmd() { trycmd::TestCases::new().case("README.md"); }
6 changes: 6 additions & 0 deletions examples/example-workspace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[workspace]
members = ["crates/*"]

[workspace.package]
version = "0.0.0"
edition = "2021"
10 changes: 10 additions & 0 deletions examples/example-workspace/crates/bar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "example-workspace-bar"
version.workspace = true
edition.workspace = true

[dependencies]
fncmd = { path = "../../../.." }

[dev-dependencies]
trycmd = "0.14.16"
11 changes: 11 additions & 0 deletions examples/example-workspace/crates/bar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```console
$ example-workspace-bar
Top-level command is called.

```

```console
$ example-workspace-bar child
One-level-deep subcommand is called.

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
pub fn main() {
println!("One-level-deep subcommand is called.");
}
4 changes: 4 additions & 0 deletions examples/example-workspace/crates/bar/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
fn main() {
println!("Top-level command is called.");
}
2 changes: 2 additions & 0 deletions examples/example-workspace/crates/bar/tests/trycmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[test]
fn trycmd() { trycmd::TestCases::new().case("README.md"); }
10 changes: 10 additions & 0 deletions examples/example-workspace/crates/foo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "example-workspace-foo"
version.workspace = true
edition.workspace = true

[dependencies]
fncmd = { path = "../../../.." }

[dev-dependencies]
trycmd = "0.14.16"
11 changes: 11 additions & 0 deletions examples/example-workspace/crates/foo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```console
$ example-workspace-foo
Top-level command is called.

```

```console
$ example-workspace-foo child
One-level-deep subcommand is called.

```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
pub fn main() {
println!("One-level-deep subcommand is called.");
}
4 changes: 4 additions & 0 deletions examples/example-workspace/crates/foo/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[fncmd::fncmd]
fn main() {
println!("Top-level command is called.");
}
2 changes: 2 additions & 0 deletions examples/example-workspace/crates/foo/tests/trycmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[test]
fn trycmd() { trycmd::TestCases::new().case("README.md"); }
Loading