THRIFT-3150 Add an option to make Read and Write methods private
Client: Go
Patch: Konstantin Shaposhnikov <k.shaposhnikov@gmail.com>, slightly modified by Jens Geyer
This closes #505
diff --git a/lib/go/test/DontExportRWTest.thrift b/lib/go/test/DontExportRWTest.thrift
new file mode 100644
index 0000000..39e5a6f
--- /dev/null
+++ b/lib/go/test/DontExportRWTest.thrift
@@ -0,0 +1,27 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+struct InnerStruct {
+ 1: required string id
+}
+
+struct TestStruct {
+ 1: required string id
+ 2: required InnerStruct inner
+}
diff --git a/lib/go/test/Makefile.am b/lib/go/test/Makefile.am
index aa3d95b..8cedfb0 100644
--- a/lib/go/test/Makefile.am
+++ b/lib/go/test/Makefile.am
@@ -34,7 +34,9 @@
RefAnnotationFieldsTest.thrift \
ErrorTest.thrift \
NamesTest.thrift \
- InitialismsTest.thrift
+ InitialismsTest.thrift \
+ DontExportRWTest.thrift \
+ dontexportrwtest/compile_test.go
mkdir -p gopath/src
grep -v list.*map.*list.*map $(THRIFTTEST) | grep -v 'set<Insanity>' > ThriftTest.thrift
$(THRIFT) $(THRIFTARGS) -r IncludesTest.thrift
@@ -49,9 +51,11 @@
$(THRIFT) $(THRIFTARGS) ErrorTest.thrift
$(THRIFT) $(THRIFTARGS) NamesTest.thrift
$(THRIFT) $(THRIFTARGS) InitialismsTest.thrift
+ $(THRIFT) $(THRIFTARGS),read_write_private DontExportRWTest.thrift
GOPATH=`pwd`/gopath $(GO) get code.google.com/p/gomock/gomock
ln -nfs ../../../thrift gopath/src/thrift
ln -nfs ../../tests gopath/src/tests
+ cp -r ./dontexportrwtest gopath/src
touch gopath
check: gopath
@@ -63,8 +67,9 @@
refannotationfieldstest \
errortest \
namestest \
- initialismstest
- GOPATH=`pwd`/gopath $(GO) test thrift tests
+ initialismstest \
+ dontexportrwtest
+ GOPATH=`pwd`/gopath $(GO) test thrift tests dontexportrwtest
clean-local:
$(RM) -r gopath ThriftTest.thrift gen-go
@@ -86,4 +91,5 @@
TypedefFieldTest.thrift \
ErrorTest.thrift \
NamesTest.thrift \
- InitialismsTest.thrift
+ InitialismsTest.thrift \
+ DontExportRWTest.thrift
diff --git a/lib/go/test/dontexportrwtest/compile_test.go b/lib/go/test/dontexportrwtest/compile_test.go
new file mode 100644
index 0000000..2b877e3
--- /dev/null
+++ b/lib/go/test/dontexportrwtest/compile_test.go
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package dontexportrwtest
+
+import (
+ "fmt"
+ "testing"
+)
+
+// Make sure that thrift generates non-exported read/write methods if
+// read_write_private option is specified
+func TestReadWriteMethodsArePrivate(t *testing.T) {
+ // This will only compile if read/write methods exist
+ s := NewTestStruct()
+ fmt.Sprintf("%v", s.read)
+ fmt.Sprintf("%v", s.write)
+
+ is := NewInnerStruct()
+ fmt.Sprintf("%v", is.read)
+ fmt.Sprintf("%v", is.write)
+}