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

Remove unneeded visit_expr() and fix stdin #3694

Merged
merged 2 commits into from
Mar 24, 2024

Conversation

Shaikh-Ubaid
Copy link
Member

and get back stdin read working.

% lfortran examples/chat_01.f90 
Please enter your name:
Joe
---------WELCOME TO CHAT_01---------
Please pick an option:
1) Say Hi
2) Say Hello
3) Say Good Morning
4) Say Happy Birthday
5) Exit the chat

Enter your choice:
1
Hi Joe

Please pick an option:
1) Say Hi
2) Say Hello
3) Say Good Morning
4) Say Happy Birthday
5) Exit the chat

Enter your choice:
2
Hello Joe

Please pick an option:
1) Say Hi
2) Say Hello
3) Say Good Morning
4) Say Happy Birthday
5) Exit the chat

Enter your choice:
3
Good Morning Joe

Please pick an option:
1) Say Hi
2) Say Hello
3) Say Good Morning
4) Say Happy Birthday
5) Exit the chat

Enter your choice:
4
Happy Birthday Joe!

Please pick an option:
1) Say Hi
2) Say Hello
3) Say Good Morning
4) Say Happy Birthday
5) Exit the chat

Enter your choice:
5

@Shaikh-Ubaid
Copy link
Member Author

This was discovered in lcompilers/lpython#2601 (comment).

@Shaikh-Ubaid Shaikh-Ubaid marked this pull request as ready for review March 24, 2024 14:09
@Shaikh-Ubaid
Copy link
Member Author

@certik how should we add a test for this to ensure it does not break in future?

@Shaikh-Ubaid
Copy link
Member Author

I am merging this as the changes seem trivial. I think we can add the test in a separate PR.

@Shaikh-Ubaid Shaikh-Ubaid merged commit 94863c9 into lfortran:main Mar 24, 2024
21 checks passed
@Shaikh-Ubaid Shaikh-Ubaid deleted the remove_unneeded_visit_expr branch March 24, 2024 14:12
@certik
Copy link
Contributor

certik commented Mar 24, 2024

Thanks! I saw that it failed too yesterday.

@Shaikh-Ubaid
Copy link
Member Author

@certik how should we add a test for this to ensure it does not break in future?

Do you know/suggest any approach to test this?

@certik
Copy link
Contributor

certik commented Mar 24, 2024

Can the input in be tested using a bash script that feeds the input on stdin?

@Shaikh-Ubaid
Copy link
Member Author

Can the input in be tested using a bash script that feeds the input on stdin?

We can simply redirect the input stream to a file using < in a bash script. For example:

% cat expr2.f90
program expr2
implicit none

    character(len = 10) :: name

    print *, "Name:"
    read(*, *) name

    print *, "Name: ", name
    if (name /= "Joe") error stop

end program
% cat tmp.txt  
Joe
% cat test.sh  
#!/usr/bin/env bash

lfortran expr2.f90 -o expr2
./expr2 < tmp.txt
% ./test.sh 
Name:
Name: Joe
% echo $?
0

@certik
Copy link
Contributor

certik commented Mar 24, 2024

Let's add a cmake test for this, a new category/label, and in cmake pass in the input to stdin, and ensure it fails if there is a bug like it was before this PR.

@Shaikh-Ubaid Shaikh-Ubaid changed the title Remove unneeded visit expr Remove unneeded visit_expr() and fix stdin Apr 15, 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

Successfully merging this pull request may close these issues.

None yet

2 participants