in reply to Re^5: Makefile.PL even weirder on Windows
in thread Makefile.PL even weirder on Windows

My test file, now named t/test.t, by default prints the "ok" lines (only) for the benifit of Test::Harness. But I can run it with the -verbose switch to get trace statements and dumps of structures so I can see what's happening, or with -quiet which just gives me a one line "all tests passed" (or the fail statements). So when developing, I run t/perl test.t -verbose. Turns out the makefile runs Test::Harness from the same directory (that contains the makefile) anyway, or maybe it's whatever the current directory was without changing anything specifically. So my quick and dirty solution is to add 't' to the @INC if it exists, and if not it assumes its being run from its own directory. Hmm, will perl complain about things in @INC that don't really exist? Maybe I could skip the conditional.

I seem to remember a module that gets the script's directory, for just such a purpose. Maybe I'll find that.

—John

Replies are listed 'Best First'.
Re^7: Makefile.PL even weirder on Windows
by adrianh (Chancellor) on Jan 14, 2003 at 21:23 UTC

    I've just had a quick look at your test.t from Exporter-VA-1.2.3. Annoying comments/suggestions follow. Feel free to ignore :-)

    I would strongly consider using Test::More and Test::Builder. It handles all the book keeping on test headers, footers and exit values for you. Implementing verbose and vv with Test::Builder is trivial.

    You don't need the "#" after the "ok" and "not out" outputs. Currently the "#" character is used to indicate special kinds of test failure/success ("# skip" & "# TODO" tests). While Test::Harness copes happily with the "#" in other circumstances I would avoid it unless you are dealing with one of these special cases - just for the sake of clarity.

    Consider testing the environment variable TEST_VERBOSE as well as your -verbose flag. That way you can do make test TEST_VERBOSE=1 to get your debug code.

    The case when the code passed to verify dies should cause a failed test, rather than a printed error message. Conceptually the test (does this code produce this result) has failed.

    Matter of personal style, but I would do:

    { package C1; use M1 v1.0 qw/--verbose_import &foo bar baz quux bazola + $ztesch --dump/ } verify "C1::foo (5)", "Called M1::foo (5)."; ...

    instead of

    package C1; use M1 v1.0 qw/--verbose_import &foo bar baz quux bazola $ztesch --dum +p/; sub verify; *verify= \&main::verify; verify "C1::foo (5)", "Called M1::foo (5)."; ...

    to save having to alias verify into each module.

      Thanks for your comments.

      The case when the code passed to verify dies should cause a failed test, rather than a printed error message.

      Ah, good catch.

      You don't need the "#" after the "ok" and "not out" outputs

      I guess I misunderstood the directions, then. I thought it was for a comment after the formal part. So it just ignores everything after the /(not )?ok( \d+)/ and I can put my commentary right there, or after some other separator like a dash?

      I would strongly consider using Test::More

      After reading the articles on testing, I went to the docs on Test::More and it said

      STOP! If you're just getting started writing tests, have a look at Test::Simple first. This is a drop in replacement for Test::Simple which you can switch to once you get the hang of basic testing.
      I suppose I made it to that point, now?

      Consider testing the environment variable TEST_VERBOSE

      Good idea. I suppose that's what most people do, so they can just use n?make test and not have to run the script in another manner.

      ...to save having to alias verify into each module.

      Ah! Since I need to qualify everything anyway (since it's eval'ed elsewhere), there is no point to having the code lexically in the scope of that module! I missed that, thanks to the organic nature of "growing" rather than planning the script.

      —John

        So it just ignores everything after the /(not )?ok( \d+)/ and I can put my commentary right there, or after some other separator like a dash?

        Yup. from Test::Harness docs:

        test names Anything after the test number but before the # is considered to be the name of the test. ok 42 this is the name of the test Currently, Test::Harness does nothing with this infor- mation.
        I suppose I made it to that point, now?

        Yup. Your ready for Test::More :-)

        Here's a quick re-write of your test script in the Test::More idiom.

        Hopefully this comes across as simpler than the original :-)

Re^7: Makefile.PL even weirder on Windows
by Aristotle (Chancellor) on Jan 15, 2003 at 01:10 UTC
    I seem to remember a module that gets the script's directory, for just such a purpose.

    You're probably thinking of FindBin - which is broken.

    Perl doesn't complain about nonexisting directories in @INC, no.

    You could check for the existence of your test modules with something like -f "./$foo" or -f "t/$foo" and bail if you can't find either.

    Makeshifts last the longest.