https://kotlinlang.org logo
Join Slack
Powered by
# parameterize
  • b

    Ben Woodworth

    10/11/2023, 1:01 PM
    set the channel description: https://github.com/BenWoodworth/parameterize
  • b

    Ben Woodworth

    10/11/2023, 1:18 PM
    set the channel description: https://github.com/BenWoodworth/parameterize
  • b

    Ben Woodworth

    10/11/2023, 1:18 PM
    set the channel topic: Discussion around Parameterize, a library that brings a concise syntax for parameterizing code
  • b

    Ben Woodworth

    11/06/2023, 9:51 PM
    @CLOVIS @mbonnin I just pushed out an initial v0.1.0 release, and looks like it's already synced to maven central :) Won't make a general announcement just yet since I have a busy week ahead of me and won't have much time to answer questions or address issues from the masses. But feel free to poke around, give it a try, and leave some feedback here!
    👍 2
  • c

    CLOVIS

    11/06/2023, 11:09 PM
    Do you plan on implementing pre-made lists of parameters? For example, in the Kotest documentation: https://kotest.io/docs/proptest/property-test-generators.html
    b
    • 2
    • 8
  • c

    CLOVIS

    11/08/2023, 10:04 AM
    From what we discussed the other day, currently Parametrize works by evaluating the lambda a first time, in which it receives the first value of each option, and schedules another evaluation because it knows some other combination has not been tested yet.
    Copy code
    parametrize {
        val letter by parameter(…)
    
        // …executes X times…
    }
    However, many test frameworks require to be able to discover all tests before executing them. For Prepared, I would require a way to declare all parameters that can be executed once before executing any test, only to register the possible cases.
    Copy code
    suite("My test suite") {
        parametrize {
            val letter by parameter(…)
    
            test("Some dummy test for $letter") {
                letter.uppercase() shouldNotBe letter
            }
        }
    }
    Do you think it is possible to get this behavior with your library? Maybe by using a different
    parametrize
    function but the same
    parameter
    functions? Additionally, my library has an additional concept to allow declaring suspend test fixtures without evaluating them: prepared values. Ideally, I'd like parametrized values to be compatible with this pattern as well. What do you think?
    b
    • 2
    • 28
  • c

    CLOVIS

    11/09/2023, 1:40 PM
    Apparently I have the right to add links at the top of the channel, so I added your repository (feel free to rename it)
    💙 1
    b
    • 2
    • 1
  • c

    CLOVIS

    12/21/2023, 10:00 PM
    Hey! Sorry it took so long. I created a very quick outline of what I was thinking about: https://github.com/BenWoodworth/Parameterize/pull/23 I tried to comment on my current thought process and what's challenging. Whenever you get some time to look at it, please tell me what you think 🙂
    b
    • 2
    • 10
  • c

    CLOVIS

    12/31/2023, 11:48 AM
    Apologies in advance, this is going to be a stupid question. You mentioned you published 0.3.0-SNAPSHOT somewhere. What's the URL for the Maven repo? I can't find it anywhere 😐
    b
    • 2
    • 8
  • c

    CLOVIS

    12/31/2023, 1:36 PM
    I was going to create a compatibility module in Prepared for Parameterize, but… it just works. The simplest example looks like:
    Copy code
    preparedSuite {
    	parameterize {
    		val text by parameterOf("123456", "hello64")
    		val int by parameterOf(4, 6)
    
    		test("Prepared $text $int") {
    			(int.toString() in text) shouldBe true
    		}
    	}
    }
    When combined with prepared values, it looks like:
    Copy code
    parameterize {
    	val first by prepared { 1.toString() }
    	val second by prepared { 2.toString() }
    	val int by parameterOf(first, second)
    
    	test("Lazy test for value $int") {
    		(int() in "123456789") shouldBe true
    	}
    }
    It's a bit verbose, but it works.
    👀 1
    ❤️ 1
    b
    • 2
    • 16
  • c

    CLOVIS

    01/01/2024, 10:23 AM
    W.r.t licensing; I see Parameterize is GPL3.0. This is a bit inconvenient, because it means it can't be depended on by open source projects (Apache 2.0, MIT…). Is there any particular reason you chose this license?
    👀 2
    ➕ 1
    b
    m
    • 3
    • 13
  • c

    CLOVIS

    01/09/2024, 10:03 PM
    Looking at the algorithm, values are re-computed on each iteration, right? Prepared has a value called `Shared` which is essentially a global shared value between multiple tests. It emulates what
    @BeforeTest
    would be in other frameworks. If I write something like the following, then it looks like the values are re-created on each iteration.
    b
    • 2
    • 14
  • c

    CLOVIS

    01/09/2024, 10:05 PM
    In theory I have set up my emails to be notified when you release 0.3.0, but just in case could you ping me here when it happens? 🙏
    b
    • 2
    • 4
  • c

    CLOVIS

    01/11/2024, 2:40 PM
    Do you plan on providing ready-made parameter lists? For example, something like
    Copy code
    parameterize {
        val number by any<Int>()
    }
    If not, I'll probably create a small helper on my side to import Kotest's
    Arb
    etc
    b
    • 2
    • 4
  • c

    CLOVIS

    02/15/2024, 3:33 PM
    It took me some time, but I finally have a Prepared version with Parameterize: https://gitlab.com/opensavvy/prepared/-/releases/1.0.0-rc.1
    b
    • 2
    • 6
  • c

    CLOVIS

    02/24/2024, 1:10 PM
    I really appreciate how much it makes even the simplest example more readable. Before/after below.
    b
    • 2
    • 4
  • b

    Ben Woodworth

    02/29/2024, 10:00 PM
    Just released v0.3, featuring many changes towards improving overall flexibility (including licensing, with Apache 2.0)! 👀 Also check out the readme, because I re-wrote a lot of it to provide clearer examples, and hopefully give a clearer understanding of how Parameterize works and what it can be useful for. Feedback is welcome! 😊 https://github.com/BenWoodworth/Parameterize/releases/tag/v0.3.0
    c
    • 2
    • 2
  • c

    CLOVIS

    03/02/2024, 11:28 AM
    It's a small thing, but I really like the way you write the changelog, I may take some inspiration from it. Especially the binary/source/behavior compatibility sections.
    ❤️ 1
    b
    • 2
    • 2
  • c

    CLOVIS

    06/23/2024, 2:22 PM
    Hey! I'm currently adding WASM support to my libraries. Since Kotlin 2.0.0, it's become as simple as:
    Copy code
    import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
    
    @OptIn(ExperimentalWasmDsl::class)
    kotlin {
        …
        wasmJs {
    		browser()
    		nodejs()
    	}
        wasmWasi {
            nodejs()
        }
    }
    since WASM is finally in stable versions of NodeJS. Since Parameterize is pure common code, it should be as simple as that.
    b
    • 2
    • 3
  • c

    CLOVIS

    07/31/2024, 10:35 AM
    I would be interested in having direct support for Kotest Property Testing. Here are a few ideas of how it could look like:
    Copy code
    val int1 by parameterOf(1, 2, 3, 4, 5)
    val int2 by parameter(<http://Arb.int|Arb.int>(), 1000)         // accept Arb instances with a number of samples (maybe with a default value?)
    val int3 by parameter(<http://Exhaustive.int|Exhaustive.int>(0..128))  // accept Exhaustive instances without requiring a number of samples
    Here are a few examples of how these could be used:
    Copy code
    // Kotest syntax
    checkAll<Int, String> { i, s ->
        foo(i, s)
    }
    
    // Parameterized syntax
    parameterize {
        val i by parameter(<http://Arb.int|Arb.int>(), 100)
        val s by parameter(Arb.string(), 150)
        foo(i, s)
    }
    Copy code
    // Kotest syntax
    val person = Arb.bind(
        Arb.string(),
        <http://Arb.int|Arb.int>(),
    ) { s, i -> Person(s, i) }
    …
    
    // Parameterized syntax
    parameterize {
        val s by parameter(Arb.string(), 100)
        val i by parameter(<http://Arb.int|Arb.int>(), 100)
        val person = Person(s, i)
        …
    }
    If this is added, there should be a way to specify the seed without explicit code by the user. For example, Prepared includes seed management already, and it should be able to inject its configured seed into the
    parameterize
    block (one way or another…) such that the user doesn't have to do it themselves and can't forget it. What do you think? 👀
    b
    • 2
    • 8
  • d

    dave08

    09/18/2024, 11:44 AM
    @Ben Woodworth If I need to write a few test suites in Prepared with one paramterOf for all the suites and some parameterOfs inside each/some suite/s, should I nest parameterize { } blocks for each, or have one around all the suites for both uses?
    b
    c
    • 3
    • 11
  • c

    CLOVIS

    12/24/2024, 9:12 AM
    @Ben Woodworth Is there a way to return a
    Sequence
    out of a
    parameterize
    block? Basically, use each run as a sequence generator If so, you may want to advertise your stuff here: https://kotlinlang.slack.com/archives/CQ3GFJTU1/p1735010170520839?thread_ts=1735008576.288699&amp;cid=CQ3GFJTU1
    b
    • 2
    • 8
  • c

    CLOVIS

    03/22/2025, 11:02 AM
    How can I abstract away parameters? Let's take the example of a typical 52 cards game.
    Copy code
    fun ParameterizeScope.allValues() =
        parameter(1..13)
    So, far, easy.
    Copy code
    fun ParameterizeScope.allCards(): Card {
        val suit by parameter(Suit.entries)
        val value by allValues()
        return Card(value, suit)
    }
    Is this safe?
    b
    • 2
    • 1