Repository: gtk-rs/gtk3-rs (language: rust)

Issue:
gtk3-macros doctests are `compile_fail`
See https://github.com/gtk-rs/gtk-rs/pull/466#discussion_r615895426

Is this intentional? @bilelmoussaoui @BrainBlasted ?


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml
index 488df4c8aa53..8b546ee8ceca 100644
--- a/.github/workflows/CI.yml
+++ b/.github/workflows/CI.yml
@@ -104,6 +104,11 @@ jobs:
         with:
           toolchain: ${{ matrix.rust }}
           override: true
+      # gtk3-macros
+      - name: "gtk3-macros: tests"
+        run: xvfb-run --auto-servernum cargo test --manifest-path gtk3-macros/Cargo.toml
+      - name: "gtk3-macros: build"
+        run: cargo build --manifest-path gtk3-macros/Cargo.toml
       # examples
       - name: "examples"
         run: cargo build --manifest-path examples/Cargo.toml --bins --examples --all-features
diff --git a/gtk3-macros/Cargo.toml b/gtk3-macros/Cargo.toml
index db4ec74c5d91..61fdf980b4ee 100644
--- a/gtk3-macros/Cargo.toml
+++ b/gtk3-macros/Cargo.toml
@@ -12,6 +12,7 @@ keywords = ["gtk", "gtk3", "gtk-rs", "gnome", "GUI"]
 repository = "https://github.com/gtk-rs/gtk3-rs"
 exclude = [
     "gir-files/*",
+    "src/composite_template.ui"
 ]
 include = ["../LICENSE"]
 rust-version = "1.56"
@@ -27,3 +28,6 @@ proc-macro2 = "1.0"
 quote = "1.0"
 syn = { version = "1.0", default-features = false, features = ["full"] }
 proc-macro-crate = "1.0"
+
+[dev-dependencies]
+gtk = { path = "../gtk" }
diff --git a/gtk3-macros/src/composite_template.ui b/gtk3-macros/src/composite_template.ui
new file mode 100644
index 000000000000..9377ed4faf3e
--- /dev/null
+++ b/gtk3-macros/src/composite_template.ui
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="MyWidget" parent="GtkBox">
+    <child>
+        <object class="GtkLabel" id="label">
+            <property name="label">Some label</property>
+        </object>
+        <object class="GtkButton" id="my_button">
+            <property name="label">Some button</property>
+        </object>
+    </child>
+  </template>
+</interface>
+
diff --git a/gtk3-macros/src/lib.rs b/gtk3-macros/src/lib.rs
index ac5677e26f61..90765a4e9b39 100644
--- a/gtk3-macros/src/lib.rs
+++ b/gtk3-macros/src/lib.rs
@@ -21,38 +21,60 @@ use syn::{parse_macro_input, DeriveInput};
 /// Specify that `MyWidget` is using a composite template and load the
 /// template file the `composite_template.ui` file.
 ///
-/// ```compile_fail
-/// use gtk::prelude::*;
-/// use gtk::CompositeTemplate;
-///
-/// #[derive(Debug, Default, CompositeTemplate)]
-/// #[template(file = "composite_template.ui")]
-/// struct MyWidget {
-///     #[template_child]
-///     pub label: TemplateChild<gtk::Label>,
-/// }
-/// ```
-///
 /// Then, in the `ObjectSubclass` implementation you will need to call
 /// `bind_template` in the `class_init` function, and `init_template` in
 /// `instance_init` function.
 ///
+/// ```no_run
+/// use gtk::prelude::*;
+/// use gtk::glib;
+/// use gtk::subclass::prelude::*;
+///
+/// mod imp {
+///     use gtk::prelude::*;
+///     use gtk::glib;
+///     use gtk::subclass::prelude::*;
 ///
-/// ```compile_fail
-/// #[glib::object_subclass]
-/// impl ObjectSubclass for MyWidget {
-///        const NAME: &'static str = "MyWidget";
-///        type Type = super::MyWidget;
-///        type ParentType = gtk::Widget;
+///     #[derive(Debug, Default, gtk::CompositeTemplate)]
+///     #[template(file = "composite_template.ui")]
+///     pub struct MyWidget {
+///         #[template_child]
+///         pub label: TemplateChild<gtk::Label>,
+///         #[template_child(id = "my_button_id")]
+///         pub button: TemplateChild<gtk::Button>,
+///     }
 ///
-///        fn class_init(klass: &mut Self::Class) {
-///            Self::bind_template(klass);
-///        }
+///     #[glib::object_subclass]
+///     impl ObjectSubclass for MyWidget {
+///         const NAME: &'static str = "MyWidget";
+///         type Type = super::MyWidget;
+///         type ParentType = gtk::Box;
 ///
-///        fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
-///            obj.init_template();
-///        }
-///    }
+///         fn class_init(klass: &mut Self::Class) {
+///             Self::bind_template(klass);
+///         }
+///
+///         fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
+///             obj.init_template();
+///         }
+///     }
+///
+///     impl ObjectImpl for MyWidget {}
+///     impl WidgetImpl for MyWidget {}
+///     impl ContainerImpl for MyWidget {}
+///     impl BoxImpl for MyWidget {}
+/// }
+///
+/// glib::wrapper! {
+///     pub struct MyWidget(ObjectSubclass<imp::MyWidget>) @extends gtk::Widget, gtk::Container, gtk::Box;
+/// }
+///
+/// impl MyWidget {
+///     pub fn new() -> Self {
+///         glib::Object::new(&[]).expect("Failed to create an instance of MyWidget")
+///     }
+/// }
+/// # fn main() {}
 /// ```
 #[proc_macro_derive(CompositeTemplate, attributes(template, template_child))]
 #[proc_macro_error]


Test patch: