Skip to content
Open
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
129 changes: 56 additions & 73 deletions cargo-typify/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ use tempdir::TempDir;

#[test]
fn test_simple() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
Expand All @@ -14,8 +12,8 @@ fn test_simple() {

let output_file = temp.path().join("simple.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
cmd.args(["typify", input_file.to_str().unwrap()])
assert_cmd::cargo::cargo_bin_cmd!()
.args(["typify", input_file.to_str().unwrap()])
.assert()
.success();

Expand All @@ -26,15 +24,13 @@ fn test_simple() {

#[test]
fn test_default_output() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
let output_file = temp.path().join("output.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
cmd.args(["typify", input, "--output", output_file.to_str().unwrap()])
assert_cmd::cargo::cargo_bin_cmd!()
.args(["typify", input, "--output", output_file.to_str().unwrap()])
.assert()
.success();

Expand All @@ -45,13 +41,9 @@ fn test_default_output() {

#[test]
fn test_no_builder_stdout() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();

let output = cmd
let output = assert_cmd::cargo::cargo_bin_cmd!()
.args(["typify", input, "--no-builder", "--output", "-"])
.output()
.unwrap();
Expand All @@ -65,23 +57,21 @@ fn test_no_builder_stdout() {

#[test]
fn test_builder() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
let output_file = temp.path().join("output.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
cmd.args([
"typify",
input,
"--builder",
"--output",
output_file.to_str().unwrap(),
])
.assert()
.success();
assert_cmd::cargo::cargo_bin_cmd!()
.args([
"typify",
input,
"--builder",
"--output",
output_file.to_str().unwrap(),
])
.assert()
.success();

let actual = std::fs::read_to_string(output_file).unwrap();

Expand All @@ -90,25 +80,23 @@ fn test_builder() {

#[test]
fn test_derive() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
let output_file = temp.path().join("output.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
cmd.args([
"typify",
input,
"--no-builder",
"--additional-derive",
"ExtraDerive",
"--output",
output_file.to_str().unwrap(),
])
.assert()
.success();
assert_cmd::cargo::cargo_bin_cmd!()
.args([
"typify",
input,
"--no-builder",
"--additional-derive",
"ExtraDerive",
"--output",
output_file.to_str().unwrap(),
])
.assert()
.success();

let actual = std::fs::read_to_string(output_file).unwrap();

Expand All @@ -117,27 +105,25 @@ fn test_derive() {

#[test]
fn test_multi_derive() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
let output_file = temp.path().join("output.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
cmd.args([
"typify",
input,
"--no-builder",
"--additional-derive",
"ExtraDerive",
"--additional-derive",
"AnotherDerive",
"--output",
output_file.to_str().unwrap(),
])
.assert()
.success();
assert_cmd::cargo::cargo_bin_cmd!()
.args([
"typify",
input,
"--no-builder",
"--additional-derive",
"ExtraDerive",
"--additional-derive",
"AnotherDerive",
"--output",
output_file.to_str().unwrap(),
])
.assert()
.success();

let actual = std::fs::read_to_string(output_file).unwrap();

Expand All @@ -146,11 +132,10 @@ fn test_multi_derive() {

#[test]
fn test_help() {
use assert_cmd::Command;

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();

let output = cmd.args(["typify", "--help"]).output().unwrap();
let output = assert_cmd::cargo::cargo_bin_cmd!()
.args(["typify", "--help"])
.output()
.unwrap();

let output_stdout = String::from_utf8(output.stdout).unwrap();
let actual = dos2unix(&output_stdout);
Expand All @@ -161,24 +146,22 @@ fn test_help() {

#[test]
fn test_btree_map() {
use assert_cmd::Command;

let input = concat!(env!("CARGO_MANIFEST_DIR"), "/../example.json");

let temp = TempDir::new("cargo-typify").unwrap();
let output_file = temp.path().join("output.rs");

let mut cmd = Command::cargo_bin("cargo-typify").unwrap();
cmd.args([
"typify",
input,
"--map-type",
"::std::collections::BTreeMap",
"--output",
output_file.to_str().unwrap(),
])
.assert()
.success();
assert_cmd::cargo::cargo_bin_cmd!()
.args([
"typify",
input,
"--map-type",
"::std::collections::BTreeMap",
"--output",
output_file.to_str().unwrap(),
])
.assert()
.success();

let actual = std::fs::read_to_string(output_file).unwrap();

Expand Down