Skip to content

Commit

Permalink
Changes in according to review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin8105 committed Jun 22, 2017
1 parent 24a2550 commit 331db04
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@
/coverage.txt
/c2go
/.vscode
*.coverprofile

# Vim backups
*.go~
*.go.swp
*.un~
*.coverprofile
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Elliot Chance, Izyumov Konstantin
Copyright (c) 2017 Elliot Chance

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
25 changes: 10 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,15 @@ func Start(args ProgramArgs) error {
return nil
}

// NewTempFile - returns temp file
func NewTempFile(dir, prefix, suffix string) (*os.File, error) {
// newTempFile - returns temp file
func newTempFile(dir, prefix, suffix string) (*os.File, error) {
for index := 1; index < 10000; index++ {
path := filepath.Join(dir, fmt.Sprintf("%s%03d%s", prefix, index, suffix))
if _, err := os.Stat(path); err != nil {
return os.Create(path)
}
}
return nil, fmt.Errorf("could not create file of the form %s%03d%s", prefix, 1, suffix)
return nil, fmt.Errorf("could not create file: %s%03d%s", prefix, 1, suffix)
}

func main() {
Expand Down Expand Up @@ -269,7 +269,7 @@ func main() {
case "ast":
err := astCommand.Parse(os.Args[2:])
if err != nil {
fmt.Printf("Ast command cannot parse: %v", err)
fmt.Printf("ast command cannot parse: %v", err)
os.Exit(1)
}

Expand All @@ -281,15 +281,10 @@ func main() {

args.ast = true
args.inputFile = astCommand.Arg(0)

if err = Start(args); err != nil {
fmt.Printf("Error: %v", err)
os.Exit(1)
}
case "transpile":
err := transpileCommand.Parse(os.Args[2:])
if err != nil {
fmt.Printf("Transpile command cannot parse: %v", err)
fmt.Printf("transpile command cannot parse: %v", err)
os.Exit(1)
}

Expand All @@ -302,13 +297,13 @@ func main() {
args.inputFile = transpileCommand.Arg(0)
args.outputFile = *outputFlag
args.packageName = *packageFlag

if err = Start(args); err != nil {
fmt.Printf("Error: %v", err)
os.Exit(1)
}
default:
flag.Usage()
os.Exit(1)
}

if err := Start(args); err != nil {
fmt.Printf("Error: %v", err)
os.Exit(1)
}
}
33 changes: 17 additions & 16 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ func TestIntegrationScripts(t *testing.T) {
}

// Compile Go
Start(programArgs)
err = Start(programArgs)
if err != nil {
t.Fatalf("error: %s\n%s", err, out)
}

buildErr, err := exec.Command("go", "build", "-o", goPath, "build/main.go").CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -160,15 +163,13 @@ func TestStartPreprocess(t *testing.T) {

// create temp file with garantee
// wrong file body
tempFile, err := NewTempFile(tempDir, "c2go", "preprocess.c")
tempFile, err := newTempFile(tempDir, "c2go", "preprocess.c")
if err != nil {
t.Errorf("Cannot create temp file for execute test")
}
defer func() {
_ = os.Remove(tempFile.Name())
}()
defer os.Remove(tempFile.Name())

fmt.Fprintf(tempFile, "#include <AbsoluteWrongInclude.h>\nint main(void){\nwrong\n}")
fmt.Fprintf(tempFile, "#include <AbsoluteWrongInclude.h>\nint main(void){\nwrong();\n}")

err = tempFile.Close()
if err != nil {
Expand All @@ -189,26 +190,26 @@ func TestGoPath(t *testing.T) {

existEnv := os.Getenv(gopath)
if existEnv == "" {
t.Errorf("Please create value $GOPATH of the environment variable")
}

// reset value of env.var.
err := os.Setenv(gopath, "")
if err != nil {
t.Errorf("Cannot set value of the environment variable")
t.Errorf("$GOPATH is not set")
}

// return env.var.
defer func() {
err = os.Setenv(gopath, existEnv)
if err != nil {
t.Errorf("Please create value $GOPATH of the environment variable")
t.Errorf("Cannot restore the value of $GOPATH")
}
}()

// reset value of env.var.
err := os.Setenv(gopath, "")
if err != nil {
t.Errorf("Cannot set value of $GOPATH")
}

// testing
err = Start(*(new(ProgramArgs)))
err = Start(&ProgramArgs{})
if err == nil {
t.Errorf("We have to check $GOPATH")
t.Errorf(err.Error())
}
}

0 comments on commit 331db04

Please sign in to comment.