Skip to content

Commit 5bb712a

Browse files
authored
test: improve test reliability and ease of use
This disables automatic filesystem-based test inclusion, opting for manual inclusion so the guides, which rely on additional features, can skip running unless all their required features are enabled. Refs: #450
1 parent 11b6a8d commit 5bb712a

File tree

8 files changed

+51
-26
lines changed

8 files changed

+51
-26
lines changed

Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ authors = ["David Cole <[email protected]>"]
1010
edition = "2021"
1111
categories = ["api-bindings"]
1212
exclude = ["/.github", "/.crates"]
13+
autotests = false
1314

1415
[dependencies]
1516
bitflags = "2"
@@ -39,6 +40,7 @@ zip = "4.0"
3940
[features]
4041
closure = []
4142
embed = []
43+
anyhow = ["dep:anyhow"]
4244

4345
[workspace]
4446
members = [
@@ -56,3 +58,16 @@ missing_docs = "warn"
5658
[[example]]
5759
name = "hello_world"
5860
crate-type = ["cdylib"]
61+
62+
[[test]]
63+
name = "guide_tests"
64+
path = "tests/guide.rs"
65+
required-features = ["embed", "closure", "anyhow"]
66+
67+
[[test]]
68+
name = "module_tests"
69+
path = "tests/module.rs"
70+
71+
[[test]]
72+
name = "sapi_tests"
73+
path = "tests/sapi.rs"

guide/src/advanced/async_impl.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ This allows full compatibility with [amphp](https://amphp.org), [PSL](https://gi
1818

1919
Make sure to require [php-tokio](https://github.com/danog/php-tokio) as a dependency before proceeding.
2020

21-
```rust,ignore
21+
<!-- Must ignore because of circular dependency with php_tokio. Otherwise, this _should_ work. -->
22+
```rust,no_run,ignore
23+
# extern crate ext_php_rs;
24+
# extern crate php_tokio;
25+
# extern crate reqwest;
2226
use ext_php_rs::prelude::*;
2327
use php_tokio::{php_async_impl, EventLoop};
2428

guide/src/macros/classes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub fn get_module(module: ModuleBuilder) -> ModuleBuilder {
121121
To implement an interface, use `#[php(implements(ce = ce_fn, stub = "InterfaceName")]` where `ce_fn` is an function returning a `ClassEntry`.
122122
The following example implements [`ArrayAccess`](https://www.php.net/manual/en/class.arrayaccess.php):
123123

124-
````rust,no_run
124+
```rust,no_run
125125
# #![cfg_attr(windows, feature(abi_vectorcall))]
126126
# extern crate ext_php_rs;
127127
use ext_php_rs::{

guide/src/types/functions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Functions & methods
22

3-
PHP functions and methods are represented by the `Function` struct.
3+
PHP functions and methods are represented by the `Function` struct.
44

5-
You can use the `try_from_function` and `try_from_method` methods to obtain a Function struct corresponding to the passed function or static method name.
6-
It's heavily recommended you reuse returned `Function` objects, to avoid the overhead of looking up the function/method name.
5+
You can use the `try_from_function` and `try_from_method` methods to obtain a Function struct corresponding to the passed function or static method name.
6+
It's heavily recommended you reuse returned `Function` objects, to avoid the overhead of looking up the function/method name.
77

88
```rust,no_run
99
# #![cfg_attr(windows, feature(abi_vectorcall))]

guide/src/types/iterable.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
|---------------|----------------|-----------------| ---------------- |----------------------------------|
77
| Yes | No | No | No | `ZendHashTable` or `ZendIterator` |
88

9-
Converting from a zval to a `Iterable` is valid when the value is either an array or an object
9+
Converting from a zval to a `Iterable` is valid when the value is either an array or an object
1010
that implements the `Traversable` interface. This means that any value that can be used in a
1111
`foreach` loop can be converted into a `Iterable`.
1212

guide/src/types/iterator.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
|---------------| -------------- |-----------------| ---------------- | ------------------ |
77
| No | Yes | No | No | `ZendIterator` |
88

9-
Converting from a zval to a `ZendIterator` is valid when there is an associated iterator to
10-
the variable. This means that any value, at the exception of an `array`, that can be used in
9+
Converting from a zval to a `ZendIterator` is valid when there is an associated iterator to
10+
the variable. This means that any value, at the exception of an `array`, that can be used in
1111
a `foreach` loop can be converted into a `ZendIterator`. As an example, a `Generator` can be
1212
used but also a the result of a `query` call with `PDO`.
1313

14-
If you want a more universal `iterable` type that also supports arrays, see [Iterable](./iterable.md).
14+
If you want a more universal `iterable` type that also supports arrays, see [Iterable](./iterable.md).
1515

1616
## Rust example
1717

src/args.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ impl<'a, 'b> ArgParser<'a, 'b> {
306306
#[cfg(test)]
307307
mod tests {
308308
#![allow(clippy::unwrap_used)]
309+
#[cfg(feature = "embed")]
310+
use crate::embed::Embed;
309311

310312
use super::*;
311313

@@ -427,12 +429,14 @@ mod tests {
427429
#[test]
428430
#[cfg(feature = "embed")]
429431
fn test_try_call_not_callable() {
430-
let mut arg = Arg::new("test", DataType::Long);
431-
let mut zval = Zval::from(42);
432-
arg.zval = Some(&mut zval);
433-
434-
let result = arg.try_call(vec![]);
435-
assert!(result.is_err());
432+
Embed::run(|| {
433+
let mut arg = Arg::new("test", DataType::Long);
434+
let mut zval = Zval::from(42);
435+
arg.zval = Some(&mut zval);
436+
437+
let result = arg.try_call(vec![]);
438+
assert!(result.is_err());
439+
});
436440
}
437441

438442
// TODO: Test the callable case

src/zend/try_catch.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,22 @@ mod tests {
190190

191191
#[test]
192192
fn test_memory_leak() {
193-
let mut ptr = null_mut();
193+
Embed::run(|| {
194+
let mut ptr = null_mut();
194195

195-
let _ = try_catch(|| {
196-
let mut result = "foo".to_string();
197-
ptr = &mut result;
196+
let _ = try_catch(|| {
197+
let mut result = "foo".to_string();
198+
ptr = &mut result;
198199

199-
unsafe {
200-
bailout();
201-
}
202-
});
200+
unsafe {
201+
bailout();
202+
}
203+
});
203204

204-
// Check that the string is never released
205-
let result = unsafe { &*ptr as &str };
205+
// Check that the string is never released
206+
let result = unsafe { &*ptr as &str };
206207

207-
assert_eq!(result, "foo");
208+
assert_eq!(result, "foo");
209+
});
208210
}
209211
}

0 commit comments

Comments
 (0)