2017-01-08 05:16:32 +00:00
|
|
|
#[cfg(unix)]
|
|
|
|
extern crate unix_socket;
|
|
|
|
extern crate tempdir;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2017-01-08 05:16:32 +00:00
|
|
|
use common::util::*;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_output_multi_files_print_all_chars() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&["alpha.txt", "256.txt", "-A", "-n"])
|
2016-02-17 00:43:25 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only(" 1\tabcde$\n 2\tfghij$\n 3\tklmno$\n 4\tpqrst$\n \
|
2015-11-16 05:25:01 +00:00
|
|
|
5\tuvwxyz$\n 6\t^@^A^B^C^D^E^F^G^H^I$\n \
|
|
|
|
7\t^K^L^M^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\\^]^^^_ \
|
|
|
|
!\"#$%&\'()*+,-./0123456789:;\
|
|
|
|
<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~^?M-^@M-^AM-^\
|
|
|
|
BM-^CM-^DM-^EM-^FM-^GM-^HM-^IM-^JM-^KM-^LM-^MM-^NM-^OM-^PM-^QM-^RM-^SM-^TM-^UM-^V\
|
|
|
|
M-^WM-^XM-^YM-^ZM-^[M-^\\M-^]M-^^M-^_M- \
|
|
|
|
M-!M-\"M-#M-$M-%M-&M-\'M-(M-)M-*M-+M-,M--M-.M-/M-0M-1M-2M-3M-4M-5M-6M-7M-8M-9M-:\
|
|
|
|
M-;M-<M-=M->M-?M-@M-AM-BM-CM-DM-EM-FM-GM-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-U\
|
|
|
|
M-VM-WM-XM-YM-ZM-[M-\\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-oM-\
|
|
|
|
pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^?");
|
|
|
|
}
|
|
|
|
|
2017-01-23 02:34:47 +00:00
|
|
|
#[test]
|
|
|
|
fn test_numbered_lines_no_trailing_newline() {
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&["nonewline.txt", "alpha.txt", "-n"])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only(" 1\ttext without a trailing newlineabcde\n 2\tfghij\n \
|
|
|
|
3\tklmno\n 4\tpqrst\n 5\tuvwxyz\n");
|
|
|
|
}
|
|
|
|
|
2016-02-17 00:43:25 +00:00
|
|
|
#[test]
|
|
|
|
fn test_stdin_show_nonprinting() {
|
|
|
|
for same_param in vec!["-v", "--show-nonprinting"] {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-11-25 19:14:46 +00:00
|
|
|
.args(&[same_param])
|
2016-02-17 00:43:25 +00:00
|
|
|
.pipe_in("\t\0\n")
|
|
|
|
.succeeds()
|
2019-02-07 20:54:48 +00:00
|
|
|
.stdout_only("\t^@\n");
|
2016-02-17 00:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_show_tabs() {
|
|
|
|
for same_param in vec!["-T", "--show-tabs"] {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&[same_param])
|
2016-02-17 00:43:25 +00:00
|
|
|
.pipe_in("\t\0\n")
|
|
|
|
.succeeds()
|
2019-02-07 20:54:48 +00:00
|
|
|
.stdout_only("^I\0\n");
|
2016-02-17 00:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_stdin_show_ends() {
|
|
|
|
for same_param in vec!["-E", "--show-ends"] {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&[same_param,"-"])
|
2019-02-07 20:54:48 +00:00
|
|
|
.pipe_in("\t\0\n\t")
|
2016-02-17 00:43:25 +00:00
|
|
|
.succeeds()
|
2019-02-07 20:54:48 +00:00
|
|
|
.stdout_only("\t\0$\n\t");
|
2016-02-17 00:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[test]
|
2016-02-17 07:06:28 +00:00
|
|
|
fn test_stdin_show_all() {
|
2016-02-17 00:43:25 +00:00
|
|
|
for same_param in vec!["-A", "--show-all"] {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&[same_param])
|
2016-02-17 00:43:25 +00:00
|
|
|
.pipe_in("\t\0\n")
|
|
|
|
.succeeds()
|
2019-02-07 20:54:48 +00:00
|
|
|
.stdout_only("^I^@$\n");
|
2016-02-17 00:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2016-02-17 00:43:25 +00:00
|
|
|
#[test]
|
|
|
|
fn test_stdin_nonprinting_and_endofline() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&["-e"])
|
2016-02-17 00:43:25 +00:00
|
|
|
.pipe_in("\t\0\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("\t^@$\n");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 07:06:28 +00:00
|
|
|
#[test]
|
2016-02-17 00:43:25 +00:00
|
|
|
fn test_stdin_nonprinting_and_tabs() {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&["-t"])
|
2016-02-17 00:43:25 +00:00
|
|
|
.pipe_in("\t\0\n")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("^I^@\n");
|
|
|
|
}
|
2016-02-17 07:06:28 +00:00
|
|
|
|
2016-02-17 00:43:25 +00:00
|
|
|
#[test]
|
|
|
|
fn test_stdin_squeeze_blank() {
|
|
|
|
for same_param in vec!["-s", "--squeeze-blank"] {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.arg(same_param)
|
2016-07-17 17:39:57 +00:00
|
|
|
.pipe_in("\n\na\n\n\n\n\nb\n\n\n")
|
2016-02-17 00:43:25 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("\na\n\nb\n\n");
|
|
|
|
}
|
2016-02-17 07:06:28 +00:00
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[test]
|
|
|
|
fn test_stdin_number_non_blank() {
|
2016-02-17 00:43:25 +00:00
|
|
|
for same_param in vec!["-b", "--number-nonblank"] {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.arg(same_param)
|
2016-02-17 00:43:25 +00:00
|
|
|
.arg("-")
|
2016-07-17 17:39:57 +00:00
|
|
|
.pipe_in("\na\nb\n\n\nc")
|
2016-02-17 00:43:25 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("\n 1\ta\n 2\tb\n\n\n 3\tc");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_non_blank_overrides_number() {
|
|
|
|
for same_param in vec!["-b", "--number-nonblank"] {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&[same_param, "-"])
|
2016-07-17 17:39:57 +00:00
|
|
|
.pipe_in("\na\nb\n\n\nc")
|
2016-02-17 00:43:25 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_only("\n 1\ta\n 2\tb\n\n\n 3\tc");
|
2017-01-08 05:16:32 +00:00
|
|
|
}
|
2016-02-17 00:43:25 +00:00
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2016-02-17 00:43:25 +00:00
|
|
|
#[test]
|
|
|
|
fn test_squeeze_blank_before_numbering() {
|
|
|
|
for same_param in vec!["-s", "--squeeze-blank"] {
|
2016-08-23 11:52:43 +00:00
|
|
|
new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.args(&[same_param, "-n", "-"])
|
2016-02-17 00:43:25 +00:00
|
|
|
.pipe_in("a\n\n\nb")
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only(" 1\ta\n 2\t\n 3\tb");
|
|
|
|
}
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
2017-01-08 05:16:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(foo)]
|
|
|
|
fn test_domain_socket() {
|
|
|
|
use std::thread;
|
|
|
|
use self::unix_socket::UnixListener;
|
|
|
|
use self::tempdir::TempDir;
|
|
|
|
use std::io::prelude::*;
|
|
|
|
|
|
|
|
let dir = TempDir::new("unix_socket").expect("failed to create dir");
|
|
|
|
let socket_path = dir.path().join("sock");
|
|
|
|
let listener = UnixListener::bind(&socket_path).expect("failed to create socket");
|
|
|
|
|
|
|
|
let thread = thread::spawn(move || {
|
|
|
|
let mut stream = listener.accept().expect("failed to accept connection").0;
|
|
|
|
stream.write_all(b"a\tb").expect("failed to write test data");
|
|
|
|
});
|
|
|
|
|
|
|
|
new_ucmd!()
|
|
|
|
.args(&[socket_path])
|
|
|
|
.succeeds()
|
|
|
|
.stdout_only("a\tb");
|
|
|
|
|
|
|
|
thread.join().unwrap();
|
|
|
|
}
|