z_all_test.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. // +build alltests
  2. // +build go1.7
  3. package codec
  4. // Run this using:
  5. // go test -tags=alltests -run=Suite -coverprofile=cov.out
  6. // go tool cover -html=cov.out
  7. //
  8. // Because build tags are a build time parameter, we will have to test out the
  9. // different tags separately.
  10. // Tags: x codecgen safe appengine notfastpath
  11. //
  12. // These tags should be added to alltests, e.g.
  13. // go test '-tags=alltests x codecgen' -run=Suite -coverprofile=cov.out
  14. //
  15. // To run all tests before submitting code, run:
  16. // a=( "" "safe" "codecgen" "notfastpath" "codecgen notfastpath" "codecgen safe" "safe notfastpath" )
  17. // for i in "${a[@]}"; do echo ">>>> TAGS: $i"; go test "-tags=alltests $i" -run=Suite; done
  18. //
  19. // This only works on go1.7 and above. This is when subtests and suites were supported.
  20. import "testing"
  21. // func TestMain(m *testing.M) {
  22. // println("calling TestMain")
  23. // // set some parameters
  24. // exitcode := m.Run()
  25. // os.Exit(exitcode)
  26. // }
  27. func testSuite(t *testing.T, f func(t *testing.T)) {
  28. // find . -name "*_test.go" | xargs grep -e 'flag.' | cut -d '&' -f 2 | cut -d ',' -f 1 | grep -e '^test'
  29. // Disregard the following: testVerbose, testInitDebug, testSkipIntf, testJsonIndent (Need a test for it)
  30. testReinit() // so flag.Parse() is called first, and never called again
  31. testDecodeOptions = DecodeOptions{}
  32. testEncodeOptions = EncodeOptions{}
  33. testUseMust = false
  34. testCanonical = false
  35. testUseMust = false
  36. testInternStr = false
  37. testUseIoEncDec = false
  38. testStructToArray = false
  39. testWriteNoSymbols = false
  40. testCheckCircRef = false
  41. testJsonHTMLCharsAsIs = false
  42. testUseReset = false
  43. testMaxInitLen = 0
  44. testJsonIndent = 0
  45. testUseIoWrapper = false
  46. testNumRepeatString = 10
  47. testReinit()
  48. t.Run("optionsFalse", f)
  49. testMaxInitLen = 10
  50. testJsonIndent = 8
  51. testReinit()
  52. t.Run("initLen10-jsonSpaces", f)
  53. testReinit()
  54. testMaxInitLen = 10
  55. testJsonIndent = -1
  56. testReinit()
  57. t.Run("initLen10-jsonTabs", f)
  58. testCanonical = true
  59. testUseMust = true
  60. testInternStr = true
  61. testUseIoEncDec = true
  62. testStructToArray = true
  63. testWriteNoSymbols = true
  64. testCheckCircRef = true
  65. testJsonHTMLCharsAsIs = true
  66. testUseReset = true
  67. testDecodeOptions.MapValueReset = true
  68. testReinit()
  69. t.Run("optionsTrue", f)
  70. testUseIoWrapper = true
  71. testReinit()
  72. t.Run("optionsTrue-ioWrapper", f)
  73. testDepth = 6
  74. testReinit()
  75. t.Run("optionsTrue-deepstruct", f)
  76. testNumRepeatString = 40
  77. testReinit()
  78. t.Run("optionsTrue-largestrings", f)
  79. // The following here MUST be tested individually, as they create
  80. // side effects i.e. the decoded value is different.
  81. // testDecodeOptions.MapValueReset = true // ok - no side effects
  82. // testDecodeOptions.InterfaceReset = true // error??? because we do deepEquals to verify
  83. // testDecodeOptions.ErrorIfNoField = true // error, as expected, as fields not there
  84. // testDecodeOptions.ErrorIfNoArrayExpand = true // no error, but no error case either
  85. // testDecodeOptions.PreferArrayOverSlice = true // error??? because slice != array.
  86. // .... however, update deepEqual to take this option
  87. // testReinit()
  88. // t.Run("optionsTrue-resetOptions", f)
  89. }
  90. /*
  91. z='codec_test.go'
  92. find . -name "$z" | xargs grep -e '^func Test' | \
  93. cut -d '(' -f 1 | cut -d ' ' -f 2 | \
  94. while read f; do echo "t.Run(\"$f\", $f)"; done
  95. */
  96. func testCodecGroup(t *testing.T) {
  97. // println("running testcodecsuite")
  98. // <setup code>
  99. t.Run("TestBincCodecsTable", TestBincCodecsTable)
  100. t.Run("TestBincCodecsMisc", TestBincCodecsMisc)
  101. t.Run("TestBincCodecsEmbeddedPointer", TestBincCodecsEmbeddedPointer)
  102. t.Run("TestBincStdEncIntf", TestBincStdEncIntf)
  103. t.Run("TestBincMammoth", TestBincMammoth)
  104. t.Run("TestSimpleCodecsTable", TestSimpleCodecsTable)
  105. t.Run("TestSimpleCodecsMisc", TestSimpleCodecsMisc)
  106. t.Run("TestSimpleCodecsEmbeddedPointer", TestSimpleCodecsEmbeddedPointer)
  107. t.Run("TestSimpleStdEncIntf", TestSimpleStdEncIntf)
  108. t.Run("TestSimpleMammoth", TestSimpleMammoth)
  109. t.Run("TestMsgpackCodecsTable", TestMsgpackCodecsTable)
  110. t.Run("TestMsgpackCodecsMisc", TestMsgpackCodecsMisc)
  111. t.Run("TestMsgpackCodecsEmbeddedPointer", TestMsgpackCodecsEmbeddedPointer)
  112. t.Run("TestMsgpackStdEncIntf", TestMsgpackStdEncIntf)
  113. t.Run("TestMsgpackMammoth", TestMsgpackMammoth)
  114. t.Run("TestCborCodecsTable", TestCborCodecsTable)
  115. t.Run("TestCborCodecsMisc", TestCborCodecsMisc)
  116. t.Run("TestCborCodecsEmbeddedPointer", TestCborCodecsEmbeddedPointer)
  117. t.Run("TestCborMapEncodeForCanonical", TestCborMapEncodeForCanonical)
  118. t.Run("TestCborCodecChan", TestCborCodecChan)
  119. t.Run("TestCborStdEncIntf", TestCborStdEncIntf)
  120. t.Run("TestCborMammoth", TestCborMammoth)
  121. t.Run("TestJsonCodecsTable", TestJsonCodecsTable)
  122. t.Run("TestJsonCodecsMisc", TestJsonCodecsMisc)
  123. t.Run("TestJsonCodecsEmbeddedPointer", TestJsonCodecsEmbeddedPointer)
  124. t.Run("TestJsonCodecChan", TestJsonCodecChan)
  125. t.Run("TestJsonStdEncIntf", TestJsonStdEncIntf)
  126. t.Run("TestJsonMammoth", TestJsonMammoth)
  127. t.Run("TestJsonRaw", TestJsonRaw)
  128. t.Run("TestBincRaw", TestBincRaw)
  129. t.Run("TestMsgpackRaw", TestMsgpackRaw)
  130. t.Run("TestSimpleRaw", TestSimpleRaw)
  131. t.Run("TestCborRaw", TestCborRaw)
  132. t.Run("TestAllEncCircularRef", TestAllEncCircularRef)
  133. t.Run("TestAllAnonCycle", TestAllAnonCycle)
  134. t.Run("TestBincRpcGo", TestBincRpcGo)
  135. t.Run("TestSimpleRpcGo", TestSimpleRpcGo)
  136. t.Run("TestMsgpackRpcGo", TestMsgpackRpcGo)
  137. t.Run("TestCborRpcGo", TestCborRpcGo)
  138. t.Run("TestJsonRpcGo", TestJsonRpcGo)
  139. t.Run("TestMsgpackRpcSpec", TestMsgpackRpcSpec)
  140. t.Run("TestBincUnderlyingType", TestBincUnderlyingType)
  141. t.Run("TestJsonLargeInteger", TestJsonLargeInteger)
  142. t.Run("TestJsonDecodeNonStringScalarInStringContext", TestJsonDecodeNonStringScalarInStringContext)
  143. t.Run("TestJsonEncodeIndent", TestJsonEncodeIndent)
  144. // <tear-down code>
  145. }
  146. func TestCodecSuite(t *testing.T) { testSuite(t, testCodecGroup) }