From 28d644572c79e318944577388d0bc14826c341e4 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 22 Sep 2026 13:18:21 -0300 Subject: [PATCH] test(docs): run doctest on CI, make sure doctests pass (#3620) * test(docs): run doctest on CI, make sure doctests pass * no_run on dialog doctests [skip ci] --- .github/workflows/test-rust.yml | 10 ++++ plugins/cli/Cargo.toml | 3 ++ plugins/dialog/src/lib.rs | 34 ++++++------ plugins/fs/Cargo.toml | 3 ++ plugins/fs/src/lib.rs | 94 ++++++++++++++++++++++++--------- plugins/notification/Cargo.toml | 3 ++ plugins/opener/Cargo.toml | 3 ++ plugins/shell/Cargo.toml | 3 ++ plugins/updater/Cargo.toml | 3 ++ 9 files changed, 115 insertions(+), 41 deletions(-) diff --git a/.github/workflows/test-rust.yml b/.github/workflows/test-rust.yml index bfd84bf0d..7fda7d355 100644 --- a/.github/workflows/test-rust.yml +++ b/.github/workflows/test-rust.yml @@ -299,3 +299,13 @@ jobs: - name: test ${{ matrix.package }} if: ${{ matrix.package == 'tauri-plugin-http' || matrix.package == 'tauri-plugin-dialog' }} run: ${{ matrix.platform.runner }} ${{ matrix.platform.command }} --package ${{ matrix.package }} --target ${{ matrix.platform.target }} --all-targets + + # `--all-targets` above does not include doc tests, so they are run separately. + # Only on the platforms we actually test on, since cargo skips doc tests when cross compiling. + - name: doc test ${{ matrix.package }} + if: ${{ matrix.platform.command == 'test' && matrix.package != 'tauri-plugin-http' && matrix.package != 'tauri-plugin-dialog' }} + run: ${{ matrix.platform.runner }} test --doc --package ${{ matrix.package }} --target ${{ matrix.platform.target }} --all-features + + - name: doc test ${{ matrix.package }} + if: ${{ matrix.platform.command == 'test' && (matrix.package == 'tauri-plugin-http' || matrix.package == 'tauri-plugin-dialog') }} + run: ${{ matrix.platform.runner }} test --doc --package ${{ matrix.package }} --target ${{ matrix.platform.target }} diff --git a/plugins/cli/Cargo.toml b/plugins/cli/Cargo.toml index 5df36b185..871597211 100644 --- a/plugins/cli/Cargo.toml +++ b/plugins/cli/Cargo.toml @@ -27,6 +27,9 @@ ios = { level = "none", notes = "" } [build-dependencies] tauri-plugin = { workspace = true, features = ["build"] } +[dev-dependencies] +tauri = { workspace = true, features = ["wry"] } + [dependencies] serde = { workspace = true } serde_json = { workspace = true } diff --git a/plugins/dialog/src/lib.rs b/plugins/dialog/src/lib.rs index 024df8ce8..0e092af0a 100644 --- a/plugins/dialog/src/lib.rs +++ b/plugins/dialog/src/lib.rs @@ -113,7 +113,7 @@ impl Dialog { /// /// - Message dialog: /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// /// tauri::Builder::default() @@ -130,14 +130,14 @@ impl Dialog { /// /// - Ask dialog: /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::{DialogExt, MessageDialogButtons}; /// /// tauri::Builder::default() /// .setup(|app| { /// app.dialog() /// .message("Are you sure?") - /// .buttons(MessageDialogButtons::OkCancelCustom("Yes", "No")) + /// .buttons(MessageDialogButtons::OkCancelCustom("Yes".to_string(), "No".to_string())) /// .show(|yes| { /// println!("user said {}", if yes { "yes" } else { "no" }); /// }); @@ -147,7 +147,7 @@ impl Dialog { /// /// - Message dialog with OK button: /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::{DialogExt, MessageDialogButtons}; /// /// tauri::Builder::default() @@ -169,7 +169,7 @@ impl Dialog { /// To block the current thread until the user acted on the dialog, you can use `blocking_show`, /// but note that it cannot be executed on the main thread as it will freeze your application. /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::{DialogExt, MessageDialogButtons}; /// /// tauri::Builder::default() @@ -178,7 +178,7 @@ impl Dialog { /// std::thread::spawn(move || { /// let yes = handle.dialog() /// .message("Are you sure?") - /// .buttons(MessageDialogButtons::OkCancelCustom("Yes", "No")) + /// .buttons(MessageDialogButtons::OkCancelCustom("Yes".to_string(), "No".to_string())) /// .blocking_show(); /// }); /// @@ -532,7 +532,7 @@ impl FileDialogBuilder { /// /// # Examples /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// tauri::Builder::default() /// .setup(|app| { @@ -559,7 +559,7 @@ impl FileDialogBuilder { /// The file paths cannot be read directly on Android as they are behind a content URI. /// The recommended way to read the files is using the [`fs`](https://v2.tauri.app/plugin/file-system/) plugin: /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// use tauri_plugin_fs::FsExt; /// tauri::Builder::default() @@ -580,7 +580,7 @@ impl FileDialogBuilder { /// /// # Examples /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// tauri::Builder::default() /// .setup(|app| { @@ -604,7 +604,7 @@ impl FileDialogBuilder { /// /// # Examples /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// tauri::Builder::default() /// .setup(|app| { @@ -629,7 +629,7 @@ impl FileDialogBuilder { /// /// # Examples /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// tauri::Builder::default() /// .setup(|app| { @@ -654,7 +654,7 @@ impl FileDialogBuilder { /// /// # Examples /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// tauri::Builder::default() /// .setup(|app| { @@ -681,7 +681,7 @@ impl FileDialogBuilder { /// /// # Examples /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// #[tauri::command] /// async fn my_command(app: tauri::AppHandle) { @@ -703,7 +703,7 @@ impl FileDialogBuilder { /// /// # Examples /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// #[tauri::command] /// async fn my_command(app: tauri::AppHandle) { @@ -725,7 +725,7 @@ impl FileDialogBuilder { /// /// # Examples /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// #[tauri::command] /// async fn my_command(app: tauri::AppHandle) { @@ -748,7 +748,7 @@ impl FileDialogBuilder { /// /// # Examples /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// #[tauri::command] /// async fn my_command(app: tauri::AppHandle) { @@ -771,7 +771,7 @@ impl FileDialogBuilder { /// /// # Examples /// - /// ``` + /// ```no_run /// use tauri_plugin_dialog::DialogExt; /// #[tauri::command] /// async fn my_command(app: tauri::AppHandle) { diff --git a/plugins/fs/Cargo.toml b/plugins/fs/Cargo.toml index 0fb01028d..74f7f6ac9 100644 --- a/plugins/fs/Cargo.toml +++ b/plugins/fs/Cargo.toml @@ -30,6 +30,9 @@ serde = { workspace = true } toml = "1.0" tauri-utils = { workspace = true } +[dev-dependencies] +tauri = { workspace = true, features = ["wry"] } + [dependencies] serde = { workspace = true } serde_json = { workspace = true } diff --git a/plugins/fs/src/lib.rs b/plugins/fs/src/lib.rs index 9b37604ba..cac582bb4 100644 --- a/plugins/fs/src/lib.rs +++ b/plugins/fs/src/lib.rs @@ -125,11 +125,17 @@ impl OpenOptions { /// /// # Examples /// - /// ```no_run - /// use tauri_plugin_fs::OpenOptions; + /// ```rust,no_run + /// use std::path::Path; + /// use tauri_plugin_fs::{FsExt, OpenOptions}; /// - /// let mut options = OpenOptions::new(); - /// let file = options.read(true).open("foo.txt"); + /// tauri::Builder::default() + /// .setup(|app| { + /// let mut options = OpenOptions::new(); + /// options.read(true); + /// let file = app.fs().open(Path::new("foo.txt"), options)?; + /// Ok(()) + /// }); /// ``` #[must_use] pub fn new() -> Self { @@ -143,10 +149,17 @@ impl OpenOptions { /// /// # Examples /// - /// ```no_run - /// use tauri_plugin_fs::OpenOptions; + /// ```rust,no_run + /// use std::path::Path; + /// use tauri_plugin_fs::{FsExt, OpenOptions}; /// - /// let file = OpenOptions::new().read(true).open("foo.txt"); + /// tauri::Builder::default() + /// .setup(|app| { + /// let mut options = OpenOptions::new(); + /// options.read(true); + /// let file = app.fs().open(Path::new("foo.txt"), options)?; + /// Ok(()) + /// }); /// ``` pub fn read(&mut self, read: bool) -> &mut Self { self.read = read; @@ -163,10 +176,17 @@ impl OpenOptions { /// /// # Examples /// - /// ```no_run - /// use tauri_plugin_fs::OpenOptions; + /// ```rust,no_run + /// use std::path::Path; + /// use tauri_plugin_fs::{FsExt, OpenOptions}; /// - /// let file = OpenOptions::new().write(true).open("foo.txt"); + /// tauri::Builder::default() + /// .setup(|app| { + /// let mut options = OpenOptions::new(); + /// options.write(true); + /// let file = app.fs().open(Path::new("foo.txt"), options)?; + /// Ok(()) + /// }); /// ``` pub fn write(&mut self, write: bool) -> &mut Self { self.write = write; @@ -217,10 +237,17 @@ impl OpenOptions { /// /// # Examples /// - /// ```no_run - /// use tauri_plugin_fs::OpenOptions; + /// ```rust,no_run + /// use std::path::Path; + /// use tauri_plugin_fs::{FsExt, OpenOptions}; /// - /// let file = OpenOptions::new().append(true).open("foo.txt"); + /// tauri::Builder::default() + /// .setup(|app| { + /// let mut options = OpenOptions::new(); + /// options.append(true); + /// let file = app.fs().open(Path::new("foo.txt"), options)?; + /// Ok(()) + /// }); /// ``` pub fn append(&mut self, append: bool) -> &mut Self { self.append = append; @@ -236,10 +263,17 @@ impl OpenOptions { /// /// # Examples /// - /// ```no_run - /// use tauri_plugin_fs::OpenOptions; + /// ```rust,no_run + /// use std::path::Path; + /// use tauri_plugin_fs::{FsExt, OpenOptions}; /// - /// let file = OpenOptions::new().write(true).truncate(true).open("foo.txt"); + /// tauri::Builder::default() + /// .setup(|app| { + /// let mut options = OpenOptions::new(); + /// options.write(true).truncate(true); + /// let file = app.fs().open(Path::new("foo.txt"), options)?; + /// Ok(()) + /// }); /// ``` pub fn truncate(&mut self, truncate: bool) -> &mut Self { self.truncate = truncate; @@ -254,10 +288,17 @@ impl OpenOptions { /// /// # Examples /// - /// ```no_run - /// use tauri_plugin_fs::OpenOptions; + /// ```rust,no_run + /// use std::path::Path; + /// use tauri_plugin_fs::{FsExt, OpenOptions}; /// - /// let file = OpenOptions::new().write(true).create(true).open("foo.txt"); + /// tauri::Builder::default() + /// .setup(|app| { + /// let mut options = OpenOptions::new(); + /// options.write(true).create(true); + /// let file = app.fs().open(Path::new("foo.txt"), options)?; + /// Ok(()) + /// }); /// ``` pub fn create(&mut self, create: bool) -> &mut Self { self.create = create; @@ -288,12 +329,17 @@ impl OpenOptions { /// /// # Examples /// - /// ```no_run - /// use tauri_plugin_fs::OpenOptions; + /// ```rust,no_run + /// use std::path::Path; + /// use tauri_plugin_fs::{FsExt, OpenOptions}; /// - /// let file = OpenOptions::new().write(true) - /// .create_new(true) - /// .open("foo.txt"); + /// tauri::Builder::default() + /// .setup(|app| { + /// let mut options = OpenOptions::new(); + /// options.write(true).create_new(true); + /// let file = app.fs().open(Path::new("foo.txt"), options)?; + /// Ok(()) + /// }); /// ``` pub fn create_new(&mut self, create_new: bool) -> &mut Self { self.create_new = create_new; diff --git a/plugins/notification/Cargo.toml b/plugins/notification/Cargo.toml index 1034932fa..b306b5fd5 100644 --- a/plugins/notification/Cargo.toml +++ b/plugins/notification/Cargo.toml @@ -30,6 +30,9 @@ ios = { level = "full", notes = "" } [build-dependencies] tauri-plugin = { workspace = true, features = ["build"] } +[dev-dependencies] +tauri = { workspace = true, features = ["wry"] } + [dependencies] serde = { workspace = true } serde_json = { workspace = true } diff --git a/plugins/opener/Cargo.toml b/plugins/opener/Cargo.toml index 553da64d1..e17b53093 100644 --- a/plugins/opener/Cargo.toml +++ b/plugins/opener/Cargo.toml @@ -26,6 +26,9 @@ tauri-plugin = { workspace = true, features = ["build"] } schemars = { workspace = true } serde = { workspace = true } +[dev-dependencies] +tauri = { workspace = true, features = ["wry"] } + [dependencies] serde = { workspace = true } serde_json = { workspace = true } diff --git a/plugins/shell/Cargo.toml b/plugins/shell/Cargo.toml index 5b51d64a2..105ea5f1e 100644 --- a/plugins/shell/Cargo.toml +++ b/plugins/shell/Cargo.toml @@ -29,6 +29,9 @@ tauri-plugin = { workspace = true, features = ["build"] } schemars = { workspace = true } serde = { workspace = true } +[dev-dependencies] +tauri = { workspace = true, features = ["wry"] } + [dependencies] serde = { workspace = true } serde_json = { workspace = true } diff --git a/plugins/updater/Cargo.toml b/plugins/updater/Cargo.toml index 01d777aa9..b14910e14 100644 --- a/plugins/updater/Cargo.toml +++ b/plugins/updater/Cargo.toml @@ -31,6 +31,9 @@ ios = { level = "none", notes = "" } [build-dependencies] tauri-plugin = { workspace = true, features = ["build"] } +[dev-dependencies] +tauri = { workspace = true, features = ["wry"] } + [dependencies] tauri = { workspace = true } serde = { workspace = true }