mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
engine: file.print.page's printer route is reachable from a test
SonarCloud's new-code coverage was 50%: CI sets PHOTOCRAFT_NO_PRINT for every test, so nothing ran the line after the new off switch. The command now passes printing_disabled() to page_of_printer, and disabled_printing_never_spools also asks it with printing on: off Windows the GDI route answers Unsupported without asking a driver, so the refusal is the route's, not the switch's. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
f996f2fc93
commit
be8c01ebee
2 files changed
+14
-1
No files matched your search
@@ -1424,6 +1424,12 @@ fn printers(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
}
|
||||
|
||||
fn printer_page(_: &mut Session, p: &Value) -> Result<Value> {
|
||||
page_of_printer(p, printing_disabled())
|
||||
}
|
||||
|
||||
/// `file.print.page` with printing turned off or not (`disabled`). A test passes `false` to reach the printer route,
|
||||
/// which `printing_disabled` never is once a test of the process or CI's `PHOTOCRAFT_NO_PRINT` turned it off.
|
||||
fn page_of_printer(p: &Value, disabled: bool) -> Result<Value> {
|
||||
// Checked before the printer, so a bad value is the error whether or not a printer answers.
|
||||
let landscape = match p.get("orientation").filter(|v| !v.is_null()) {
|
||||
None => None,
|
||||
@@ -1436,7 +1442,7 @@ fn printer_page(_: &mut Session, p: &Value) -> Result<Value> {
|
||||
let mut settings = printer_settings(p)?;
|
||||
// A driver query is still a call into a printer driver, which can hang (and holds SPOOLER
|
||||
// while it does), so a process that turned printing off asks no driver here either.
|
||||
if printing_disabled() {
|
||||
if disabled {
|
||||
return Err(other("printing is disabled in this process (disable_printing or PHOTOCRAFT_NO_PRINT); file.print.page asks no printer driver"));
|
||||
}
|
||||
let printer = printer_name(p)?;
|
||||
|
||||
@@ -789,6 +789,13 @@ fn disabled_printing_never_spools() {
|
||||
// Bad values are still the error they were, before the check.
|
||||
let e = s.execute("file.print.page", json!({"orientation": "sideways"})).unwrap_err().to_string();
|
||||
assert!(e.contains("orientation"), "{e}");
|
||||
// With printing on the command goes past the switch to the printer route: off Windows the GDI route has no
|
||||
// printers, so a named printer's page is the route's own refusal (no driver is asked there).
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
let e = super::page_of_printer(&json!({"printer": "Anything"}), false).unwrap_err().to_string();
|
||||
assert!(!e.contains("printing is disabled"), "{e}");
|
||||
}
|
||||
// A dry run still renders and reports the command it would have run.
|
||||
let r = s.execute("file.print", json!({"dryRun": true})).unwrap();
|
||||
assert_eq!(r["sent"], false);
|
||||
|
||||
Reference in new issue
Block a user