diff --git a/src/lib.rs b/src/lib.rs index c4f930752..952e038d9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -798,7 +798,7 @@ impl PostgresConnection { /// let maybe_stmt = conn.prepare("SELECT foo FROM bar WHERE baz = $1"); /// let stmt = match maybe_stmt { /// Ok(stmt) => stmt, - /// Err(err) => fail!("Error preparing statement: {}", err) + /// Err(err) => panic!("Error preparing statement: {}", err) /// }; pub fn prepare<'a>(&'a self, query: &str) -> PostgresResult> { let mut conn = self.conn.borrow_mut(); @@ -1283,7 +1283,7 @@ impl<'conn> PostgresStatement<'conn> { /// # let baz = true; /// let mut rows = match stmt.query(&[&baz]) { /// Ok(rows) => rows, - /// Err(err) => fail!("Error running query: {}", err) + /// Err(err) => panic!("Error running query: {}", err) /// }; /// for row in rows { /// let foo: i32 = row.get("foo"); @@ -1488,7 +1488,7 @@ impl<'stmt> PostgresRow<'stmt> { pub fn get(&self, idx: I) -> T where I: RowIndex + fmt::Show + Clone, T: FromSql { match self.get_opt(idx.clone()) { Ok(ok) => ok, - Err(err) => fail!("error retrieving column {}: {}", idx, err) + Err(err) => panic!("error retrieving column {}: {}", idx, err) } } } diff --git a/src/macros.rs b/src/macros.rs index 0f8a6d87f..100760676 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -43,7 +43,7 @@ macro_rules! try_pg_desync( macro_rules! check_desync( ($e:expr) => ({ if $e.canary() != CANARY { - fail!("PostgresConnection use after free. See mozilla/rust#13246."); + panic!("PostgresConnection use after free. See mozilla/rust#13246."); } if $e.is_desynchronized() { return Err(PgStreamDesynchronized); diff --git a/tests/pool.rs b/tests/pool.rs index 09d48dade..38d263f4d 100644 --- a/tests/pool.rs +++ b/tests/pool.rs @@ -9,7 +9,7 @@ use postgres::pool::PostgresConnectionPool; #[test] // Make sure we can take both connections at once and can still get one after fn test_pool() { - let pool = or_fail!(PostgresConnectionPool::new("postgres://postgres@localhost", + let pool = or_panic!(PostgresConnectionPool::new("postgres://postgres@localhost", NoSsl, 2)); let (s1, r1) = comm::channel(); diff --git a/tests/test.rs b/tests/test.rs index 070d203cb..d22d6a5f6 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -38,11 +38,11 @@ use postgres::error::{PgConnectDbError, CardinalityViolation}; use postgres::types::{PgInt4, PgVarchar, ToSql}; -macro_rules! or_fail( +macro_rules! or_panic( ($e:expr) => ( match $e { Ok(ok) => ok, - Err(err) => fail!("{}", err) + Err(err) => panic!("{}", err) } ) ) @@ -52,21 +52,21 @@ mod pool; #[test] fn test_non_default_database() { - or_fail!(PostgresConnection::connect("postgres://postgres@localhost/postgres", &NoSsl)); + or_panic!(PostgresConnection::connect("postgres://postgres@localhost/postgres", &NoSsl)); } #[test] fn test_url_terminating_slash() { - or_fail!(PostgresConnection::connect("postgres://postgres@localhost/", &NoSsl)); + or_panic!(PostgresConnection::connect("postgres://postgres@localhost/", &NoSsl)); } #[test] fn test_prepare_err() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); match conn.prepare("invalid sql statment") { Err(PgDbError(PostgresDbError { code: SyntaxError, position: Some(Position(1)), .. })) => (), - Err(e) => fail!("Unexpected result {}", e), - _ => fail!("Unexpected result"), + Err(e) => panic!("Unexpected result {}", e), + _ => panic!("Unexpected result"), } } @@ -74,193 +74,193 @@ fn test_prepare_err() { fn test_unknown_database() { match PostgresConnection::connect("postgres://postgres@localhost/asdf", &NoSsl) { Err(PgConnectDbError(PostgresDbError { code: InvalidCatalogName, .. })) => {} - Err(resp) => fail!("Unexpected result {}", resp), - _ => fail!("Unexpected result"), + Err(resp) => panic!("Unexpected result {}", resp), + _ => panic!("Unexpected result"), } } #[test] fn test_connection_finish() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); assert!(conn.finish().is_ok()); } #[test] fn test_unix_connection() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let stmt = or_fail!(conn.prepare("SHOW unix_socket_directories")); - let result = or_fail!(stmt.query([])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let stmt = or_panic!(conn.prepare("SHOW unix_socket_directories")); + let result = or_panic!(stmt.query([])); let unix_socket_directories: String = result.map(|row| row.get(0)).next().unwrap(); if unix_socket_directories.is_empty() { - fail!("can't test connect_unix; unix_socket_directories is empty"); + panic!("can't test connect_unix; unix_socket_directories is empty"); } let unix_socket_directory = unix_socket_directories[].split(',').next().unwrap(); let path = url::utf8_percent_encode(unix_socket_directory, url::USERNAME_ENCODE_SET); let url = format!("postgres://postgres@{}", path); - let conn = or_fail!(PostgresConnection::connect(url[], &NoSsl)); + let conn = or_panic!(PostgresConnection::connect(url[], &NoSsl)); assert!(conn.finish().is_ok()); } #[test] fn test_transaction_commit() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); - let trans = or_fail!(conn.transaction()); - or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32])); + let trans = or_panic!(conn.transaction()); + or_panic!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32])); trans.set_commit(); drop(trans); - let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(conn.prepare("SELECT * FROM foo")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect()); } #[test] fn test_transaction_commit_finish() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); - let trans = or_fail!(conn.transaction()); - or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32])); + let trans = or_panic!(conn.transaction()); + or_panic!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32])); trans.set_commit(); assert!(trans.finish().is_ok()); - let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(conn.prepare("SELECT * FROM foo")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect()); } #[test] fn test_transaction_commit_method() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); - let trans = or_fail!(conn.transaction()); - or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32])); + let trans = or_panic!(conn.transaction()); + or_panic!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32])); assert!(trans.commit().is_ok()); - let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(conn.prepare("SELECT * FROM foo")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect()); } #[test] fn test_transaction_rollback() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); - or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32])); + or_panic!(conn.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32])); - let trans = or_fail!(conn.transaction()); - or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&2i32])); + let trans = or_panic!(conn.transaction()); + or_panic!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&2i32])); drop(trans); - let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(conn.prepare("SELECT * FROM foo")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect()); } #[test] fn test_transaction_rollback_finish() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); - or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32])); + or_panic!(conn.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32])); - let trans = or_fail!(conn.transaction()); - or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&2i32])); + let trans = or_panic!(conn.transaction()); + or_panic!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&2i32])); assert!(trans.finish().is_ok()); - let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(conn.prepare("SELECT * FROM foo")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect()); } #[test] fn test_nested_transactions() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); - or_fail!(conn.execute("INSERT INTO foo (id) VALUES (1)", [])); + or_panic!(conn.execute("INSERT INTO foo (id) VALUES (1)", [])); { - let trans1 = or_fail!(conn.transaction()); - or_fail!(trans1.execute("INSERT INTO foo (id) VALUES (2)", [])); + let trans1 = or_panic!(conn.transaction()); + or_panic!(trans1.execute("INSERT INTO foo (id) VALUES (2)", [])); { - let trans2 = or_fail!(trans1.transaction()); - or_fail!(trans2.execute("INSERT INTO foo (id) VALUES (3)", [])); + let trans2 = or_panic!(trans1.transaction()); + or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (3)", [])); } { - let trans2 = or_fail!(trans1.transaction()); - or_fail!(trans2.execute("INSERT INTO foo (id) VALUES (4)", [])); + let trans2 = or_panic!(trans1.transaction()); + or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (4)", [])); { - let trans3 = or_fail!(trans2.transaction()); - or_fail!(trans3.execute("INSERT INTO foo (id) VALUES (5)", [])); + let trans3 = or_panic!(trans2.transaction()); + or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (5)", [])); } { - let trans3 = or_fail!(trans2.transaction()); - or_fail!(trans3.execute("INSERT INTO foo (id) VALUES (6)", [])); + let trans3 = or_panic!(trans2.transaction()); + or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (6)", [])); assert!(trans3.commit().is_ok()); } assert!(trans2.commit().is_ok()); } - let stmt = or_fail!(trans1.prepare("SELECT * FROM foo ORDER BY id")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(trans1.prepare("SELECT * FROM foo ORDER BY id")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![1i32, 2, 4, 6], result.map(|row| row.get(0)).collect()); } - let stmt = or_fail!(conn.prepare("SELECT * FROM foo ORDER BY id")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(conn.prepare("SELECT * FROM foo ORDER BY id")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect()); } #[test] fn test_nested_transactions_finish() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); - or_fail!(conn.execute("INSERT INTO foo (id) VALUES (1)", [])); + or_panic!(conn.execute("INSERT INTO foo (id) VALUES (1)", [])); { - let trans1 = or_fail!(conn.transaction()); - or_fail!(trans1.execute("INSERT INTO foo (id) VALUES (2)", [])); + let trans1 = or_panic!(conn.transaction()); + or_panic!(trans1.execute("INSERT INTO foo (id) VALUES (2)", [])); { - let trans2 = or_fail!(trans1.transaction()); - or_fail!(trans2.execute("INSERT INTO foo (id) VALUES (3)", [])); + let trans2 = or_panic!(trans1.transaction()); + or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (3)", [])); assert!(trans2.finish().is_ok()); } { - let trans2 = or_fail!(trans1.transaction()); - or_fail!(trans2.execute("INSERT INTO foo (id) VALUES (4)", [])); + let trans2 = or_panic!(trans1.transaction()); + or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (4)", [])); { - let trans3 = or_fail!(trans2.transaction()); - or_fail!(trans3.execute("INSERT INTO foo (id) VALUES (5)", [])); + let trans3 = or_panic!(trans2.transaction()); + or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (5)", [])); assert!(trans3.finish().is_ok()); } { - let trans3 = or_fail!(trans2.transaction()); - or_fail!(trans3.execute("INSERT INTO foo (id) VALUES (6)", [])); + let trans3 = or_panic!(trans2.transaction()); + or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (6)", [])); trans3.set_commit(); assert!(trans3.finish().is_ok()); } @@ -271,8 +271,8 @@ fn test_nested_transactions_finish() { // in a block to unborrow trans1 for the finish call { - let stmt = or_fail!(trans1.prepare("SELECT * FROM foo ORDER BY id")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(trans1.prepare("SELECT * FROM foo ORDER BY id")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![1i32, 2, 4, 6], result.map(|row| row.get(0)).collect()); } @@ -280,69 +280,69 @@ fn test_nested_transactions_finish() { assert!(trans1.finish().is_ok()); } - let stmt = or_fail!(conn.prepare("SELECT * FROM foo ORDER BY id")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(conn.prepare("SELECT * FROM foo ORDER BY id")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect()); } #[test] fn test_conn_prepare_with_trans() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let _trans = or_fail!(conn.transaction()); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let _trans = or_panic!(conn.transaction()); match conn.prepare("") { Err(PgWrongTransaction) => {} - Err(r) => fail!("Unexpected error {}", r), - Ok(_) => fail!("Unexpected success"), + Err(r) => panic!("Unexpected error {}", r), + Ok(_) => panic!("Unexpected success"), } match conn.transaction() { Err(PgWrongTransaction) => {} - Err(r) => fail!("Unexpected error {}", r), - Ok(_) => fail!("Unexpected success"), + Err(r) => panic!("Unexpected error {}", r), + Ok(_) => panic!("Unexpected success"), } } #[test] fn test_trans_prepare_with_nested_trans() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let trans = or_fail!(conn.transaction()); - let _trans2 = or_fail!(trans.transaction()); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let trans = or_panic!(conn.transaction()); + let _trans2 = or_panic!(trans.transaction()); match trans.prepare("") { Err(PgWrongTransaction) => {} - Err(r) => fail!("Unexpected error {}", r), - Ok(_) => fail!("Unexpected success"), + Err(r) => panic!("Unexpected error {}", r), + Ok(_) => panic!("Unexpected success"), } match trans.transaction() { Err(PgWrongTransaction) => {} - Err(r) => fail!("Unexpected error {}", r), - Ok(_) => fail!("Unexpected success"), + Err(r) => panic!("Unexpected error {}", r), + Ok(_) => panic!("Unexpected success"), } } #[test] fn test_stmt_finish() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", [])); - let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", [])); + let stmt = or_panic!(conn.prepare("SELECT * FROM foo")); assert!(stmt.finish().is_ok()); } #[test] fn test_batch_execute() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY); INSERT INTO foo (id) VALUES (10);"; - or_fail!(conn.batch_execute(query)); + or_panic!(conn.batch_execute(query)); - let stmt = or_fail!(conn.prepare("SELECT * from foo ORDER BY id")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(conn.prepare("SELECT * from foo ORDER BY id")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![10i64], result.map(|row| row.get(0)).collect()); } #[test] fn test_batch_execute_error() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY); INSERT INTO foo (id) VALUES (10); asdfa; @@ -351,41 +351,41 @@ fn test_batch_execute_error() { match conn.prepare("SELECT * from foo ORDER BY id") { Err(PgDbError(PostgresDbError { code: UndefinedTable, .. })) => {}, - Err(e) => fail!("unexpected error {}", e), - _ => fail!("unexpected success"), + Err(e) => panic!("unexpected error {}", e), + _ => panic!("unexpected success"), } } #[test] fn test_transaction_batch_execute() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let trans = or_fail!(conn.transaction()); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let trans = or_panic!(conn.transaction()); let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY); INSERT INTO foo (id) VALUES (10);"; - or_fail!(trans.batch_execute(query)); + or_panic!(trans.batch_execute(query)); - let stmt = or_fail!(trans.prepare("SELECT * from foo ORDER BY id")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(trans.prepare("SELECT * from foo ORDER BY id")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![10i64], result.map(|row| row.get(0)).collect()); } #[test] fn test_query() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", [])); - or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1), ($2)", + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", [])); + or_panic!(conn.execute("INSERT INTO foo (id) VALUES ($1), ($2)", &[&1i64, &2i64])); - let stmt = or_fail!(conn.prepare("SELECT * from foo ORDER BY id")); - let result = or_fail!(stmt.query([])); + let stmt = or_panic!(conn.prepare("SELECT * from foo ORDER BY id")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![1i64, 2], result.map(|row| row.get(0)).collect()); } #[test] fn test_error_after_datarow() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let stmt = or_fail!(conn.prepare(" + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let stmt = or_panic!(conn.prepare(" SELECT (SELECT generate_series(1, ss.i)) FROM (SELECT gs.i @@ -394,61 +394,61 @@ FROM (SELECT gs.i LIMIT 2) ss")); match stmt.query([]) { Err(PgDbError(PostgresDbError { code: CardinalityViolation, .. })) => {} - Err(err) => fail!("Unexpected error {}", err), - Ok(_) => fail!("Expected failure"), + Err(err) => panic!("Unexpected error {}", err), + Ok(_) => panic!("Expected failure"), } } #[test] fn test_result_finish() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", [])); - let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); - let result = or_fail!(stmt.query([])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", [])); + let stmt = or_panic!(conn.prepare("SELECT * FROM foo")); + let result = or_panic!(stmt.query([])); assert!(result.finish().is_ok()); } #[test] fn test_lazy_query() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let trans = or_fail!(conn.transaction()); - or_fail!(trans.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); - let stmt = or_fail!(trans.prepare("INSERT INTO foo (id) VALUES ($1)")); + let trans = or_panic!(conn.transaction()); + or_panic!(trans.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); + let stmt = or_panic!(trans.prepare("INSERT INTO foo (id) VALUES ($1)")); let values = vec!(0i32, 1, 2, 3, 4, 5); for value in values.iter() { - or_fail!(stmt.execute(&[value])); + or_panic!(stmt.execute(&[value])); } - let stmt = or_fail!(trans.prepare("SELECT id FROM foo ORDER BY id")); - let result = or_fail!(trans.lazy_query(&stmt, [], 2)); + let stmt = or_panic!(trans.prepare("SELECT id FROM foo ORDER BY id")); + let result = or_panic!(trans.lazy_query(&stmt, [], 2)); assert_eq!(values, result.map(|row| row.unwrap().get(0)).collect()); } #[test] fn test_lazy_query_wrong_conn() { - let conn1 = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let conn2 = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn1 = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn2 = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let trans = or_fail!(conn1.transaction()); - let stmt = or_fail!(conn2.prepare("SELECT 1::INT")); + let trans = or_panic!(conn1.transaction()); + let stmt = or_panic!(conn2.prepare("SELECT 1::INT")); match trans.lazy_query(&stmt, [], 1) { Err(PgWrongConnection) => {} - Err(err) => fail!("Unexpected error {}", err), - Ok(_) => fail!("Expected failure") + Err(err) => panic!("Unexpected error {}", err), + Ok(_) => panic!("Expected failure") } } #[test] fn test_param_types() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let stmt = or_fail!(conn.prepare("SELECT $1::INT, $2::VARCHAR")); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let stmt = or_panic!(conn.prepare("SELECT $1::INT, $2::VARCHAR")); assert_eq!(stmt.param_types(), [PgInt4, PgVarchar][]); } #[test] fn test_result_descriptions() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let stmt = or_fail!(conn.prepare("SELECT 1::INT as a, 'hi'::VARCHAR as b")); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let stmt = or_panic!(conn.prepare("SELECT 1::INT as a, 'hi'::VARCHAR as b")); assert!(stmt.result_descriptions() == [ResultDescription { name: "a".to_string(), ty: PgInt4}, ResultDescription { name: "b".to_string(), ty: PgVarchar}]); @@ -456,49 +456,49 @@ fn test_result_descriptions() { #[test] fn test_execute_counts() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - assert_eq!(0, or_fail!(conn.execute("CREATE TEMPORARY TABLE foo ( + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + assert_eq!(0, or_panic!(conn.execute("CREATE TEMPORARY TABLE foo ( id SERIAL PRIMARY KEY, b INT )", []))); - assert_eq!(3, or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($2)", + assert_eq!(3, or_panic!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($2)", &[&1i32, &2i32]))); - assert_eq!(2, or_fail!(conn.execute("UPDATE foo SET b = 0 WHERE b = 2", []))); - assert_eq!(3, or_fail!(conn.execute("SELECT * FROM foo", []))); + assert_eq!(2, or_panic!(conn.execute("UPDATE foo SET b = 0 WHERE b = 2", []))); + assert_eq!(3, or_panic!(conn.execute("SELECT * FROM foo", []))); } #[test] fn test_wrong_param_type() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); match conn.execute("SELECT $1::VARCHAR", &[&1i32]) { Err(PgWrongType(_)) => {} - res => fail!("unexpected result {}", res) + res => panic!("unexpected result {}", res) } } #[test] fn test_too_few_params() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); match conn.execute("SELECT $1::INT, $2::INT", &[&1i32]) { Err(PgWrongParamCount { expected: 2, actual: 1 }) => {}, - res => fail!("unexpected result {}", res) + res => panic!("unexpected result {}", res) } } #[test] fn test_too_many_params() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); match conn.execute("SELECT $1::INT, $2::INT", &[&1i32, &2i32, &3i32]) { Err(PgWrongParamCount { expected: 2, actual: 3 }) => {}, - res => fail!("unexpected result {}", res) + res => panic!("unexpected result {}", res) } } #[test] fn test_index_named() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let stmt = or_fail!(conn.prepare("SELECT 10::INT as val")); - let result = or_fail!(stmt.query([])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let stmt = or_panic!(conn.prepare("SELECT 10::INT as val")); + let result = or_panic!(stmt.query([])); assert_eq!(vec![10i32], result.map(|row| row.get("val")).collect()); } @@ -506,34 +506,34 @@ fn test_index_named() { #[test] #[should_fail] fn test_index_named_fail() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let stmt = or_fail!(conn.prepare("SELECT 10::INT as id")); - let mut result = or_fail!(stmt.query([])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let stmt = or_panic!(conn.prepare("SELECT 10::INT as id")); + let mut result = or_panic!(stmt.query([])); let _: i32 = result.next().unwrap().get("asdf"); } #[test] fn test_get_named_err() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let stmt = or_fail!(conn.prepare("SELECT 10::INT as id")); - let mut result = or_fail!(stmt.query([])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let stmt = or_panic!(conn.prepare("SELECT 10::INT as id")); + let mut result = or_panic!(stmt.query([])); match result.next().unwrap().get_opt::<&str, i32>("asdf") { Err(PgInvalidColumn) => {} - res => fail!("unexpected result {}", res), + res => panic!("unexpected result {}", res), }; } #[test] fn test_get_was_null() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let stmt = or_fail!(conn.prepare("SELECT NULL::INT as id")); - let mut result = or_fail!(stmt.query([])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let stmt = or_panic!(conn.prepare("SELECT NULL::INT as id")); + let mut result = or_panic!(stmt.query([])); match result.next().unwrap().get_opt::(0) { Err(PgWasNull) => {} - res => fail!("unexpected result {}", res), + res => panic!("unexpected result {}", res), }; } @@ -549,22 +549,22 @@ fn test_custom_notice_handler() { } } - let conn = or_fail!(PostgresConnection::connect( + let conn = or_panic!(PostgresConnection::connect( "postgres://postgres@localhost?client_min_messages=NOTICE", &NoSsl)); conn.set_notice_handler(box Handler); - or_fail!(conn.execute("CREATE FUNCTION pg_temp.note() RETURNS INT AS $$ + or_panic!(conn.execute("CREATE FUNCTION pg_temp.note() RETURNS INT AS $$ BEGIN RAISE NOTICE 'note'; RETURN 1; END; $$ LANGUAGE plpgsql", [])); - or_fail!(conn.execute("SELECT pg_temp.note()", [])); + or_panic!(conn.execute("SELECT pg_temp.note()", [])); assert_eq!(unsafe { count }, 1); } #[test] fn test_notification_iterator_none() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); assert!(conn.notifications().next().is_none()); } @@ -577,16 +577,16 @@ fn test_notification_iterator_some() { assert_eq!(&expected.channel, &channel); assert_eq!(&expected.payload, &payload); } - None => fail!("Unexpected result") + None => panic!("Unexpected result") } } - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); let mut it = conn.notifications(); - or_fail!(conn.execute("LISTEN test_notification_iterator_one_channel", [])); - or_fail!(conn.execute("LISTEN test_notification_iterator_one_channel2", [])); - or_fail!(conn.execute("NOTIFY test_notification_iterator_one_channel, 'hello'", [])); - or_fail!(conn.execute("NOTIFY test_notification_iterator_one_channel2, 'world'", [])); + or_panic!(conn.execute("LISTEN test_notification_iterator_one_channel", [])); + or_panic!(conn.execute("LISTEN test_notification_iterator_one_channel2", [])); + or_panic!(conn.execute("NOTIFY test_notification_iterator_one_channel, 'hello'", [])); + or_panic!(conn.execute("NOTIFY test_notification_iterator_one_channel2, 'world'", [])); check_notification(PostgresNotification { pid: 0, @@ -600,7 +600,7 @@ fn test_notification_iterator_some() { }, it.next()); assert!(it.next().is_none()); - or_fail!(conn.execute("NOTIFY test_notification_iterator_one_channel, '!'", [])); + or_panic!(conn.execute("NOTIFY test_notification_iterator_one_channel, '!'", [])); check_notification(PostgresNotification { pid: 0, channel: "test_notification_iterator_one_channel".to_string(), @@ -612,7 +612,7 @@ fn test_notification_iterator_some() { #[test] // This test is pretty sad, but I don't think there's a better way :( fn test_cancel_query() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); let cancel_data = conn.cancel_data(); spawn(proc() { @@ -623,30 +623,30 @@ fn test_cancel_query() { match conn.execute("SELECT pg_sleep(10)", []) { Err(PgDbError(PostgresDbError { code: QueryCanceled, .. })) => {} - Err(res) => fail!("Unexpected result {}", res), - _ => fail!("Unexpected result"), + Err(res) => panic!("Unexpected result {}", res), + _ => panic!("Unexpected result"), } } #[test] fn test_require_ssl_conn() { let ctx = SslContext::new(Sslv3).unwrap(); - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &RequireSsl(ctx))); - or_fail!(conn.execute("SELECT 1::VARCHAR", [])); + or_panic!(conn.execute("SELECT 1::VARCHAR", [])); } #[test] fn test_prefer_ssl_conn() { let ctx = SslContext::new(Sslv3).unwrap(); - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &PreferSsl(ctx))); - or_fail!(conn.execute("SELECT 1::VARCHAR", [])); + or_panic!(conn.execute("SELECT 1::VARCHAR", [])); } #[test] fn test_plaintext_pass() { - or_fail!(PostgresConnection::connect("postgres://pass_user:password@localhost/postgres", &NoSsl)); + or_panic!(PostgresConnection::connect("postgres://pass_user:password@localhost/postgres", &NoSsl)); } #[test] @@ -654,8 +654,8 @@ fn test_plaintext_pass_no_pass() { let ret = PostgresConnection::connect("postgres://pass_user@localhost/postgres", &NoSsl); match ret { Err(MissingPassword) => (), - Err(err) => fail!("Unexpected error {}", err), - _ => fail!("Expected error") + Err(err) => panic!("Unexpected error {}", err), + _ => panic!("Expected error") } } @@ -664,14 +664,14 @@ fn test_plaintext_pass_wrong_pass() { let ret = PostgresConnection::connect("postgres://pass_user:asdf@localhost/postgres", &NoSsl); match ret { Err(PgConnectDbError(PostgresDbError { code: InvalidPassword, .. })) => (), - Err(err) => fail!("Unexpected error {}", err), - _ => fail!("Expected error") + Err(err) => panic!("Unexpected error {}", err), + _ => panic!("Expected error") } } #[test] fn test_md5_pass() { - or_fail!(PostgresConnection::connect("postgres://md5_user:password@localhost/postgres", &NoSsl)); + or_panic!(PostgresConnection::connect("postgres://md5_user:password@localhost/postgres", &NoSsl)); } #[test] @@ -679,8 +679,8 @@ fn test_md5_pass_no_pass() { let ret = PostgresConnection::connect("postgres://md5_user@localhost/postgres", &NoSsl); match ret { Err(MissingPassword) => (), - Err(err) => fail!("Unexpected error {}", err), - _ => fail!("Expected error") + Err(err) => panic!("Unexpected error {}", err), + _ => panic!("Expected error") } } @@ -689,56 +689,56 @@ fn test_md5_pass_wrong_pass() { let ret = PostgresConnection::connect("postgres://md5_user:asdf@localhost/postgres", &NoSsl); match ret { Err(PgConnectDbError(PostgresDbError { code: InvalidPassword, .. })) => (), - Err(err) => fail!("Unexpected error {}", err), - _ => fail!("Expected error") + Err(err) => panic!("Unexpected error {}", err), + _ => panic!("Expected error") } } #[test] fn test_execute_copy_from_err() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", [])); - let stmt = or_fail!(conn.prepare("COPY foo (id) FROM STDIN")); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", [])); + let stmt = or_panic!(conn.prepare("COPY foo (id) FROM STDIN")); match stmt.execute([]) { Err(PgDbError(ref err)) if err.message[].contains("COPY") => {} - Err(err) => fail!("Unexptected error {}", err), - _ => fail!("Expected error"), + Err(err) => panic!("Unexptected error {}", err), + _ => panic!("Expected error"), } match stmt.query([]) { Err(PgDbError(ref err)) if err.message[].contains("COPY") => {} - Err(err) => fail!("Unexptected error {}", err), - _ => fail!("Expected error"), + Err(err) => panic!("Unexptected error {}", err), + _ => panic!("Expected error"), } } #[test] fn test_copy_in() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", [])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", [])); - let stmt = or_fail!(conn.prepare_copy_in("foo", ["id", "name"])); + let stmt = or_panic!(conn.prepare_copy_in("foo", ["id", "name"])); let data: &[&[&ToSql]] = &[&[&0i32, &"Steven".to_string()], &[&1i32, &None::]]; assert_eq!(Ok(2), stmt.execute(data.iter().map(|r| r.iter().map(|&e| e)))); - let stmt = or_fail!(conn.prepare("SELECT id, name FROM foo ORDER BY id")); + let stmt = or_panic!(conn.prepare("SELECT id, name FROM foo ORDER BY id")); assert_eq!(vec![(0i32, Some("Steven".to_string())), (1, None)], - or_fail!(stmt.query([])).map(|r| (r.get(0), r.get(1))).collect()); + or_panic!(stmt.query([])).map(|r| (r.get(0), r.get(1))).collect()); } #[test] fn test_copy_in_bad_column_count() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", [])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", [])); - let stmt = or_fail!(conn.prepare_copy_in("foo", ["id", "name"])); + let stmt = or_panic!(conn.prepare_copy_in("foo", ["id", "name"])); let data: &[&[&ToSql]] = &[&[&0i32, &"Steven".to_string()], &[&1i32]]; let res = stmt.execute(data.iter().map(|r| r.iter().map(|&e| e))); match res { Err(PgDbError(ref err)) if err.message[].contains("Invalid column count") => {} - Err(err) => fail!("unexpected error {}", err), - _ => fail!("Expected error"), + Err(err) => panic!("unexpected error {}", err), + _ => panic!("Expected error"), } let data: &[&[&ToSql]] = &[&[&0i32, &"Steven".to_string()], &[&1i32, &"Steven".to_string(), &1i32]]; @@ -746,39 +746,39 @@ fn test_copy_in_bad_column_count() { let res = stmt.execute(data.iter().map(|r| r.iter().map(|&e| e))); match res { Err(PgDbError(ref err)) if err.message[].contains("Invalid column count") => {} - Err(err) => fail!("unexpected error {}", err), - _ => fail!("Expected error"), + Err(err) => panic!("unexpected error {}", err), + _ => panic!("Expected error"), } - or_fail!(conn.execute("SELECT 1", [])); + or_panic!(conn.execute("SELECT 1", [])); } #[test] fn test_copy_in_bad_type() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", [])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", [])); - let stmt = or_fail!(conn.prepare_copy_in("foo", ["id", "name"])); + let stmt = or_panic!(conn.prepare_copy_in("foo", ["id", "name"])); let data: &[&[&ToSql]] = &[&[&0i32, &"Steven".to_string()], &[&1i32, &2i32]]; let res = stmt.execute(data.iter().map(|r| r.iter().map(|&e| e))); match res { Err(PgDbError(ref err)) if err.message[].contains("Unexpected type PgVarchar") => {} - Err(err) => fail!("unexpected error {}", err), - _ => fail!("Expected error"), + Err(err) => panic!("unexpected error {}", err), + _ => panic!("Expected error"), } - or_fail!(conn.execute("SELECT 1", [])); + or_panic!(conn.execute("SELECT 1", [])); } #[test] fn test_batch_execute_copy_from_err() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", [])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", [])); match conn.batch_execute("COPY foo (id) FROM STDIN") { Err(PgDbError(ref err)) if err.message[].contains("COPY") => {} - Err(err) => fail!("Unexptected error {}", err), - _ => fail!("Expected error"), + Err(err) => panic!("Unexptected error {}", err), + _ => panic!("Expected error"), } } @@ -786,11 +786,11 @@ fn test_batch_execute_copy_from_err() { // Just make sure the impls don't infinite loop fn test_generic_connection() { fn f(t: &T) where T: GenericConnection { - or_fail!(t.execute("SELECT 1", [])); + or_panic!(t.execute("SELECT 1", [])); } - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); f(&conn); - let trans = or_fail!(conn.transaction()); + let trans = or_panic!(conn.transaction()); f(&trans); } diff --git a/tests/types/mod.rs b/tests/types/mod.rs index 0d1684959..b276485df 100644 --- a/tests/types/mod.rs +++ b/tests/types/mod.rs @@ -13,14 +13,14 @@ mod array; mod range; fn test_type(sql_type: &str, checks: &[(T, S)]) { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); for &(ref val, ref repr) in checks.iter() { - let stmt = or_fail!(conn.prepare(format!("SELECT {:s}::{}", *repr, sql_type)[])); - let result = or_fail!(stmt.query([])).next().unwrap().get(0u); + let stmt = or_panic!(conn.prepare(format!("SELECT {:s}::{}", *repr, sql_type)[])); + let result = or_panic!(stmt.query([])).next().unwrap().get(0u); assert!(val == &result); - let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type)[])); - let result = or_fail!(stmt.query(&[val])).next().unwrap().get(0u); + let stmt = or_panic!(conn.prepare(format!("SELECT $1::{}", sql_type)[])); + let result = or_panic!(stmt.query(&[val])).next().unwrap().get(0u); assert!(val == &result); } } @@ -93,15 +93,15 @@ fn test_text_params() { #[test] fn test_bpchar_params() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - or_fail!(conn.execute("CREATE TEMPORARY TABLE foo ( + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + or_panic!(conn.execute("CREATE TEMPORARY TABLE foo ( id SERIAL PRIMARY KEY, b CHAR(5) )", [])); - or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($3)", + or_panic!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($3)", &[&Some("12345"), &Some("123"), &None::<&'static str>])); - let stmt = or_fail!(conn.prepare("SELECT b FROM foo ORDER BY id")); - let res = or_fail!(stmt.query([])); + let stmt = or_panic!(conn.prepare("SELECT b FROM foo ORDER BY id")); + let res = or_panic!(stmt.query([])); assert_eq!(vec!(Some("12345".to_string()), Some("123 ".to_string()), None), res.map(|row| row.get(0u)).collect()); @@ -334,15 +334,15 @@ fn test_hstore_params() { } fn test_nan_param(sql_type: &str) { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let stmt = or_fail!(conn.prepare(format!("SELECT 'NaN'::{}", sql_type)[])); - let mut result = or_fail!(stmt.query([])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let stmt = or_panic!(conn.prepare(format!("SELECT 'NaN'::{}", sql_type)[])); + let mut result = or_panic!(stmt.query([])); let val: T = result.next().unwrap().get(0u); assert!(val.is_nan()); let nan: T = Float::nan(); - let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type)[])); - let mut result = or_fail!(stmt.query(&[&nan])); + let stmt = or_panic!(conn.prepare(format!("SELECT $1::{}", sql_type)[])); + let mut result = or_panic!(stmt.query(&[&nan])); let val: T = result.next().unwrap().get(0u); assert!(val.is_nan()) } @@ -370,11 +370,11 @@ fn test_jsonarray_params() { #[test] fn test_pg_database_datname() { - let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - let stmt = or_fail!(conn.prepare("SELECT datname FROM pg_database")); - let mut result = or_fail!(stmt.query([])); + let conn = or_panic!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); + let stmt = or_panic!(conn.prepare("SELECT datname FROM pg_database")); + let mut result = or_panic!(stmt.query([])); let next = result.next().unwrap(); - or_fail!(next.get_opt::(0)); - or_fail!(next.get_opt::<&str, String>("datname")); + or_panic!(next.get_opt::(0)); + or_panic!(next.get_opt::<&str, String>("datname")); }