diff --git a/examples/mysql/getting_started_step_1/Cargo.toml b/examples/mysql/getting_started_step_1/Cargo.toml index 10909ef3bca8..d452c25da2ab 100644 --- a/examples/mysql/getting_started_step_1/Cargo.toml +++ b/examples/mysql/getting_started_step_1/Cargo.toml @@ -8,6 +8,9 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] } dotenvy = "0.15" +[dev_dependencies] +assert_cmd = "2.0.14" + [[bin]] name = "show_posts" doc = false diff --git a/examples/mysql/getting_started_step_1/tests/step_1.rs b/examples/mysql/getting_started_step_1/tests/step_1.rs new file mode 100644 index 000000000000..324d21e7d05d --- /dev/null +++ b/examples/mysql/getting_started_step_1/tests/step_1.rs @@ -0,0 +1,10 @@ +use assert_cmd::Command; + +#[test] +fn show_posts() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} diff --git a/examples/mysql/getting_started_step_2/Cargo.toml b/examples/mysql/getting_started_step_2/Cargo.toml index 00dd2675f1c4..d07d2b704e10 100644 --- a/examples/mysql/getting_started_step_2/Cargo.toml +++ b/examples/mysql/getting_started_step_2/Cargo.toml @@ -8,6 +8,9 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] } dotenvy = "0.15" +[dev_dependencies] +assert_cmd = "2.0.14" + [[bin]] name = "show_posts" doc = false diff --git a/examples/mysql/getting_started_step_2/tests/step_2.rs b/examples/mysql/getting_started_step_2/tests/step_2.rs new file mode 100644 index 000000000000..b21a9a07e984 --- /dev/null +++ b/examples/mysql/getting_started_step_2/tests/step_2.rs @@ -0,0 +1,27 @@ +use assert_cmd::Command; + +#[test] +fn write_post() { + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z"; diff --git a/examples/mysql/getting_started_step_3/Cargo.toml b/examples/mysql/getting_started_step_3/Cargo.toml index eb9c81a25383..24288748689a 100644 --- a/examples/mysql/getting_started_step_3/Cargo.toml +++ b/examples/mysql/getting_started_step_3/Cargo.toml @@ -8,6 +8,9 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["mysql"] } dotenvy = "0.15" +[dev_dependencies] +assert_cmd = "2.0.14" + [[bin]] name = "show_posts" doc = false diff --git a/examples/mysql/getting_started_step_3/tests/step_3.rs b/examples/mysql/getting_started_step_3/tests/step_3.rs new file mode 100644 index 000000000000..3e779c241fc4 --- /dev/null +++ b/examples/mysql/getting_started_step_3/tests/step_3.rs @@ -0,0 +1,54 @@ +use assert_cmd::Command; + +#[test] +fn publish_post() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); + + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); + + let _ = Command::cargo_bin("publish_post") + .unwrap() + .arg("1") + .assert() + .append_context("publish_post", "") + .stdout("Published post Test Title\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 1 posts\nTest Title\n-----------\n\ntest text\n1 2 3\n"); + + let _ = Command::cargo_bin("delete_post") + .unwrap() + .arg("Test Title") + .assert() + .append_context("delete_post", "") + .stdout("Deleted 1 posts\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z"; diff --git a/examples/postgres/getting_started_step_1/Cargo.toml b/examples/postgres/getting_started_step_1/Cargo.toml index ee57cfd7ddf4..96101d7771fd 100644 --- a/examples/postgres/getting_started_step_1/Cargo.toml +++ b/examples/postgres/getting_started_step_1/Cargo.toml @@ -8,6 +8,9 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] } dotenvy = "0.15" +[dev_dependencies] +assert_cmd = "2.0.14" + [[bin]] name = "show_posts" doc = false diff --git a/examples/postgres/getting_started_step_1/tests/step_1.rs b/examples/postgres/getting_started_step_1/tests/step_1.rs new file mode 100644 index 000000000000..324d21e7d05d --- /dev/null +++ b/examples/postgres/getting_started_step_1/tests/step_1.rs @@ -0,0 +1,10 @@ +use assert_cmd::Command; + +#[test] +fn show_posts() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} diff --git a/examples/postgres/getting_started_step_2/Cargo.toml b/examples/postgres/getting_started_step_2/Cargo.toml index 9d0ded076927..99eb748a9813 100644 --- a/examples/postgres/getting_started_step_2/Cargo.toml +++ b/examples/postgres/getting_started_step_2/Cargo.toml @@ -8,6 +8,9 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] } dotenvy = "0.15" +[dev_dependencies] +assert_cmd = "2.0.14" + [[bin]] name = "show_posts" doc = false diff --git a/examples/postgres/getting_started_step_2/tests/step_2.rs b/examples/postgres/getting_started_step_2/tests/step_2.rs new file mode 100644 index 000000000000..b21a9a07e984 --- /dev/null +++ b/examples/postgres/getting_started_step_2/tests/step_2.rs @@ -0,0 +1,27 @@ +use assert_cmd::Command; + +#[test] +fn write_post() { + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z"; diff --git a/examples/postgres/getting_started_step_3/Cargo.toml b/examples/postgres/getting_started_step_3/Cargo.toml index 3cbdafcd031d..5e3a8a1dbcf2 100644 --- a/examples/postgres/getting_started_step_3/Cargo.toml +++ b/examples/postgres/getting_started_step_3/Cargo.toml @@ -8,6 +8,9 @@ publish = false diesel = { version = "2.1.0", path = "../../../diesel", features = ["postgres"] } dotenvy = "0.15" +[dev_dependencies] +assert_cmd = "2.0.14" + [[bin]] name = "show_posts" doc = false diff --git a/examples/postgres/getting_started_step_3/tests/step_3.rs b/examples/postgres/getting_started_step_3/tests/step_3.rs new file mode 100644 index 000000000000..3e779c241fc4 --- /dev/null +++ b/examples/postgres/getting_started_step_3/tests/step_3.rs @@ -0,0 +1,54 @@ +use assert_cmd::Command; + +#[test] +fn publish_post() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); + + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); + + let _ = Command::cargo_bin("publish_post") + .unwrap() + .arg("1") + .assert() + .append_context("publish_post", "") + .stdout("Published post Test Title\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 1 posts\nTest Title\n-----------\n\ntest text\n1 2 3\n"); + + let _ = Command::cargo_bin("delete_post") + .unwrap() + .arg("Test Title") + .assert() + .append_context("delete_post", "") + .stdout("Deleted 1 posts\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z"; diff --git a/examples/sqlite/getting_started_step_1/Cargo.toml b/examples/sqlite/getting_started_step_1/Cargo.toml index a72fddd5c3b2..ae2fcfb1d653 100644 --- a/examples/sqlite/getting_started_step_1/Cargo.toml +++ b/examples/sqlite/getting_started_step_1/Cargo.toml @@ -11,6 +11,9 @@ diesel = { version = "2.1.0", path = "../../../diesel", features = ["sqlite"] } dotenvy = "0.15" libsqlite3-sys = { version = "0.28.0", features = ["bundled"] } +[dev_dependencies] +assert_cmd = "2.0.14" + [[bin]] name = "show_posts" doc = false diff --git a/examples/sqlite/getting_started_step_1/tests/step_1.rs b/examples/sqlite/getting_started_step_1/tests/step_1.rs new file mode 100644 index 000000000000..324d21e7d05d --- /dev/null +++ b/examples/sqlite/getting_started_step_1/tests/step_1.rs @@ -0,0 +1,10 @@ +use assert_cmd::Command; + +#[test] +fn show_posts() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} diff --git a/examples/sqlite/getting_started_step_2/Cargo.toml b/examples/sqlite/getting_started_step_2/Cargo.toml index 9d645210109a..e4aacd8f23e4 100644 --- a/examples/sqlite/getting_started_step_2/Cargo.toml +++ b/examples/sqlite/getting_started_step_2/Cargo.toml @@ -10,6 +10,9 @@ diesel = { version = "2.1.0", path = "../../../diesel", features = ["sqlite", "r dotenvy = "0.15" libsqlite3-sys = { version = "0.28.0", features = ["bundled"] } +[dev_dependencies] +assert_cmd = "2.0.14" + [[bin]] name = "show_posts" doc = false diff --git a/examples/sqlite/getting_started_step_2/tests/step_2.rs b/examples/sqlite/getting_started_step_2/tests/step_2.rs new file mode 100644 index 000000000000..b21a9a07e984 --- /dev/null +++ b/examples/sqlite/getting_started_step_2/tests/step_2.rs @@ -0,0 +1,27 @@ +use assert_cmd::Command; + +#[test] +fn write_post() { + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z"; diff --git a/examples/sqlite/getting_started_step_3/Cargo.toml b/examples/sqlite/getting_started_step_3/Cargo.toml index 36a106ea72b8..df55ed256afc 100644 --- a/examples/sqlite/getting_started_step_3/Cargo.toml +++ b/examples/sqlite/getting_started_step_3/Cargo.toml @@ -10,6 +10,9 @@ diesel = { version = "2.1.0", path = "../../../diesel", features = ["sqlite", "r dotenvy = "0.15" libsqlite3-sys = { version = "0.28.0", features = ["bundled"] } +[dev_dependencies] +assert_cmd = "2.0.14" + [[bin]] name = "show_posts" doc = false diff --git a/examples/sqlite/getting_started_step_3/tests/step_3.rs b/examples/sqlite/getting_started_step_3/tests/step_3.rs new file mode 100644 index 000000000000..3e779c241fc4 --- /dev/null +++ b/examples/sqlite/getting_started_step_3/tests/step_3.rs @@ -0,0 +1,54 @@ +use assert_cmd::Command; + +#[test] +fn publish_post() { + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); + + let _ = Command::cargo_bin("write_post") + .unwrap() + .write_stdin("Test Title\ntest text\n1 2 3") + .assert() + .append_context("write_post", "") + .stdout( + "What would you like your title to be?\n\nOk! Let's write Test Title (Press " + .to_owned() + + EOF + + " when finished)\n\n\nSaved draft Test Title with id 1\n", + ); + + let _ = Command::cargo_bin("publish_post") + .unwrap() + .arg("1") + .assert() + .append_context("publish_post", "") + .stdout("Published post Test Title\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 1 posts\nTest Title\n-----------\n\ntest text\n1 2 3\n"); + + let _ = Command::cargo_bin("delete_post") + .unwrap() + .arg("Test Title") + .assert() + .append_context("delete_post", "") + .stdout("Deleted 1 posts\n"); + + let _ = Command::cargo_bin("show_posts") + .unwrap() + .assert() + .append_context("show_posts", "") + .stdout("Displaying 0 posts\n"); +} + +#[cfg(not(windows))] +const EOF: &str = "CTRL+D"; + +#[cfg(windows)] +const EOF: &str = "CTRL+Z";