Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Introspecting function signatures

by szabgab (Priest)
on Mar 05, 2021 at 21:29 UTC ( [id://11129173]=note: print w/replies, xml ) Need Help??


in reply to Re: Introspecting function signatures
in thread Introspecting function signatures

Thanks, this is what I was playing with: perltest. I would need the introspection of the function signatures to be able to provide dependency injection. Any suggestion in that direction? Specifically the run function. Would any of the modules that provide signature be a better idea?
  • Comment on Re^2: Introspecting function signatures

Replies are listed 'Best First'.
Re^3: Introspecting function signatures
by dave_the_m (Monsignor) on Mar 05, 2021 at 22:03 UTC
    I had a quick glance at that repo, and have no idea what it does apart from the fact that it's supposed to be similar to Pytest, about which I know nothing. So could you explain further the use case?

    Dave.

      It is an experiment to write a module to allow you to write tests like this:
      sub test_someting($tempdir) { ... }
      The test harness runs all the individual test_something functions. If the function has arguments that it will prepare the appropriate object and call the function passing those objects into the function. The example I created was injecting a $tempdir object, but, once the system is ready, you could write and register your own objects. In Pythest these are called fixtures, and they mostly act test fixtures. (In Pytest there are a few other ready-made such fixtures, for example one that captures stdout/stderr, and one that can mock methods, attributes, etc.)

      If you look at the modules in the t/ directory, those are all examples on how to use the module to write tests.

        Is there a reason why they need to be available as parameters at all? These fixtures could just be global variables, couldn't they?

        I may have trouble understanding the full intention.... please help me:

        You want to parse

        sub test_someting($tempdir) { # do some tests }

        And because you see the (registered) keyword "tempdir" your test system is supposed to call this test with a prepared temporary directory?

        ok( test_something( create_tempdir() ), "something", )

        Kind of a naming convention?

        Did I get it right?

        If yes, I could think of some alternative (and more perlish) ways to achieve this without needing to parse the signature.

        PS: not sure why you call this "dependency injection" or do you plan testruns where the injected $tempdir is not a temporary dir? :)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129173]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2025-02-08 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (95 votes). Check out past polls.