Skip to content

Commit

Permalink
Merge pull request #73 from ajolma/issue_61_test_dirs
Browse files Browse the repository at this point in the history
Tests: use Test::TempDir::Tiny and Path::Tiny
  • Loading branch information
shawnlaffan authored Jun 11, 2024
2 parents 9a4b588 + 278c1e1 commit c2e9a63
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/linux_bin_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ jobs:
cpanm --notest Test::Exception
cpanm --notest JSON
cpanm --notest PDL
cpanm --notest Path::Tiny
cpanm --notest Test::TempDir::Tiny
- name: Build
run: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/linux_share_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ jobs:
cpanm --notest local::lib
echo $(perl -Mlocal::lib=${HOME}/perl5)
eval "$(perl -Mlocal::lib=${HOME}/perl5)"
cpanm --notest Path::Tiny
cpanm --notest Test::TempDir::Tiny
cpanm --notest PDL
cpanm --notest Alien::Build
cpanm --installdeps --notest Alien::sqlite
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/linux_sys_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
cpanm --notest local::lib
echo $(perl -Mlocal::lib=${HOME}/perl5)
eval "$(perl -Mlocal::lib=${HOME}/perl5)"
cpanm --notest Path::Tiny
cpanm --notest Test::TempDir::Tiny
cpanm --notest PDL
cpanm --notest Alien::Build
cpanm --installdeps --notest Alien::sqlite
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
- name: Install Dynamic Dependencies
run: |
cpanm --notest Path::Tiny
cpanm --notest Test::TempDir::Tiny
cpanm --notest PDL
cpanm --notest Alien::Build
cpanm --notest Alien::Build::MM
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/macos_share_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
- name: Install Dynamic Dependencies
run: |
cpanm --notest Path::Tiny
cpanm --notest Test::TempDir::Tiny
cpanm --notest PDL
cpanm --notest Alien::Build
cpanm --notest Alien::Build::MM
Expand Down
10 changes: 6 additions & 4 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,12 @@ my %args = (
'Alien::gdal' => 0,
},
TEST_REQUIRES => {
'Test::More' => 0,
'Test::Exception' => 0,
'JSON' => 0,
'Data::Dumper' => 0
'Test::More' => 0,
'Test::Exception' => 0,
'JSON' => 0,
'Data::Dumper' => 0,
'Path::Tiny' => 0,
'Test::TempDir::Tiny' => 0,
},
META_MERGE => {
"meta-spec" => { version => 2 },
Expand Down
9 changes: 6 additions & 3 deletions t/00.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use Encode qw(decode encode);
use Test::More;
use Data::Dumper;
use JSON;
use Test::TempDir::Tiny;
use Path::Tiny qw/path/;

BEGIN { use_ok('Geo::GDAL::FFI', qw/:all/); }

Expand Down Expand Up @@ -286,8 +288,10 @@ if(1){

# test creating a shapefile
if(1){
my $dir = tempdir();
my $testfile = path($dir, 'test.shp');
my $dr = GetDriver('ESRI Shapefile');
my $ds = $dr->Create('test.shp');
my $ds = $dr->Create($testfile);
my @sr = ();
if (FindFile('gcs.csv')) { # should be version checked? GDAL 3 does not use gcs.csv
@sr = (SpatialReference => Geo::GDAL::FFI::SpatialReference->new(EPSG => 3067));
Expand All @@ -297,11 +301,10 @@ if(1){
my $f = Geo::GDAL::FFI::Feature->new($d);
$l->CreateFeature($f);
undef $l; # otherwise $ds is not flushed due to parent ref
$ds = Open('test.shp');
$ds = Open($testfile);
$l = $ds->GetLayer;
$d = $l->GetDefn();
ok($d->GetGeomType eq 'Point', "Create point shapefile and open it.");
unlink qw/test.dbf test.prj test.shp test.shx/;
}

# test field definitions
Expand Down
6 changes: 5 additions & 1 deletion t/dataset.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ use Geo::GDAL::FFI qw/GetDriver HaveGEOS/;
use Test::More;
use Test::Exception;
use Data::Dumper;
use Test::TempDir::Tiny;
use Path::Tiny qw/path/;

my $ds = GetDriver('GPKG')->Create('test.gpkg');
my $dir = tempdir();
my $gpkg_file = path ($dir, 'test.gpkg');
my $ds = GetDriver('GPKG')->Create($gpkg_file);
my $sr = Geo::GDAL::FFI::SpatialReference->new(EPSG => 3067);
foreach my $i (1..3) {
my $l = $ds->CreateLayer({
Expand Down
8 changes: 6 additions & 2 deletions t/dataset_rasterize.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use warnings;
use Geo::GDAL::FFI;

Check failure on line 5 in t/dataset_rasterize.t

View workflow job for this annotation

GitHub Actions / perl

Compilation failed in require

use Test::More;
use Test::TempDir::Tiny;
use Path::Tiny qw/path/;

local $| = 1;

Expand Down Expand Up @@ -165,8 +167,10 @@ sub test_Rasterize {


sub get_test_raster {
my $name = 'test_ras' . (time() + rand()) . '.tiff';
my $tiff = Geo::GDAL::FFI::GetDriver('GTiff')->Create('test.tiff', 3, 2);
my $dir = tempdir();
# my $name = 'test_ras' . time() + rand() . '.tiff';
my $tiff_file = path ($dir, 'test.tiff');
my $tiff = Geo::GDAL::FFI::GetDriver('GTiff')->Create($tiff_file, 3, 2);
my $ogc_wkt =
'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS84",6378137,298.257223563,'.
'AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,'.
Expand Down
13 changes: 8 additions & 5 deletions t/open.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ use Test::More;
use Data::Dumper;
use JSON;
use FFI::Platypus::Buffer;
use Path::Tiny qw/path/;
use Test::TempDir::Tiny;

my $dir = tempdir();
my $testfile = path($dir, 'test.shp');

{
my $ds = GetDriver('ESRI Shapefile')->Create('test.shp');
my $ds = GetDriver('ESRI Shapefile')->Create($testfile);
my $sr = Geo::GDAL::FFI::SpatialReference->new(EPSG => 3067);
my $l = $ds->CreateLayer({Name => 'test', SpatialReference => $sr, GeometryType => 'Point'});
my $d = $l->GetDefn();
Expand All @@ -21,7 +26,7 @@ use FFI::Platypus::Buffer;
my $ds;

eval {
$ds = Open('test.shp', {
$ds = Open($testfile, {
Flags => [qw/READONLY VERBOSE_ERROR/],
AllowedDrivers => [('GML')]
});
Expand All @@ -31,13 +36,11 @@ $e[0] =~ s/ at .*//;
ok($@, "Right driver not in AllowedDrivers: ".$e[0]);

eval {
$ds = Open('test.shp', {
$ds = Open($testfile, {
Flags => [qw/READONLY VERBOSE_ERROR/],
AllowedDrivers => [('GML', 'ESRI Shapefile')]
});
};
ok(!@$, "Require right driver in AllowedDrivers");

unlink qw/test.dbf test.prj test.shp test.shx/;

done_testing();

0 comments on commit c2e9a63

Please sign in to comment.