Problem with using 2 file Go in Eclipse


(Michele Mori) #1

Hi to everyone, I’m a newbie with go. I’m using go with eclipse.
Does anyone know how to build and run a project in Eclipse with two files? I’ve created a first file with a function for test and a second file with a definition of an array of struct. They are in the same src and in the same package.

First file:

import ( "math" "testing")
func TestData(t *testing.T) { 
const precision = 0.01
for _, tc := range testExamples {
actual := DataTest(tc.FirstValue, tc.SecondValue)
if ... {
    t.Fatalf("FAIL: %s\nExpected: %#v\nActual: %#v", tc.description, tc.expected, actual)
}
t.Logf("PASS: %s", tc.description)
}
}

Second File:

var testCases = []struct {
description string
valuex      string
valuey      string
expected    float64
}{
{
description: "example1",
FirstValue:      xxxxx,
SecondValue:     yyyyy,
expected:    10,
},{
description: "example2",
FirstValue:      xxxxx,
SecondValue:     yyyyy,
expected:    280,
}
}

Eclipse, in the first file, report: undefined: testCases

I thought the problem was related to the automatic compilation that does not take into account the 2 files. Does anyone have any suggestions?

Thanks


(Johan Dahl) #2

Did you write the package declaration? They are missing in your examples here…


(Michele Mori) #3

Yes, I’m sorry. I forgot to write It in the post but in both of them, I wrote the package declaration: package main.


(Kevin Maduro) #4

Are your funcs being called inside the func main? If doesn’t, try to call them inside that func.


(Norbert Melzer) #5

Does it work from the terminal using go build?


(Michele Mori) #6

Hello, I did not put the main function inside my application, because I seemed to have understood that to perform the test function was not necessary.

I tried to build the build manually but I always get the same error, as if I did not see the test case I declared inside the other file go.

Do you have any suggestions?
is it necessary to use the main function even when using test_case?


(Michele Mori) #7

Do you have any suggestions?
Thanks