Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print function is broke #1535

Closed
liangyuanpeng opened this issue Aug 2, 2024 · 3 comments
Closed

Print function is broke #1535

liangyuanpeng opened this issue Aug 2, 2024 · 3 comments

Comments

@liangyuanpeng
Copy link
Contributor

liangyuanpeng commented Aug 2, 2024

cc @Peefy @He1pa
Now, Print is not working, and i found the tests for print seems like all disabled:

NOTE: i have check the cli, kpm and kcl-go, i believe that the problem is kcl-lang/kcl
I have enable this test and then failed.

=================================== FAILURES ===================================
_ test_grammar[/home/runner/work/kcl/kcl/test/grammar/builtins/default/print/hello_world] _
[gw0] linux -- Python 3.10.12 /usr/bin/python3

test_dir = '/home/runner/work/kcl/kcl/test/grammar/builtins/default/print/hello_world'

    @pytest.mark.parametrize("test_dir", test_dirs)
    def test_grammar(test_dir):
        print("Testing {}".format(test_dir))
        test_settings = read_settings_file(os.path.join(test_dir, SETTINGS_FILE))
        kcl_command = ["kclvm_cli", "run", TEST_FILE]
        if test_settings and test_settings["kcl_options"]:
            kcl_command.extend(test_settings["kcl_options"].split())
        process = subprocess.Popen(
            kcl_command,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            cwd=os.path.abspath(test_dir),
            env=dict(os.environ),
        )
        stdout, stderr = process.communicate()
        print("STDOUT:\n{}".format(stdout.decode()))
        print("STDERR:\n{}".format(stderr.decode()))
        # Attempt to use existing golden stdout.
        try:
            with open(
                os.path.join(test_dir, STDOUT_GOLDEN), "r"
            ) as golden_file:
>               compare_results_with_lines(stdout, golden_file)

test_grammar.py:138: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
test_grammar.py:64: in compare_results_with_lines
    compare_strings(result_strings, golden_strings)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

result_strings = ['Hello, World!', '{}', '']
golden_strings = ['Hello, World!', '']

    def compare_strings(result_strings: list, golden_strings: list):
        result = "\n".join(result_strings)
        golden_result = "\n".join(golden_strings)
        result_yaml_list = [r for r in list(ruamel_yaml.load_all(result)) if r]
        golden_yaml_list = [r for r in list(ruamel_yaml.load_all(golden_result)) if r]
>       assert result_yaml_list == golden_yaml_list
E       AssertionError: assert ['Hello, World! {}'] == ['Hello, World!']
E         
E         At index 0 diff: 'Hello, World! {}' != 'Hello, World!'
E         
E         Full diff:
E           [
E         -     'Hello, World!',
E         +     'Hello, World! {}',
E         ?                   +++
E           ]

test_grammar.py:38: AssertionError
----------------------------- Captured stdout call -----------------------------
Testing /home/runner/work/kcl/kcl/test/grammar/builtins/default/print/hello_world
STDOUT:
Hello, World!
{}

STDERR:

=========================== short test summary info ============================
FAILED test_grammar.py::test_grammar[/home/runner/work/kcl/kcl/test/grammar/builtins/default/print/hello_world] - AssertionError: assert ['Hello, World! {}'] == ['Hello, World!']
  
  At index 0 diff: 'Hello, World! {}' != 'Hello, World!'
  
  Full diff:
    [
  -     'Hello, World!',
  +     'Hello, World! {}',
  ?                   +++
    ]

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

2. What did you expect to see? (Required)

3. What did you see instead (Required)

4. What is your KCL components version? (Required)

@Peefy
Copy link
Contributor

Peefy commented Aug 2, 2024

cc @zong-zhe

I think bug is involved in this refactor issue and forget to set the logger to os.Stdout

kcl-lang/cli#105

@liangyuanpeng
Copy link
Contributor Author

liangyuanpeng commented Aug 2, 2024

@Peefy you are right!

const code = `
import kcl_plugin.hello

name = "kcl"
sum = hello.add(option("a"), option("b"))
+++print("hello world")
`

func TestNativeRun(t *testing.T) {
---	yaml := MustRun("main.k", WithCode(code), WithOptions("a=1", "b=2")).GetRawYamlResult()
+++	yaml := MustRun("main.k", WithCode(code), WithLogger(os.Stdout), WithOptions("a=1", "b=2")).GetRawYamlResult()
	fmt.Println(yaml)
}

At the sdk-go level, I thought Stdout was used as the logger by default.

@Peefy
Copy link
Contributor

Peefy commented Aug 5, 2024

Closed by kcl-lang/kpm#428 and kcl-lang/cli#122

@Peefy Peefy closed this as completed Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants