Skip to content

Tests contain non-functional -d "lib" boilerplate code #5

@mauke

Description

@mauke

I saw this sort of setup in all test files in this distribution:

BEGIN {
   if (-d "lib") {
      use lib "./lib";
   } elsif (-d "../lib") {
      use lib "../lib";
   }
}

This makes no sense because use executes at compile time, so this code is equivalent to:

BEGIN {
   use lib "./lib";
   use lib "../lib";
   if (-d "lib") {
   } elsif (-d "../lib") {
   }
}

In other words, this whole block could be replaced by use lib "./lib", "../lib"; without changing its functionality.

On the other hand, a working -d check could be implemented as

BEGIN {
    require lib;
    if (-d "lib") {
        lib->import("./lib");
    } elsif (-d "../lib") {
        lib->import("../lib");
    }
}

or simply

use lib (
    -d "lib" ? "./lib" :
    -d "../lib" ? "../lib" :
    ()
);

or perhaps even

use lib grep { -d } qw(./lib ../lib);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions