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

TestApp generation should add necessary imports #267

Closed
yulvil opened this issue Oct 23, 2017 · 6 comments
Closed

TestApp generation should add necessary imports #267

yulvil opened this issue Oct 23, 2017 · 6 comments

Comments

@yulvil
Copy link
Contributor

yulvil commented Oct 23, 2017

Function TestApp does make use of os, ioutil, noarch and testing packages. We should make sure that those imports are always included.

import "io/ioutil"
import "os"
import "testing"
import "github.com/elliotchance/c2go/noarch"

func TestApp(t *testing.T) {
   os.Chdir("../../..")
   ioutil.WriteFile("build/stdin", []byte{'7'}, 0777)
   stdin, _ := os.Open("build/stdin")
   noarch.Stdin = noarch.NewFile(stdin)
   main()
}

It is possible to create trivial programs where the main function do not refer to those imports.

int main() {
    return 97;
}

=> ./main.go:21:2: undefined: noarch

Low priority since any non-trivial C program will import "os" and "noarch".

@elliotchance
Copy link
Owner

TestApp should only be generated under go test. Are you seeing this output from c2go transpile? If you are then this is a bug and OutputAsTest is not false (the default mode): https://github.com/elliotchance/c2go/blob/master/program/program.go#L76

@yulvil
Copy link
Contributor Author

yulvil commented Oct 23, 2017

@elliotchance Yes I am seeing this with go transpile. I will look into this later.

@yulvil
Copy link
Contributor Author

yulvil commented Oct 24, 2017

I confirm that p.OutputAsTest = true // args.outputAsTest in main.c

https://github.com/elliotchance/c2go/blame/master/main.go#L227

@elliotchance
Copy link
Owner

That was a bug introduced by myself... You can even see the original code commented out. 😢

If you have time please change that line back to:

p.OutputAsTest = args.outputAsTest

That will also fix this ticket.

@yulvil
Copy link
Contributor Author

yulvil commented Oct 25, 2017

TODO: Verify that this is fixed by 1a2f089

@elliotchance
Copy link
Owner

I can confirm that it was not fixed in that PR (already merged).

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