Skip to content

Commit 6330269

Browse files
authored
Merge pull request #1076 from CraftSpider/improve-tests
Make file expectations always check all expected files at once
2 parents 12396e2 + 545fa2e commit 6330269

9 files changed

Lines changed: 190 additions & 121 deletions

File tree

crates/bridge_core/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,10 +1224,14 @@ pub unsafe extern "C" fn ttbc_diag_append(diag: &mut Diagnostic, text: *const li
12241224
}
12251225

12261226
/// "Finish" a diagnostic: report it to the driver and free the diagnostic object.
1227+
///
1228+
/// # Safety
1229+
///
1230+
/// This function is unsafe because it dereferences a raw Diagnostic pointer
12271231
#[no_mangle]
1228-
pub extern "C" fn ttbc_diag_finish(es: &mut CoreBridgeState, diag: *mut Diagnostic) {
1232+
pub unsafe extern "C" fn ttbc_diag_finish(es: &mut CoreBridgeState, diag: *mut Diagnostic) {
12291233
// By creating the box, we will free the diagnostic when this function exits.
1230-
let rdiag = unsafe { Box::from_raw(diag as *mut Diagnostic) };
1234+
let rdiag = Box::from_raw(diag);
12311235
es.status
12321236
.report(rdiag.kind, format_args!("{}", rdiag.message), None);
12331237
}

crates/docmodel/src/workspace.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ impl WorkspaceCreator {
144144
tex_dir.push("_preamble.tex");
145145
let mut f = fs::File::create(&tex_dir)?;
146146
f.write_all(
147-
br#"\documentclass{article}
147+
br"\documentclass{article}
148148
\title{My Title}
149149
\begin{document}
150-
"#,
150+
",
151151
)?;
152152
tex_dir.pop();
153153
}
@@ -156,8 +156,8 @@ impl WorkspaceCreator {
156156
tex_dir.push("index.tex");
157157
let mut f = fs::File::create(&tex_dir)?;
158158
f.write_all(
159-
br#"Hello, world.
160-
"#,
159+
br"Hello, world.
160+
",
161161
)?;
162162
tex_dir.pop();
163163
}
@@ -166,8 +166,8 @@ impl WorkspaceCreator {
166166
tex_dir.push("_postamble.tex");
167167
let mut f = fs::File::create(&tex_dir)?;
168168
f.write_all(
169-
br#"\end{document}
170-
"#,
169+
br"\end{document}
170+
",
171171
)?;
172172
tex_dir.pop();
173173
}

crates/io_base/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ fn try_normalize_tex_path(path: &str) -> Option<String> {
674674

675675
let r = repeat("..")
676676
.take(parent_level)
677-
.chain(r.into_iter())
677+
.chain(r)
678678
// No `join` on `Iterator`.
679679
.collect::<Vec<_>>()
680680
.join("/");

dist/azure-build-and-test.yml

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,52 @@ parameters:
173173
vars:
174174
TARGET: i686-unknown-linux-gnu
175175

176-
- name: mips_unknown_linux_gnu
177-
vars:
178-
TARGET: mips-unknown-linux-gnu
179-
180176
- name: x86_64_unknown_linux_musl
181177
vars:
182178
TARGET: x86_64-unknown-linux-musl
183179

184180
jobs:
185181

182+
# rustfmt check
183+
- job: rustfmt
184+
pool:
185+
vmImage: ubuntu-20.04
186+
steps:
187+
- bash: rustup component add rustfmt
188+
displayName: "Install rustfmt"
189+
- bash: cargo fmt --all -- --check
190+
displayName: "Check rustfmt (cargo)"
191+
variables:
192+
TOOLCHAIN: stable
193+
194+
# clippy check
195+
- job: clippy
196+
pool:
197+
vmImage: ubuntu-20.04
198+
steps:
199+
- template: azure-generic-build-setup.yml
200+
- bash: |
201+
rustup component add clippy
202+
cargo clippy --version
203+
displayName: "Install clippy"
204+
# Ew, redundant with stock builds:
205+
- bash: |
206+
set -xeuo pipefail
207+
sudo apt-get update
208+
sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y \
209+
libgraphite2-dev \
210+
libharfbuzz-dev \
211+
libfontconfig1-dev \
212+
libicu-dev \
213+
libssl-dev \
214+
openssl \
215+
zlib1g-dev
216+
displayName: "Install pkg-config dependencies (Ubuntu)"
217+
- bash: cargo clippy --all --all-targets --all-features -- --deny warnings
218+
displayName: "Check clippy (cargo)"
219+
variables:
220+
TOOLCHAIN: stable
221+
186222
# pkg-config builds
187223
- ${{ each build in parameters.pkgconfigBuilds }}:
188224
- job: ${{ format('build_{0}_pkgconfig', build.name) }}
@@ -227,46 +263,6 @@ jobs:
227263
variables:
228264
TOOLCHAIN: stable
229265

230-
# rustfmt check
231-
- job: rustfmt
232-
pool:
233-
vmImage: ubuntu-20.04
234-
steps:
235-
- bash: rustup component add rustfmt
236-
displayName: "Install rustfmt"
237-
- bash: cargo fmt --all -- --check
238-
displayName: "Check rustfmt (cargo)"
239-
variables:
240-
TOOLCHAIN: stable
241-
242-
# clippy check
243-
- job: clippy
244-
pool:
245-
vmImage: ubuntu-20.04
246-
steps:
247-
- template: azure-generic-build-setup.yml
248-
- bash: |
249-
rustup component add clippy
250-
cargo clippy --version
251-
displayName: "Install clippy"
252-
# Ew, redundant with stock builds:
253-
- bash: |
254-
set -xeuo pipefail
255-
sudo apt-get update
256-
sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y \
257-
libgraphite2-dev \
258-
libharfbuzz-dev \
259-
libfontconfig1-dev \
260-
libicu-dev \
261-
libssl-dev \
262-
openssl \
263-
zlib1g-dev
264-
displayName: "Install pkg-config dependencies (Ubuntu)"
265-
- bash: cargo clippy --all --all-targets --all-features -- --deny warnings
266-
displayName: "Check clippy (cargo)"
267-
variables:
268-
TOOLCHAIN: stable
269-
270266
# book build
271267
- job: book
272268
pool:

tests/bibtex.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ use std::path::PathBuf;
88
use tectonic::io::{FilesystemIo, IoProvider, IoStack, MemoryIo};
99
use tectonic::BibtexEngine;
1010
use tectonic_bridge_core::{CoreBridgeLauncher, MinimalDriver};
11-
use tectonic_io_base::stdstreams::GenuineStdoutIo;
1211
use tectonic_status_base::NoopStatusBackend;
1312

1413
#[path = "util/mod.rs"]
1514
mod util;
16-
use crate::util::{test_path, ExpectedInfo};
15+
use crate::util::{test_path, Expected, ExpectedFile};
1716

1817
struct TestCase {
1918
stem: String,
@@ -55,9 +54,7 @@ impl TestCase {
5554

5655
let mut assets = FilesystemIo::new(&p, false, false, HashSet::new());
5756

58-
let mut genio = GenuineStdoutIo::new();
59-
60-
let io_list: Vec<&mut dyn IoProvider> = vec![&mut genio, &mut mem, &mut assets];
57+
let io_list: Vec<&mut dyn IoProvider> = vec![&mut mem, &mut assets];
6158

6259
let io = IoStack::new(io_list);
6360
let mut hooks = MinimalDriver::new(io);
@@ -74,13 +71,16 @@ impl TestCase {
7471

7572
let files = mem.files.borrow();
7673

74+
let mut expect = Expected::new();
75+
7776
if self.test_bbl {
78-
let expected_bbl = ExpectedInfo::read_with_extension(&mut p, "bbl");
79-
expected_bbl.test_from_collection(&files);
77+
expect =
78+
expect.file(ExpectedFile::read_with_extension(&mut p, "bbl").collection(&files));
8079
}
8180

82-
let expected_blg = ExpectedInfo::read_with_extension(&mut p, "blg");
83-
expected_blg.test_from_collection(&files);
81+
expect
82+
.file(ExpectedFile::read_with_extension(&mut p, "blg").collection(&files))
83+
.finish();
8484
}
8585
}
8686

tests/executable.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ fn biber_no_such_tool() {
403403

404404
command.env("TECTONIC_TEST_FAKE_BIBER", "ohnothereisnobiberprogram");
405405

406-
const REST: &str = r#"\bye"#;
406+
const REST: &str = r"\bye";
407407
let tex = format!("{BIBER_TRIGGER_TEX}{REST}");
408408

409409
command
@@ -431,15 +431,15 @@ fn biber_signal() {
431431

432432
#[test]
433433
fn biber_success() {
434-
const REST: &str = r#"
434+
const REST: &str = r"
435435
\ifsecond
436436
\ifnum\input{biberout.qqq}=456\relax
437437
a
438438
\else
439439
\ohnothebiberdidntwork
440440
\fi
441441
\fi
442-
\bye"#;
442+
\bye";
443443
let tex = format!("{BIBER_TRIGGER_TEX}{REST}");
444444
let output = run_with_biber("success", &tex);
445445
success_or_panic(&output);
@@ -771,14 +771,14 @@ fn v2_dump_suffix() {
771771
writeln!(
772772
file,
773773
"{}", // <= works around {} fussiness in Rust format strings
774-
r#"\newwrite\w
774+
r"\newwrite\w
775775
\immediate\openout\w=first.demo\relax
776776
\immediate\write\w{content-un}
777777
\immediate\closeout\w
778778
\immediate\openout\w=second.demo\relax
779779
\immediate\write\w{content-deux}
780780
\immediate\closeout\w
781-
"#
781+
"
782782
)
783783
.unwrap();
784784
}
@@ -806,15 +806,15 @@ fn v2_dump_suffix() {
806806
assert!(saw_first && saw_second);
807807
}
808808

809-
const SHELL_ESCAPE_TEST_DOC: &str = r#"\immediate\write18{mkdir shellwork}
809+
const SHELL_ESCAPE_TEST_DOC: &str = r"\immediate\write18{mkdir shellwork}
810810
\immediate\write18{echo 123 >shellwork/persist}
811811
\ifnum123=\input{shellwork/persist}
812812
a
813813
\else
814814
\ohnotheshellescapedidntwork
815815
\fi
816816
\bye
817-
"#;
817+
";
818818

819819
/// Test that shell escape actually runs the commands
820820
#[test]

tests/tex-outputs.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tectonic_status_base::NoopStatusBackend;
1717

1818
#[path = "util/mod.rs"]
1919
mod util;
20-
use crate::util::{ensure_plain_format, test_path, ExpectedInfo};
20+
use crate::util::{ensure_plain_format, test_path, Expected, ExpectedFile};
2121

2222
struct TestCase {
2323
stem: String,
@@ -107,7 +107,7 @@ impl TestCase {
107107
// add this layer.
108108
let mut assets = FilesystemIo::new(&test_path(&["assets"]), false, false, HashSet::new());
109109

110-
let expected_log = ExpectedInfo::read_with_extension(&mut p, "log");
110+
let expected_log = ExpectedFile::read_with_extension(&mut p, "log");
111111

112112
// Run the engine(s)!
113113
let res = {
@@ -159,20 +159,24 @@ impl TestCase {
159159

160160
let files = mem.files.borrow();
161161

162-
expected_log.test_from_collection(&files);
162+
let mut expect = Expected::new().file(expected_log.collection(&files));
163163

164164
if expect_xdv {
165-
ExpectedInfo::read_with_extension(&mut p, "xdv").test_from_collection(&files);
165+
expect =
166+
expect.file(ExpectedFile::read_with_extension(&mut p, "xdv").collection(&files));
166167
}
167-
168168
if self.check_synctex {
169-
ExpectedInfo::read_with_extension_rooted_gz(&mut p, "synctex.gz")
170-
.test_from_collection(&files);
169+
expect = expect.file(
170+
ExpectedFile::read_with_extension_rooted_gz(&mut p, "synctex.gz")
171+
.collection(&files),
172+
);
171173
}
172-
173174
if self.check_pdf {
174-
ExpectedInfo::read_with_extension(&mut p, "pdf").test_from_collection(&files);
175+
expect =
176+
expect.file(ExpectedFile::read_with_extension(&mut p, "pdf").collection(&files));
175177
}
178+
179+
expect.finish();
176180
}
177181
}
178182

tests/trip.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use tectonic_status_base::NoopStatusBackend;
2424

2525
#[path = "util/mod.rs"]
2626
mod util;
27-
use crate::util::{test_path, ExpectedInfo};
27+
use crate::util::{test_path, Expected, ExpectedFile};
2828

2929
#[test]
3030
fn trip_test() {
@@ -41,11 +41,11 @@ fn trip_test() {
4141
let mut tfm = SingleInputFileIo::new(&p);
4242

4343
// Read in the expected outputs.
44-
let expected_log = ExpectedInfo::read_with_extension(&mut p, "log");
45-
let expected_xdv = ExpectedInfo::read_with_extension(&mut p, "xdv");
46-
let expected_fot = ExpectedInfo::read_with_extension(&mut p, "fot");
44+
let expected_log = ExpectedFile::read_with_extension(&mut p, "log");
45+
let expected_xdv = ExpectedFile::read_with_extension(&mut p, "xdv");
46+
let expected_fot = ExpectedFile::read_with_extension(&mut p, "fot");
4747
p.set_file_name("tripos");
48-
let expected_os = ExpectedInfo::read_with_extension(&mut p, "tex");
48+
let expected_os = ExpectedFile::read_with_extension(&mut p, "tex");
4949

5050
// MemoryIo layer that will accept the outputs. Save `files` since the
5151
// engine consumes `mem`.
@@ -81,10 +81,12 @@ fn trip_test() {
8181

8282
// Check that outputs match expectations.
8383
let files = &*mem.files.borrow();
84-
expected_log.test_from_collection(files);
85-
expected_xdv.test_from_collection(files);
86-
expected_os.test_from_collection(files);
87-
expected_fot.test_data(&files.get("").unwrap().data);
84+
Expected::new()
85+
.file(expected_log.collection(files))
86+
.file(expected_xdv.collection(files))
87+
.file(expected_os.collection(files))
88+
.file(expected_fot.data(&files.get("").unwrap().data))
89+
.finish();
8890
}
8991

9092
#[test]
@@ -102,10 +104,10 @@ fn etrip_test() {
102104
let mut tfm = SingleInputFileIo::new(&p);
103105

104106
// Read in the expected outputs.
105-
let expected_log = ExpectedInfo::read_with_extension(&mut p, "log");
106-
let expected_xdv = ExpectedInfo::read_with_extension(&mut p, "xdv");
107-
let expected_fot = ExpectedInfo::read_with_extension(&mut p, "fot");
108-
let expected_out = ExpectedInfo::read_with_extension(&mut p, "out");
107+
let expected_log = ExpectedFile::read_with_extension(&mut p, "log");
108+
let expected_xdv = ExpectedFile::read_with_extension(&mut p, "xdv");
109+
let expected_fot = ExpectedFile::read_with_extension(&mut p, "fot");
110+
let expected_out = ExpectedFile::read_with_extension(&mut p, "out");
109111

110112
// MemoryIo layer that will accept the outputs. Save `files` since the
111113
// engine consumes `mem`.
@@ -142,8 +144,10 @@ fn etrip_test() {
142144

143145
// Check that outputs match expectations.
144146
let files = &*files.borrow();
145-
expected_log.test_from_collection(files);
146-
expected_xdv.test_from_collection(files);
147-
expected_out.test_from_collection(files);
148-
expected_fot.test_data(&files.get("").unwrap().data);
147+
Expected::new()
148+
.file(expected_log.collection(files))
149+
.file(expected_xdv.collection(files))
150+
.file(expected_out.collection(files))
151+
.file(expected_fot.data(&files.get("").unwrap().data))
152+
.finish();
149153
}

0 commit comments

Comments
 (0)