You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2014/05/02 23:38:35 UTC
git commit: THRIFT-2491 unable to import generated ThriftTest service
Client: Go Patch: Aleksey Pesternikov
Repository: thrift
Updated Branches:
refs/heads/master 2a9e6a491 -> e52c046cb
THRIFT-2491 unable to import generated ThriftTest service
Client: Go
Patch: Aleksey Pesternikov
This closes #105
commit f2e7186ca8d63f407dba0c56ee51afd6405926ba
Author: Aleksey Pesternikov <ap...@alekseys-mbp.att.net>
Date: 2014-04-22T12:48:14Z
add _ to generated filename if it ends with _test.go
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/e52c046c
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/e52c046c
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/e52c046c
Branch: refs/heads/master
Commit: e52c046cb62d1f910302148f7bc2091c014acd27
Parents: 2a9e6a4
Author: Jens Geyer <je...@apache.org>
Authored: Fri May 2 23:37:39 2014 +0200
Committer: Jens Geyer <je...@apache.org>
Committed: Fri May 2 23:37:39 2014 +0200
----------------------------------------------------------------------
compiler/cpp/src/generate/t_generator.h | 2 +-
compiler/cpp/src/generate/t_go_generator.cc | 17 ++++++++++----
lib/go/test/Makefile.am | 10 ++++----
lib/go/test/NamespacedTest.thrift | 2 +-
lib/go/test/tests/binary_key_test.go | 4 ++--
lib/go/test/tests/multiplexed_protocol_test.go | 20 ++++++++--------
lib/go/test/tests/one_way_test.go | 8 +++----
lib/go/test/tests/optional_fields_test.go | 26 ++++++++++-----------
test/ThriftTest.thrift | 2 +-
9 files changed, 49 insertions(+), 42 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/e52c046c/compiler/cpp/src/generate/t_generator.h
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_generator.h b/compiler/cpp/src/generate/t_generator.h
index d5cf835..d131777 100644
--- a/compiler/cpp/src/generate/t_generator.h
+++ b/compiler/cpp/src/generate/t_generator.h
@@ -193,7 +193,7 @@ class t_generator {
in[0] = tolower(in[0]);
return in;
}
- std::string lowercase(std::string in) {
+ static std::string lowercase(std::string in) {
for (size_t i = 0; i < in.size(); ++i) {
in[i] = tolower(in[i]);
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/e52c046c/compiler/cpp/src/generate/t_go_generator.cc
----------------------------------------------------------------------
diff --git a/compiler/cpp/src/generate/t_go_generator.cc b/compiler/cpp/src/generate/t_go_generator.cc
index 4893c71..6f273f1 100644
--- a/compiler/cpp/src/generate/t_go_generator.cc
+++ b/compiler/cpp/src/generate/t_go_generator.cc
@@ -254,12 +254,11 @@ public:
return package_flag;
}
std::string real_module = program->get_namespace("go");
-
- if (real_module.empty()) {
- return program->get_name();
+ if (!real_module.empty()) {
+ return real_module;
}
- return real_module;
+ return lowercase(program->get_name());
}
private:
@@ -1510,7 +1509,15 @@ void t_go_generator::generate_go_struct_writer(ofstream& out,
*/
void t_go_generator::generate_service(t_service* tservice)
{
- string f_service_name = package_dir_ + "/" + underscore(service_name_) + ".go";
+ string test_suffix("_test");
+ string filename = lowercase(service_name_);
+ string f_service_name;
+ if (filename.compare(filename.length() - test_suffix.length(),
+ test_suffix.length(), test_suffix) == 0) {
+ f_service_name = package_dir_ + "/" + filename + "_.go";
+ } else {
+ f_service_name = package_dir_ + "/" + filename + ".go";
+ }
f_service_.open(f_service_name.c_str());
f_service_ <<
go_autogen_comment() <<
http://git-wip-us.apache.org/repos/asf/thrift/blob/e52c046c/lib/go/test/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/go/test/Makefile.am b/lib/go/test/Makefile.am
index 5499fb7..0be6cf7 100644
--- a/lib/go/test/Makefile.am
+++ b/lib/go/test/Makefile.am
@@ -47,11 +47,11 @@ gopath: $(top_srcdir)/compiler/cpp/thrift $(THRIFTTEST) \
check: gopath
GOPATH=`pwd`/gopath $(GO) build \
- IncludesTest \
- BinaryKeyTest \
- ServicesTest \
- TypedefFieldTest \
- RefAnnotationFieldsTest
+ includestest \
+ binarykeytest \
+ servicestest \
+ typedeffieldtest \
+ refannotationfieldstest
GOPATH=`pwd`/gopath $(GO) test thrift tests
clean-local:
http://git-wip-us.apache.org/repos/asf/thrift/blob/e52c046c/lib/go/test/NamespacedTest.thrift
----------------------------------------------------------------------
diff --git a/lib/go/test/NamespacedTest.thrift b/lib/go/test/NamespacedTest.thrift
index 1bb2fc4..a910350 100644
--- a/lib/go/test/NamespacedTest.thrift
+++ b/lib/go/test/NamespacedTest.thrift
@@ -19,7 +19,7 @@
include "ThriftTest.thrift"
-namespace go lib.go.test.NamespacedTest
+namespace go lib.go.test.namespacedtest
enum Stuff {
ONE = 1,
http://git-wip-us.apache.org/repos/asf/thrift/blob/e52c046c/lib/go/test/tests/binary_key_test.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/binary_key_test.go b/lib/go/test/tests/binary_key_test.go
index 4cd3eb4..aa96193 100644
--- a/lib/go/test/tests/binary_key_test.go
+++ b/lib/go/test/tests/binary_key_test.go
@@ -20,12 +20,12 @@
package tests
import (
- "BinaryKeyTest"
+ "binarykeytest"
"testing"
)
func TestBinaryMapKeyGeneratesString(t *testing.T) {
- s := BinaryKeyTest.NewTestStruct()
+ s := binarykeytest.NewTestStruct()
//This will only compile if BinToString has type of map[string]string
s.BinToString = make(map[string]string)
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/e52c046c/lib/go/test/tests/multiplexed_protocol_test.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/multiplexed_protocol_test.go b/lib/go/test/tests/multiplexed_protocol_test.go
index 5b8a328..00669ef 100644
--- a/lib/go/test/tests/multiplexed_protocol_test.go
+++ b/lib/go/test/tests/multiplexed_protocol_test.go
@@ -20,7 +20,7 @@
package tests
import (
- "MultiplexedProtocolTest"
+ "multiplexedprotocoltest"
"net"
"testing"
"thrift"
@@ -61,37 +61,37 @@ func TestInitTwoServers(t *testing.T) {
}
server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
- firstProcessor := MultiplexedProtocolTest.NewFirstProcessor(&FirstImpl{})
+ firstProcessor := multiplexedprotocoltest.NewFirstProcessor(&FirstImpl{})
processor.RegisterProcessor("FirstService", firstProcessor)
- secondProcessor := MultiplexedProtocolTest.NewSecondProcessor(&SecondImpl{})
+ secondProcessor := multiplexedprotocoltest.NewSecondProcessor(&SecondImpl{})
processor.RegisterProcessor("SecondService", secondProcessor)
go server.Serve()
}
-var firstClient *MultiplexedProtocolTest.FirstClient
+var firstClient *multiplexedprotocoltest.FirstClient
func TestInitClient1(t *testing.T) {
socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
transport := thrift.NewTFramedTransport(socket)
var protocol thrift.TProtocol = thrift.NewTBinaryProtocolTransport(transport)
protocol = thrift.NewTMultiplexedProtocol(protocol, "FirstService")
- firstClient = MultiplexedProtocolTest.NewFirstClientProtocol(transport, protocol, protocol)
+ firstClient = multiplexedprotocoltest.NewFirstClientProtocol(transport, protocol, protocol)
err := transport.Open()
if err != nil {
t.Fatal("Unable to open client socket", err)
}
}
-var secondClient *MultiplexedProtocolTest.SecondClient
+var secondClient *multiplexedprotocoltest.SecondClient
func TestInitClient2(t *testing.T) {
socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
transport := thrift.NewTFramedTransport(socket)
var protocol thrift.TProtocol = thrift.NewTBinaryProtocolTransport(transport)
protocol = thrift.NewTMultiplexedProtocol(protocol, "SecondService")
- secondClient = MultiplexedProtocolTest.NewSecondClientProtocol(transport, protocol, protocol)
+ secondClient = multiplexedprotocoltest.NewSecondClientProtocol(transport, protocol, protocol)
err := transport.Open()
if err != nil {
t.Fatal("Unable to open client socket", err)
@@ -99,11 +99,11 @@ func TestInitClient2(t *testing.T) {
}
//create client without service prefix
-func createLegacyClient(t *testing.T) *MultiplexedProtocolTest.SecondClient {
+func createLegacyClient(t *testing.T) *multiplexedprotocoltest.SecondClient {
socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
transport := thrift.NewTFramedTransport(socket)
var protocol thrift.TProtocol = thrift.NewTBinaryProtocolTransport(transport)
- legacyClient := MultiplexedProtocolTest.NewSecondClientProtocol(transport, protocol, protocol)
+ legacyClient := multiplexedprotocoltest.NewSecondClientProtocol(transport, protocol, protocol)
err := transport.Open()
if err != nil {
t.Fatal("Unable to open client socket", err)
@@ -139,7 +139,7 @@ func TestCallLegacy(t *testing.T) {
t.Fatal("Expecting error")
}
//register default processor and call again
- processor.RegisterDefault(MultiplexedProtocolTest.NewSecondProcessor(&SecondImpl{}))
+ processor.RegisterDefault(multiplexedprotocoltest.NewSecondProcessor(&SecondImpl{}))
legacyClient = createLegacyClient(t)
ret, err = legacyClient.ReturnTwo()
if err != nil {
http://git-wip-us.apache.org/repos/asf/thrift/blob/e52c046c/lib/go/test/tests/one_way_test.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/one_way_test.go b/lib/go/test/tests/one_way_test.go
index 5ffbbfe..3ff025f 100644
--- a/lib/go/test/tests/one_way_test.go
+++ b/lib/go/test/tests/one_way_test.go
@@ -20,9 +20,9 @@
package tests
import (
- "OnewayTest"
"fmt"
"net"
+ "onewaytest"
"testing"
"thrift"
"time"
@@ -47,7 +47,7 @@ const TIMEOUT = time.Second
var addr net.Addr
var server *thrift.TSimpleServer
-var client *OnewayTest.OneWayClient
+var client *onewaytest.OneWayClient
func TestInitOneway(t *testing.T) {
var err error
@@ -56,7 +56,7 @@ func TestInitOneway(t *testing.T) {
if err != nil {
t.Fatal("Unable to create server socket", err)
}
- processor := OnewayTest.NewOneWayProcessor(&impl{})
+ processor := onewaytest.NewOneWayProcessor(&impl{})
server = thrift.NewTSimpleServer2(processor, serverTransport)
go server.Serve()
@@ -65,7 +65,7 @@ func TestInitOneway(t *testing.T) {
func TestInitOnewayClient(t *testing.T) {
transport := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
protocol := thrift.NewTBinaryProtocolTransport(transport)
- client = OnewayTest.NewOneWayClientProtocol(transport, protocol, protocol)
+ client = onewaytest.NewOneWayClientProtocol(transport, protocol, protocol)
err := transport.Open()
if err != nil {
t.Fatal("Unable to open client socket", err)
http://git-wip-us.apache.org/repos/asf/thrift/blob/e52c046c/lib/go/test/tests/optional_fields_test.go
----------------------------------------------------------------------
diff --git a/lib/go/test/tests/optional_fields_test.go b/lib/go/test/tests/optional_fields_test.go
index 4b0797c..324bf00 100644
--- a/lib/go/test/tests/optional_fields_test.go
+++ b/lib/go/test/tests/optional_fields_test.go
@@ -20,15 +20,15 @@
package tests
import (
- "OptionalFieldsTest"
"bytes"
gomock "code.google.com/p/gomock/gomock"
+ "optionalfieldstest"
"testing"
"thrift"
)
func TestIsSetReturnFalseOnCreation(t *testing.T) {
- ao := OptionalFieldsTest.NewAllOptional()
+ ao := optionalfieldstest.NewAllOptional()
if ao.IsSetS() {
t.Errorf("Optional field S is set on initialization")
}
@@ -71,7 +71,7 @@ func TestIsSetReturnFalseOnCreation(t *testing.T) {
}
func TestDefaultValuesOnCreation(t *testing.T) {
- ao := OptionalFieldsTest.NewAllOptional()
+ ao := optionalfieldstest.NewAllOptional()
if ao.GetS() != "DEFAULT" {
t.Errorf("Unexpected default value %#v for field S", ao.GetS())
}
@@ -112,7 +112,7 @@ func TestDefaultValuesOnCreation(t *testing.T) {
}
func TestInitialValuesOnCreation(t *testing.T) {
- ao := OptionalFieldsTest.NewAllOptional()
+ ao := optionalfieldstest.NewAllOptional()
if ao.S != "DEFAULT" {
t.Errorf("Unexpected initial value %#v for field S", ao.S)
}
@@ -152,11 +152,11 @@ func TestInitialValuesOnCreation(t *testing.T) {
}
func TestIsSetReturnTrueAfterUpdate(t *testing.T) {
- ao := OptionalFieldsTest.NewAllOptional()
+ ao := optionalfieldstest.NewAllOptional()
ao.S = "somevalue"
ao.I = 123
ao.B = true
- ao.Aa = OptionalFieldsTest.NewStructA()
+ ao.Aa = optionalfieldstest.NewStructA()
if !ao.IsSetS() {
t.Errorf("Field S should be set")
}
@@ -172,7 +172,7 @@ func TestIsSetReturnTrueAfterUpdate(t *testing.T) {
}
func TestListNotEmpty(t *testing.T) {
- ao := OptionalFieldsTest.NewAllOptional()
+ ao := optionalfieldstest.NewAllOptional()
ao.L = []int64{1, 2, 3}
if !ao.IsSetL() {
t.Errorf("Field L should be set")
@@ -189,7 +189,7 @@ func TestNoOptionalUnsetFieldsOnWire(t *testing.T) {
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
- ao := OptionalFieldsTest.NewAllOptional()
+ ao := optionalfieldstest.NewAllOptional()
ao.Write(proto)
}
@@ -202,7 +202,7 @@ func TestNoSetToDefaultFieldsOnWire(t *testing.T) {
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
- ao := OptionalFieldsTest.NewAllOptional()
+ ao := optionalfieldstest.NewAllOptional()
ao.I = 42
ao.Write(proto)
}
@@ -220,7 +220,7 @@ func TestOneISetFieldOnWire(t *testing.T) {
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
- ao := OptionalFieldsTest.NewAllOptional()
+ ao := optionalfieldstest.NewAllOptional()
ao.I = 123
ao.Write(proto)
}
@@ -240,7 +240,7 @@ func TestOneLSetFieldOnWire(t *testing.T) {
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
- ao := OptionalFieldsTest.NewAllOptional()
+ ao := optionalfieldstest.NewAllOptional()
ao.L = []int64{1, 2}
ao.Write(proto)
}
@@ -257,7 +257,7 @@ func TestOneBinSetFieldOnWire(t *testing.T) {
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
- ao := OptionalFieldsTest.NewAllOptional()
+ ao := optionalfieldstest.NewAllOptional()
ao.Bin = []byte("somebytestring")
ao.Write(proto)
}
@@ -274,7 +274,7 @@ func TestOneEmptyBinSetFieldOnWire(t *testing.T) {
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
- ao := OptionalFieldsTest.NewAllOptional()
+ ao := optionalfieldstest.NewAllOptional()
ao.Bin = []byte{}
ao.Write(proto)
}
http://git-wip-us.apache.org/repos/asf/thrift/blob/e52c046c/test/ThriftTest.thrift
----------------------------------------------------------------------
diff --git a/test/ThriftTest.thrift b/test/ThriftTest.thrift
index 7ca194e..4a689fe 100644
--- a/test/ThriftTest.thrift
+++ b/test/ThriftTest.thrift
@@ -31,7 +31,7 @@ namespace js ThriftTest
namespace st ThriftTest
namespace py ThriftTest
namespace py.twisted ThriftTest
-namespace go ThriftTest
+namespace go thrifttest
namespace php ThriftTest
namespace delphi Thrift.Test
namespace cocoa ThriftTest