diff --git a/TrsrDB.pm b/TrsrDB.pm index 1bf3247..e3e5e9c 100644 --- a/TrsrDB.pm +++ b/TrsrDB.pm @@ -14,7 +14,7 @@ sub import { return if @_ == 1; croak "use TrsrDB \$your_db_handle missing" if !defined $dbh_ref; $$dbh_ref = $class->connect( - "DBI:SQLite:" . ($filename // ":memory:"), + "DBI:SQLite:" . ($filename // $ENV{TRSRDB_SQLITE_FILE} // ":memory:"), "", "", { sqlite_unicode => 1, on_connect_call => 'use_foreign_keys', diff --git a/t/schema.out b/t/schema.out index 5e0f26d..f2fd0b1 100644 --- a/t/schema.out +++ b/t/schema.out @@ -9,9 +9,9 @@ john: 0 +0 0 Club: 0 +0 -16250 alex: 7200 +16250 0 # Some updates and deletes that could, unless denied, destroy consistency ... -Error: near line 409: paid is set and adjusted automatically according to added Transfer records -Error: near line 410: Debt is involved in transfers to revoke at first -Error: near line 411: FOREIGN KEY constraint failed +Error: near line 41: paid is set and adjusted automatically according to added Transfer records +Error: near line 42: Debt is involved in transfers to revoke at first +Error: near line 43: FOREIGN KEY constraint failed # After revoking transactions, you are free to change or delete debts and credits ... Club: 7200 +0 0 alex: 0 +0 0 diff --git a/t/schema.sh b/t/schema.sh index c3f58a0..87397d9 100644 --- a/t/schema.sh +++ b/t/schema.sh @@ -1 +1,4 @@ -diff t/schema.out <(cat {,t/}schema.sql | sqlite3 2>&1) +echo "My database file: $1" +if sqlite3 $1 < schema.sql; then + diff t/schema.out <(sqlite3 $1 < t/schema.sql 2>&1) +fi diff --git a/t/schema.t b/t/schema.t index d0c97a7..a13b33f 100644 --- a/t/schema.t +++ b/t/schema.t @@ -1,7 +1,7 @@ use strict; my $db; -use TrsrDB \$db => 'trsr.db'; +use TrsrDB \$db => $ENV{TRSRDB_SQLITE_FILE}; use Test::More; $db->resultset("Account")->create({ ID => "Club", altId => 1, type => 'eV' }); diff --git a/test.sh b/test.sh index c021a92..96a9eff 100755 --- a/test.sh +++ b/test.sh @@ -1,5 +1,20 @@ #!/bin/bash -source t/schema.sh + +abort () { + echo Database not deleted. + exit ${1:-1} +} + +db=$(mktemp -t trsr-XXXXXXXXX.db); +bash t/schema.sh $db if [ $? == 0 ]; then echo Tests passed. +else abort +fi + +> $db; sqlite3 $db < schema.sql +export TRSRDB_SQLITE_FILE=$db +if prove -r t; then + rm $db +else abort $? fi