kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.61k stars 113 forks source link

[Enhancement] The KCL testing tool supports testing incorrect failure cases, such as schema check conditions using the runtime.catch function #1385

Closed Peefy closed 3 months ago

Peefy commented 4 months ago

For exampla

schema Name:
    count: int

    check:
        count > 10
import runtime

test_name_schema_failed = lambda {
    assert "Schema check failed" in runtime.catch(lambda {Name{count: 10}}
}
Wck-iipi commented 4 months ago

@Peefy Can I work on this issue?

Wck-iipi commented 4 months ago

@Peefy I tried kcl test after building kcl but none of the subcommands with kcl are currently working. I am currently on MacOS 14.5. The only subcommands that I am being shown are run, server, version and help.

image

Even the make doesn't show any errors.

image

Below is my zshrc file which has set kcl as alias for kclvm_cli.

image

Moreover, even testing package cannot be imported.

image

Any idea why I can't see any subcommands or I cannot import testing? Have I not installed something? Thanks for the help.

Peefy commented 4 months ago

Hello @Wck-iipi.

You can install full KCL CLI from https://github.com/kcl-lang/cli and prevent alias kcl

Wck-iipi commented 4 months ago

@Peefy, But it cannot still find testing.

image
Peefy commented 4 months ago

@Wck-iipi

The content I wrote in the issue is the expected functionality rather than the existing functionality.

Wck-iipi commented 4 months ago

@Peefy Thanks for responding. Could you tell me where I have to write this catch_err code at? Would it be at /tools/src/testing? I am a little confused with the implementation. Also, when I finally create the catch_err function, how would user use that function?

Peefy commented 4 months ago

I think that we need to achieve two things here.

  1. Implement the testing system module and add some functions to assist in unit testing.
  2. Implement a compiler runtime plugin that can capture erroneous exceptions to prompt users.
  3. recover function from the runtime panic like go and rust.

Furthermore, this is not a simple function that requires a design solution first and then implementation.

Wck-iipi commented 4 months ago

@Peefy Could you give me some references that would tell me more about this(like some PR where you have created/modified compiler runtime plugin or testing system module)? Because upon searching import testing, I came across some examples like this, which is useful, but I would like if you could guide me more. Thanks.

Peefy commented 4 months ago

You can try impl runtime panic recovery like go and rust. 😃