Testing framework: extend comparison
Motivation and Context
It was reported in #ligo that in the context of the testing framework, variant (sum) types could not be compared for something different of equality/non-equality.
Description
This MR updates the comparison (apply_comparison
) in interpreter.ml
. Instead of relying in compare_value
from Ligo_interpreter
stage, we directly re-implement comparison at this point (they have different usages).
We change the output of apply_comparison
from value t
to int
. We rely on raise
to signal failure. This allows us to use standard List.sort
and similar (otherwise it wouldn't work as recursive calls are guarded with t
monad, and binds should be applied).
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Performance improvement (non-breaking change that improves performance) -
None (change with no changelog)
Changelog
The comparison functions (<
, <=
, etc.) now can work with variant types.
Example
Given the file test_compare.mligo
:
type c = [@layout:comb] | B of int | A of string
type cl = c list
let test_cmp_list = Test.assert ([A "hello" ; A "bye"] > [A "hello" ; B 42])
Before this change
$ ligo run test test_compare.mligo
File "test_compare.mligo", line 4, characters 33-75:
3 |
4 | let test_cmp_list = Test.assert ([A "hello" ; A "bye"] > [A "hello" ; B 42])
"Not comparable"
After this change
$ ligo run test test_compare.mligo
Everything at the top-level was executed.
- test_cmp_list exited with value ().
Checklist:
-
Changes follow the existing coding style (use dune @fmt
to check). -
Tests for the changes have been added (for bug fixes / feature). -
Documentation has been updated. -
Changelog description has been added (if appropriate). -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by E. Rivas