-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat: implement io.popen #88
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems almost it. Apart from the mode validation I think there is another issue to figure out: what happens when the file is closed? A simple test in lua 5.4 gives this:
> f = io.popen("echo foo")
> f
file (0x21021ac10)
> f:close()
true exit 0
> f
file (closed)
What happens in Golua? Given there is no real file handle backing up the File instance I think things may go wrong here.
A few tests would be good also, best if they could be cross-platform.
Codecov ReportBase: 89.05% // Head: 88.82% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## lua5.4 #88 +/- ##
==========================================
- Coverage 89.05% 88.82% -0.24%
==========================================
Files 104 104
Lines 11122 11233 +111
==========================================
+ Hits 9905 9978 +73
- Misses 921 949 +28
- Partials 296 306 +10
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
an idea for handling file operations on popen is that i could add the cmd to iolib.File and add specific functions for that. what do you think? also how do i improve coverage... by writing the lua tests? |
It depends on the behaviour that popen implements I think. It's not really specified in the Lua docs afaict so it might be a matter of testing it in Lua (or looking at the code). Go's
Yes :). I am not very familiar with windows but perhaps the windows shell implements |
close on popen returns the process' status (same returns as os.execute) so i don't think it'll be enough |
Yeah I just had a quick look at C Lua, Lua file objects contain a callback for closing the file. In the case of files opened by |
fixed. tested in hilbish
|
now just the other functions, and tests |
for tests i just copy pasted already available ones (but only 2 suites) |
ok i'm not sure why tests are failing and how wait is blocking |
I think the test
should be
You want to write to the process, not read from it. I might have some time to look at it tomorrow. |
no it's the popen write test ( |
As a sanity check I wrote this little Go program: func main() {
cmd := exec.Command("/bin/sh", "-c", "cat > foo.txt")
stdin, _ := cmd.StdinPipe()
fmt.Println("Starting cat...")
cmd.Start()
go func() {
fmt.Println("Sending greeting...")
fmt.Fprintln(stdin, "Hello from test")
fmt.Println("Waiting 5s...")
time.Sleep(5 * time.Second)
fmt.Println("Closing stdin...")
stdin.Close()
}()
fmt.Println("Waiting for cat to exit...")
cmd.Wait()
fmt.Println("Done")
} That terminates fine, and suggests that |
weirdly, not using a type assert and just storing the stdout/stdin pipe makes it work from my side. now we should be good |
Co-authored-by: Arnaud Delobelle <arnodel@gmail.com>
anything else to fix/improve? i'm not sure how to improve the coverage; what else to test |
If you could just disable the failing test on windows, then I'll merge it. Don't worry about test coverage atm |
oh how do i do that |
does that work? |
Sadly that doesn't work because the expected results are not conditional. I should have some time tomorrow so hopefully I can figure out something to help with that. |
I added a feature to help with this: 41f7e93 You should be able to put the tests that fail on windows in a file e.g.
It will only run this lua test file on non-windows platforms HTH Edit: this commit is on the default branch (lua5.4) Edit 2: the working commit is 8cf7d84 |
like that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that looks good, thank you. Windows tests are still failing though (see comments). I do not have a windows environment to test in, so I don't have any suggestions why they are not working. If you can't debug the issue either and you don't need a windows implementation we could always disable popen on windows for now? I think it would be better than to have a broken implementation.
--> ~^false\t.*invalid format | ||
|
||
|
||
for line in f:lines() do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is not finding any lines in windows (see e.g. test failure at https://github.com/arnodel/golua/runs/6722468583?check_suite_focus=true#step:4:35)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does that even make sense
i wanna have popen on windows at least, but this is infuriating edit: i do have a windows install but it is excruciatingly slow and i would rather not use it |
I can try to find a way forward, but it probably won't be very quick as it means getting a windows environment. |
that's fine, i won't be able to do much because of school finals |
hello? |
Sorry I haven't got round to provisioning a windows machine yet. Hopefully
I get some time soon.
…On Tue, 21 Jun 2022 at 01:22, sammyette ***@***.***> wrote:
hello?
—
Reply to this email directly, view it on GitHub
<#88 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAMJKONPFLIZUYMDYVGKWBDVQEDM3ANCNFSM5W6Z4B4Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Update: I only have an apple silicon mac at the moment and it appears to be tricky to run windows on it - so far no luck so I'll need to get another way to have access. |
been a while huh i'm on windows myself now and it seems to actually be decent so i can try testing to fix the issue |
the path needed a backward slash yeah that makes sense |
ya good? didnt want to poke, but it's been 4 months so whats happening |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only change I would request before merging is to update the README.md file which currently marks popen
as unimplemented.
like that? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's going in
as of writing, the pr only adds the popen function; iolib.File is untouched.is there anything else i need to add here, like tests? also how should i actually handle file options, or is it fine as-is?
closes #7