Skip to content

Commit f34b5c8

Browse files
committed
Test --web-bundle with refactored config.rs
`config.rs` is refactored such that `test-bundle://` is interpreted as the valid web-bundle for offline testing.
1 parent c64e524 commit f34b5c8

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

src/config.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ pub fn is_config_test_mode_activated() -> bool {
4444
CONFIG_TEST_MODE_ACTIVATED.load(Ordering::SeqCst)
4545
}
4646

47+
pub fn is_test_bundle_wanted(web_bundle: Option<String>) -> bool {
48+
if !is_config_test_mode_activated() {
49+
return false;
50+
}
51+
match web_bundle {
52+
None => true,
53+
Some(x) if x.contains("test-bundle://") => true,
54+
_ => false,
55+
}
56+
}
57+
58+
pub fn maybe_return_test_bundle(web_bundle: Option<String>) -> Result<Box<dyn Bundle>> {
59+
if is_test_bundle_wanted(web_bundle) {
60+
Ok(Box::<crate::test_util::TestBundle>::default())
61+
} else {
62+
Err(ErrorKind::Msg("not asking for the default test bundle".to_owned()).into())
63+
}
64+
}
65+
4766
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
4867
pub struct PersistentConfig {
4968
default_bundles: Vec<BundleInfo>,
@@ -122,6 +141,10 @@ impl PersistentConfig {
122141
custom_cache_root: Option<&Path>,
123142
status: &mut dyn StatusBackend,
124143
) -> Result<Box<dyn Bundle>> {
144+
if let Ok(test_bundle) = maybe_return_test_bundle(Some(url.to_owned())) {
145+
return Ok(test_bundle);
146+
}
147+
125148
let mut cache = if let Some(root) = custom_cache_root {
126149
Cache::get_for_custom_directory(root)
127150
} else {
@@ -156,9 +179,8 @@ impl PersistentConfig {
156179
) -> Result<Box<dyn Bundle>> {
157180
use std::io;
158181

159-
if CONFIG_TEST_MODE_ACTIVATED.load(Ordering::SeqCst) {
160-
let bundle = crate::test_util::TestBundle::default();
161-
return Ok(Box::new(bundle));
182+
if let Ok(test_bundle) = maybe_return_test_bundle(None) {
183+
return Ok(test_bundle);
162184
}
163185

164186
if self.default_bundles.len() != 1 {
@@ -183,7 +205,7 @@ impl PersistentConfig {
183205
}
184206

185207
pub fn format_cache_path(&self) -> Result<PathBuf> {
186-
if CONFIG_TEST_MODE_ACTIVATED.load(Ordering::SeqCst) {
208+
if is_config_test_mode_activated() {
187209
Ok(crate::test_util::test_path(&[]))
188210
} else {
189211
Ok(app_dirs::ensure_user_cache_dir("formats")?)

tests/executable.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,37 @@ fn stdin_content() {
636636
success_or_panic(&output);
637637
}
638638

639+
#[test]
640+
fn web_bundle_flag() {
641+
let filename = "subdirectory/content/1.tex";
642+
let fmt_arg: &str = &get_plain_format_arg();
643+
let tempdir = setup_and_copy_files(&[filename]);
644+
let temppath = tempdir.path().to_owned();
645+
646+
let arg_bad_bundle = ["--web-bundle", "bad-bundle"];
647+
let arg_good_bundle = ["--web-bundle", "test-bundle://"];
648+
649+
// test with a bad bundle
650+
let output = run_tectonic(
651+
&temppath,
652+
&[&arg_bad_bundle[..], &[fmt_arg, filename]].concat(),
653+
);
654+
error_or_panic(&output);
655+
656+
// test with a good bundle
657+
let valid_args: Vec<Vec<&str>> = vec![
658+
// different positions
659+
[&arg_good_bundle[..], &[fmt_arg, filename]].concat(),
660+
[&[fmt_arg], &arg_good_bundle[..], &[filename]].concat(),
661+
[&[fmt_arg], &[filename], &arg_good_bundle[..]].concat(),
662+
];
663+
664+
for args in valid_args {
665+
let output = run_tectonic(&temppath, &args);
666+
success_or_panic(&output);
667+
}
668+
}
669+
639670
#[cfg(feature = "serialization")]
640671
#[test]
641672
fn v2_build_basic() {

0 commit comments

Comments
 (0)