-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The new `plrust-tests` create is a standalone pgrx crate that only contains the unit tests from `plrust`. These were copied over verbatim, followed by minor organizational and formatting changes. To run the tests: ```shell $ cd plrust-tests $ ./run-tests.sh pgXX [test_name] ``` Co-authored-by: Eric B. Ridge <[email protected]> Co-authored-by: Brady Bonnette <[email protected]> Co-authored-by: Jubilee Young <[email protected]>
- Loading branch information
1 parent
9368363
commit 291842d
Showing
25 changed files
with
1,814 additions
and
1,418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "plrust-tests" | ||
version = "0.0.0" | ||
edition = "2021" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[features] | ||
default = ["pg13"] | ||
pg13 = ["pgrx/pg13", "pgrx-tests/pg13" ] | ||
pg14 = ["pgrx/pg14", "pgrx-tests/pg14" ] | ||
pg15 = ["pgrx/pg15", "pgrx-tests/pg15" ] | ||
pg_test = [] | ||
trusted = [] | ||
|
||
[dependencies] | ||
pgrx = "=0.9.7" | ||
tempfile = "3.8.0" | ||
once_cell = "1.18.0" | ||
|
||
[dev-dependencies] | ||
pgrx-tests = "=0.9.7" | ||
tempfile = "3.8.0" | ||
once_cell = "1.18.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
comment = 'plrust_tests: Created by pgrx' | ||
default_version = '@CARGO_VERSION@' | ||
module_pathname = '$libdir/plrust_tests' | ||
relocatable = false | ||
superuser = true | ||
requires = 'plrust' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#! /bin/bash | ||
|
||
VERSION=$1 | ||
|
||
if [ -z ${VERSION} ]; then | ||
echo "usage: ./run-tests.sh pgXX [test-name]" | ||
exit 1 | ||
fi | ||
|
||
TEST_DIR=`pwd` | ||
|
||
set -e | ||
|
||
# install the plrust extension into the pgrx-managed postgres | ||
echo "============================" | ||
echo " installing plrust" | ||
echo | ||
cd ../plrust | ||
echo "\q" | cargo pgrx run ${VERSION} | ||
|
||
# run the test suite from this crate | ||
cd ${TEST_DIR} | ||
|
||
echo | ||
echo "============================" | ||
echo " running plrust-tests suite" | ||
echo | ||
|
||
cargo pgrx test ${VERSION} $2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Portions Copyright 2020-2021 ZomboDB, LLC. | ||
Portions Copyright 2021-2023 Technology Concepts & Design, Inc. <[email protected]> | ||
All rights reserved. | ||
Use of this source code is governed by the PostgreSQL license that can be found in the LICENSE.md file. | ||
*/ | ||
|
||
#[cfg(any(test, feature = "pg_test"))] | ||
#[pgrx::pg_schema] | ||
mod tests { | ||
use pgrx::prelude::*; | ||
|
||
#[pg_test] | ||
#[search_path(@extschema@)] | ||
#[should_panic = "plrust functions cannot have their STRICT property altered"] | ||
fn plrust_cant_change_strict_off() -> spi::Result<()> { | ||
let definition = r#" | ||
CREATE FUNCTION cant_change_strict_off() | ||
RETURNS int | ||
LANGUAGE plrust | ||
AS $$ Ok(Some(1)) $$; | ||
"#; | ||
Spi::run(definition)?; | ||
Spi::run("ALTER FUNCTION cant_change_strict_off() CALLED ON NULL INPUT") | ||
} | ||
|
||
#[pg_test] | ||
#[search_path(@extschema@)] | ||
#[should_panic = "plrust functions cannot have their STRICT property altered"] | ||
fn plrust_cant_change_strict_on() -> spi::Result<()> { | ||
let definition = r#" | ||
CREATE FUNCTION cant_change_strict_on() | ||
RETURNS int | ||
LANGUAGE plrust | ||
AS $$ Ok(Some(1)) $$; | ||
"#; | ||
Spi::run(definition)?; | ||
Spi::run("ALTER FUNCTION cant_change_strict_on() RETURNS NULL ON NULL INPUT") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Portions Copyright 2020-2021 ZomboDB, LLC. | ||
Portions Copyright 2021-2023 Technology Concepts & Design, Inc. <[email protected]> | ||
All rights reserved. | ||
Use of this source code is governed by the PostgreSQL license that can be found in the LICENSE.md file. | ||
*/ | ||
|
||
#[cfg(any(test, feature = "pg_test"))] | ||
#[pgrx::pg_schema] | ||
mod tests { | ||
use pgrx::prelude::*; | ||
|
||
#[pg_test] | ||
#[search_path(@extschema@)] | ||
#[should_panic = "parameter name \"a\" used more than once"] | ||
fn plrust_dup_args() -> spi::Result<()> { | ||
let definition = r#" | ||
CREATE FUNCTION not_unique(a int, a int) | ||
RETURNS int AS | ||
$$ | ||
Ok(a) | ||
$$ LANGUAGE plrust; | ||
"#; | ||
Spi::run(definition)?; | ||
let result = Spi::get_one::<i32>("SELECT not_unique(1, 2);\n"); | ||
assert_eq!(Ok(Some(1)), result); | ||
Ok(()) | ||
} | ||
|
||
#[pg_test] | ||
#[search_path(@extschema@)] | ||
#[should_panic = "PL/Rust does not support unnamed arguments"] | ||
fn plrust_defaulting_dup_args() -> spi::Result<()> { | ||
let definition = r#" | ||
CREATE FUNCTION not_unique(int, arg0 int) | ||
RETURNS int AS | ||
$$ | ||
Ok(arg0) | ||
$$ LANGUAGE plrust; | ||
"#; | ||
Spi::run(definition)?; | ||
let result = Spi::get_one::<i32>("SELECT not_unique(1, 2);\n"); | ||
assert_eq!(Ok(Some(1)), result); | ||
Ok(()) | ||
} | ||
|
||
#[pg_test] | ||
#[search_path(@extschema@)] | ||
#[should_panic(expected = "PL/Rust does not support unnamed arguments")] | ||
fn unnamed_args() -> spi::Result<()> { | ||
Spi::run("CREATE FUNCTION unnamed_arg(int) RETURNS int LANGUAGE plrust as $$ Ok(None) $$;") | ||
} | ||
|
||
#[pg_test] | ||
#[search_path(@extschema@)] | ||
#[should_panic(expected = "PL/Rust does not support unnamed arguments")] | ||
fn named_unnamed_args() -> spi::Result<()> { | ||
Spi::run("CREATE FUNCTION named_unnamed_arg(bob text, int) RETURNS int LANGUAGE plrust as $$ Ok(None) $$;") | ||
} | ||
|
||
#[pg_test] | ||
#[search_path(@extschema@)] | ||
#[should_panic( | ||
expected = "is an invalid Rust identifier and cannot be used as an argument name" | ||
)] | ||
fn invalid_arg_identifier() -> spi::Result<()> { | ||
Spi::run("CREATE FUNCTION invalid_arg_identifier(\"this isn't a valid rust identifier\" int) RETURNS int LANGUAGE plrust as $$ Ok(None) $$;") | ||
} | ||
} |
Oops, something went wrong.