dodona-edu / universal-judge

Universal judge for educational software testing
https://docs.dodona.be/en/tested
MIT License
9 stars 4 forks source link

Enable definitions blocks in DSL for YAML anchor/alias/merge #441

Closed niknetniko closed 9 months ago

niknetniko commented 9 months ago

This PR enables a new object called definitions that can be used to define stuff and use it later:

- unit: 'Sum of three cubes'
  definitions:
    sum_of_three: &sum_of_three
      oracle: 'custom_check'
      language: 'python'
      name: 'sum_of_three_cubes'
      file: 'oracle.py'
   a_value: &string_value "some string"
  testcases:
    - stdin: '3'
      stdout:
        <<: *sum_of_three
        data: |
          1
          1
          1
    - stdin: '33'
      stdout: *string_value
    - stdin: '42'
    - stdout:
        <<: *sum_of_three
        data: |
          -80538738812075974
          80435758145817515
          12602123297335631

This is done by using three YAML features:

For example, this below will merge all attributes of the sum_of_three object with the stdout object:

stdout:
  <<: *sum_of_three
  data: "example"

The example below is an alias: the stdout object will be the same as the sum_of_three object:

stdout: *sum_of_three

Since this is purely YAML, you could also anchor the first use, instead of using the definitions object.

To be consistent, this PR also removes our own "inheritance" support for config values. The support for files is kept for now, as merging lists is not possible in a somewhat standard way (but we could introduce support for it with a custom tag at some point).

Closes #394.