-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbasic.rs
More file actions
132 lines (113 loc) · 5.03 KB
/
basic.rs
File metadata and controls
132 lines (113 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
// ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
//
#[cfg(test)]
mod passing {
use assert_cmd::prelude::*;
use std::process::Command;
#[test]
fn must_print_help_information_out_when_asked_to() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
let assert = cmd.arg("-h").assert();
let help_message: String = format!(
"{bin} {ver}
Sunshine <sunshine@uberspace.net>
CLI tool and Rust crate for parsing and generating data URLs
USAGE:
{bin}{exe} [FLAGS] [OPTIONS] [INPUT]
FLAGS:
-b, --base64 Enforces base64 encoding
-d, --decode Toggles decode mode on
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-c, --charset <ENCODING> Sets custom encoding parameter
-f, --fragment <FRAGMENT> Appends URL fragment
-i, --input-file <INPUT FILE> Provides input file
-t, --media-type <MEDIA TYPE> Sets custom media type
-o, --output-file <OUTPUT FILE> Specifies output file
ARGS:
<INPUT> Input string
",
bin = env!("CARGO_PKG_NAME"),
ver = env!("CARGO_PKG_VERSION"),
exe = if cfg!(windows) { ".exe" } else { "" }
);
assert
// Exit code must be 0
.success()
// STDERR must be empty
.stderr("")
// STDOUT must contain program name, version, and usage information
.stdout(help_message);
}
#[test]
fn must_print_program_name_and_version_number_when_asked_to() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
let assert = cmd.arg("-V").assert();
assert
// Exit code must be 0
.success()
// STDERR must be empty
.stderr("")
// STDOUT must contain program name and version
.stdout(format!(
"{bin} {ver}\n",
bin = env!("CARGO_PKG_NAME"),
ver = env!("CARGO_PKG_VERSION")
));
}
}
//
// ███████╗ █████╗ ██╗██╗ ██╗███╗ ██╗ ██████╗
// ██╔════╝██╔══██╗██║██║ ██║████╗ ██║██╔════╝
// █████╗ ███████║██║██║ ██║██╔██╗ ██║██║ ███╗
// ██╔══╝ ██╔══██║██║██║ ██║██║╚██╗██║██║ ██║
// ██║ ██║ ██║██║███████╗██║██║ ╚████║╚██████╔╝
// ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
//
#[cfg(test)]
mod failing {
use assert_cmd::prelude::*;
use std::process::Command;
#[test]
fn must_fail_when_given_wrong_argument() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
let assert = cmd.arg("-X").arg("").assert();
assert
// Exit code must be 1
.failure()
// STDERR must contain error message
.stderr(format!(
"error: Found argument '-X' which wasn't expected, or isn't valid in this context
USAGE:
{bin}{exe} [FLAGS] [OPTIONS] [INPUT]
For more information try --help\n",
bin = env!("CARGO_PKG_NAME"),
exe = if cfg!(windows) { ".exe" } else { "" }
))
// STDOUT must contain absolutely nothing
.stdout("");
}
#[test]
fn must_fail_when_both_file_and_argument_input_given() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
let assert = cmd
.arg("-i")
.arg("_data_/text-file.txt")
.arg("text")
.assert();
assert
// Exit code must be 1
.failure()
// STDERR must contain error message
.stderr("error: Both file and argument inputs provided\n")
// STDOUT must contain absolutely nothing
.stdout("");
}
}