Skip to content

Commit 6352e0c

Browse files
committed
Add integraton values return tests.
1 parent e69a4b5 commit 6352e0c

File tree

7 files changed

+64
-6
lines changed

7 files changed

+64
-6
lines changed

tests/integration/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "values"
2+
name = "integration"
33
version = "0.1.0"
44
authors = ["jmjoy <[email protected]>"]
55
edition = "2018"

tests/integration/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn get_module() -> Module {
1212
env!("CARGO_PKG_AUTHORS"),
1313
);
1414

15-
// ...
15+
values::integrate(&mut module);
1616

1717
module
1818
}

tests/integration/src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use phper::cmd::make;
2+
3+
fn main() {
4+
make();
5+
}

tests/integration/src/values.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1+
use phper::{modules::Module, values::Val};
12

3+
pub fn integrate(module: &mut Module) {
4+
integrate_returns(module);
5+
}
6+
7+
fn integrate_returns(module: &mut Module) {
8+
module.add_function(
9+
"integration_values_return_null",
10+
integration_values_return_null,
11+
vec![],
12+
);
13+
module.add_function(
14+
"integration_values_return_i32",
15+
integration_values_return_i32,
16+
vec![],
17+
);
18+
module.add_function(
19+
"integration_values_return_i64",
20+
integration_values_return_i64,
21+
vec![],
22+
);
23+
}
24+
25+
fn integration_values_return_null(_: &mut [Val]) {}
26+
27+
fn integration_values_return_i32(_: &mut [Val]) -> i32 {
28+
32
29+
}
30+
31+
fn integration_values_return_i64(_: &mut [Val]) -> i64 {
32+
64
33+
}

tests/integration/tests/integration.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,12 @@ use phper_test::test_php_scripts;
22
use std::{env, path::Path};
33

44
#[test]
5-
fn test_php() {}
5+
fn test_php() {
6+
test_php_scripts(
7+
env!("CARGO_BIN_EXE_integration"),
8+
&[&Path::new(env!("CARGO_MANIFEST_DIR"))
9+
.join("tests")
10+
.join("php")
11+
.join("values.php")],
12+
);
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
ini_set("display_errors", "On");
4+
ini_set("display_startup_errors", "On");
5+
error_reporting(E_ALL);
6+
7+
function assert_eq($left, $right) {
8+
if ($left !== $right) {
9+
throw new Exception(sprintf("left != right,\n left: %s,\n right: %s", var_export($left, true), var_export($right, true)));
10+
}
11+
}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3-
ini_set("display_errors", "On");
4-
ini_set("display_startup_errors", "On");
5-
error_reporting(E_ALL);
3+
require_once __DIR__ . '/_common.php';
4+
5+
assert_eq(integration_values_return_null(), null);
6+
assert_eq(integration_values_return_i32(), 32);
7+
assert_eq(integration_values_return_i64(), 64);

0 commit comments

Comments
 (0)