Debian Codegraph @

tests/capturing.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 extern crate tempfilerust-analyzer cargo fomat-macros 0.3.2 tempfile/;
2 extern crate tarrust-analyzer cargo fomat-macros 0.3.2 tar/;
3
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#;
•5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#;
6
7
8 const FILESrust-analyzer cargo fomat-macros 0.3.2 FILES.: &'static [(&'static str, &'static str)] = &[
9 ("Cargo.toml", r#"
10 [package]
11 name = "pint"
12 version = "0.1.0"
13
14 [dependencies]
15 fomat-macros = { path = "PATH" }
16 "#),
17 ("src/main.rs", r#"
18 #[macro_use] extern crate fomat_macros;
19
20 fn foo() {
21 pint!("stdout"(1));
22 pintln!("stdout"(2));
23 epint!("stderr"(1));
24 epintln!("stderr"(2));
25 perr!("stderr"(1));
26 perrln!("stderr"(2));
27 }
28
29 fn main() {
30 foo();
31 }
32
33 #[test]
34 fn capturing() {
35 foo();
36 }
37 "#),
38 ("src/lib.rs", r#"
39 #[macro_use] extern crate fomat_macros;
40
41 pub fn called_from_other_crate() {
42 pintln!("nocapture"(1));
43 }
44 "#),
45 ("tests/nocapture.rs", r#"
46 extern crate pint;
47
48 #[test]
49 fn nocapture() {
50 pint::called_from_other_crate();
51 }
52 "#),
53 ];
54
55 fn unpack_filesrust-analyzer cargo fomat-macros 0.3.2 unpack_files().(directory: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, replace_path: &str) {
56 use tarrust-analyzer cargo tar 0.4.46 crate/::{Builderrust-analyzer cargo tar 0.4.46 builder/Builder#, Headerrust-analyzer cargo tar 0.4.46 header/Header#, Archiverust-analyzer cargo tar 0.4.46 archive/Archive#};
57
58 let mut builder = Builderrust-analyzer cargo tar 0.4.46 builder/Builder#::newrust-analyzer cargo tar 0.4.46 builder/impl#[`Builder<W>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().());
59 for &(name, data) in FILESrust-analyzer cargo fomat-macros 0.3.2 FILES. {
60 let data = data.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("PATH", replace_path);
61 let mut header = Headerrust-analyzer cargo tar 0.4.46 header/Header#::new_gnurust-analyzer cargo tar 0.4.46 header/impl#[Header]new_gnu().();
62 header.set_pathrust-analyzer cargo tar 0.4.46 header/impl#[Header]set_path().(name).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
63 header.set_sizerust-analyzer cargo tar 0.4.46 header/impl#[Header]set_size().(data.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() as u64);
64 header.set_cksumrust-analyzer cargo tar 0.4.46 header/impl#[Header]set_cksum().();
65 builder.appendrust-analyzer cargo tar 0.4.46 builder/impl#[`Builder<W>`]append().(&header, data.as_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_bytes().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
66 }
67
68 let archive: &[u8] = &builder.into_innerrust-analyzer cargo tar 0.4.46 builder/impl#[`Builder<W>`]into_inner().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
69 Archiverust-analyzer cargo tar 0.4.46 archive/Archive#::newrust-analyzer cargo tar 0.4.46 archive/impl#[`Archive<R>`]new().(archive).unpackrust-analyzer cargo tar 0.4.46 archive/impl#[`Archive<R>`]unpack().(directory)
70 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Can't unpack test crate");
71 }
72
73 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
74 fn capturingrust-analyzer cargo fomat-macros 0.3.2 capturing().() {
75 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#;
76 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/;
•77 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().;
78
79 let rootdir = {
80 let mut rootdir = envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::current_exerust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/current_exe().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
81 while rootdir.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#ne().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("target".as_refrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[str][`AsRef<OsStr>`]as_ref().()) {
82 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( rootdir.poprust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]pop().() );
83 }
84 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( rootdir.poprust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]pop().() );
85 rootdir
86 };
87
88 let pintdir = tempfilerust-analyzer cargo tempfile 3.27.0 crate/::Builderrust-analyzer cargo tempfile 3.27.0 Builder#::newrust-analyzer cargo tempfile 3.27.0 impl#[`Builder<'a, 'b>`]new().()
89 .prefixrust-analyzer cargo tempfile 3.27.0 impl#[`Builder<'a, 'b>`]prefix().("fomat-macros-capturing-test")
90 .tempdirrust-analyzer cargo tempfile 3.27.0 impl#[`Builder<'a, 'b>`]tempdir().()
91 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Can't create tempdir");
•92 unpack_filesrust-analyzer cargo fomat-macros 0.3.2 unpack_files().(pintdir.as_refrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir][`AsRef<Path>`]as_ref().(), /*rootdir.to_str().unwrap()*/&envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("CARGO_MANIFEST_DIR").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().());
93
94 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
95 Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().("cargo").argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("build")
•96 .env_removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]env_remove().("CARGO_TARGET_DIR")
97 .current_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]current_dir().(&pintdir)
98 .statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]status().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().()
99 );
100
101 let expected_stdout = "stdout1stdout2\n";
102 let expected_stderr = "stderr1stderr2\nstderr1stderr2\n";
103
•104 /*use std::io::stdout;
105 use std::io::Write;
106 let output = Command::new("find")
107 .current_dir(&pintdir)
108 .output().unwrap();
109 stdout().write_all(&output.stdout);
110
111 for (key, value) in env::vars() {
112 println!("{key}: {value}");
113 }*/
114
115 let pintexe;
116 if pintdir.as_refrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir][`AsRef<Path>`]as_ref().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("target/debug/pint").existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
117 pintexe = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().("target/debug/pint");
118 } else if pintdir.as_refrust-analyzer cargo tempfile 3.27.0 dir/impl#[TempDir][`AsRef<Path>`]as_ref().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("target").joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("DEB_TARGET_RUST_TYPE").unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().("___envar_not_found___".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("debug/pint").existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
119 pintexe = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("target").joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().("DEB_TARGET_RUST_TYPE").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()).joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("debug/pint");
120 } else {
121 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("can't find pint exuctable");
122 }
123
124 let output = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().(pintexe)
125 .current_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]current_dir().(&pintdir)
126 .outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]output().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
127 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#status..successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().());
128 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&output.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), expected_stdout);
129 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&output.stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stderr.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), expected_stderr);
130
131 let output = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().("cargo")
132 .argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("test")
133 .current_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]current_dir().(&pintdir)
134 .outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]output().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
135 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#status..successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().());
136 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&output.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(expected_stdout));
137 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&output.stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stderr.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(expected_stderr));
138 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&output.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().("nocapture1"));
139
140 let output = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().("cargo")
141 .argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]args().(&["test", "--", "--nocapture"])
142 .current_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]current_dir().(&pintdir)
143 .outputrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]output().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
144 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(output.statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#status..successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().());
145 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&output.stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stdout.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(expected_stdout));
146 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&output.stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Output#stderr.).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(expected_stderr));
147 }