Skip to content

Commit

Permalink
blueprint: Add compilation error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
yuraiz committed Jan 16, 2023
1 parent 18c1154 commit 1d8155d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gtk4-macros/src/blueprint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use anyhow::Result;
use anyhow::{bail, Result};
use std::io::{Read, Write};
use std::process::{Command, Stdio};

Expand All @@ -20,5 +20,9 @@ pub(crate) fn compile_blueprint(blueprint: &[u8]) -> Result<String> {
let mut buf = String::new();
compiler.stdout.unwrap().read_to_string(&mut buf)?;

if !buf.starts_with("<") {
bail!(buf);
}

Ok(buf)
}
3 changes: 3 additions & 0 deletions gtk4-macros/tests/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ fn template_child_without_attribute() {
let _: MyWidget3 = glib::Object::new(&[]);
}

#[cfg(target_os = "linux")]
mod imp4 {
use super::*;

Expand Down Expand Up @@ -245,11 +246,13 @@ mod imp4 {
impl WidgetImpl for MyWidget4 {}
}

#[cfg(target_os = "linux")]
glib::wrapper! {
pub struct MyWidget4(ObjectSubclass<imp4::MyWidget4>) @extends gtk::Widget;
}

#[gtk::test]
#[cfg(target_os = "linux")]
fn blueprint_template() {
let _: MyWidget4 = glib::Object::new(&[]);
}

0 comments on commit 1d8155d

Please sign in to comment.