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

Fix a warning when there are only enums, no messages. #370

Merged
merged 2 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proto-lens-protoc/app/Data/ProtoLens/Compiler/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ generateModule modName fdesc imports publicImports definitions importedEnv servi
-- messages, it's omitted since it's only used inside of Message
-- instances.
packedFileDescriptorProto
| null definitions = []
| null [m | Message m <- Map.elems definitions] = []
| otherwise = [
typeSig "packedFileDescriptor" $ var "Data.ByteString.ByteString",
valBind "packedFileDescriptor" $ string packedFDesc
Expand Down
1 change: 1 addition & 0 deletions proto-lens-tests/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ tests:
generated-other-modules:
- Proto.Enum
- Proto.Enum_Fields
- Proto.EnumOnly

names_test:
main: names_test.hs
Expand Down
10 changes: 10 additions & 0 deletions proto-lens-tests/tests/enum_only.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// A file that only contains an enum, not a message.
// Checks that we're not generating unused top-level definitions.

syntax = "proto2";

package enums;

enum Lone {
LONE = 0;
}
6 changes: 5 additions & 1 deletion proto-lens-tests/tests/enum_test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Proto.Enum
, Alias(..)
, ManyCasesProto
)
import Proto.EnumOnly (Lone(..))
import Proto.Enum_Fields
import Data.Function (on)
import Data.ProtoLens
Expand Down Expand Up @@ -46,12 +47,13 @@ main = testMain
, testMonotonicFromEnum
, testAliases
, testManyCases
, testLone
]

testExternalEnum, testNestedEnum, testDefaults, testBadEnumValues,
testNamedEnumValues, testRoundTrip, testBounded, testMaybeSuccAndPred,
testEnumFromThenTo, testMonotonicFromEnum, testAliases,
testManyCases :: TestTree
testManyCases, testLone :: TestTree

testExternalEnum = testGroup "external"
[ serializeTo (show e1)
Expand Down Expand Up @@ -163,3 +165,5 @@ testAliases = testCase "alias" $ do

testManyCases =
runTypedTest (roundTripTest "many cases" :: TypedTest ManyCasesProto)

testLone = testCase "no messages" $ LONE @?= LONE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this test. Isn't LONE always == LONE?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment. The test is intentionally trivial; the goal is just to make this file import the other module to make sure it compiles properly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks for the comment.