test.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. set -e
  3. # Download protoc 3.0.0 from Maven if it is not already present.
  4. OLD_PROTOC_URL=https://repo1.maven.org/maven2/com/google/protobuf/protoc/3.0.0/protoc-3.0.0-linux-x86_64.exe
  5. if [ ! -f protoc ]; then
  6. wget $OLD_PROTOC_URL -O protoc
  7. chmod +x protoc
  8. fi
  9. pushd ../..
  10. npm install && npm test
  11. popd
  12. old_protoc=./protoc
  13. new_protoc=../../../src/protoc
  14. # The protos in group 2 have some dependencies on protos in group 1. The tests
  15. # will verify that the generated code for one group can be regenerated
  16. # independently of the other group in a compatible way.
  17. #
  18. # Note: these lists of protos duplicate the lists in gulpfile.js. Ideally we
  19. # should find a good way of having a single source of truth for this.
  20. group1_protos="data.proto test3.proto test5.proto commonjs/test6/test6.proto testbinary.proto testempty.proto test.proto"
  21. group2_protos="proto3_test.proto test2.proto test4.proto commonjs/test7/test7.proto"
  22. # We test the following cases:
  23. #
  24. # Case 1: build groups 1 and 2 with the old protoc
  25. # Case 2: build group 1 with new protoc but group 2 with old protoc
  26. # Case 3: build group 1 with old protoc but group 2 with new protoc
  27. #
  28. # In each case, we use the current runtime.
  29. #
  30. # CommonJS tests
  31. #
  32. mkdir -p commonjs_out{1,2,3}
  33. # Case 1
  34. $old_protoc --js_out=import_style=commonjs,binary:commonjs_out1 -I ../../../src -I commonjs -I . $group1_protos
  35. $old_protoc --js_out=import_style=commonjs,binary:commonjs_out1 -I ../../../src -I commonjs -I . $group2_protos
  36. # Case 2
  37. $new_protoc --js_out=import_style=commonjs,binary:commonjs_out2 -I ../../../src -I commonjs -I . $group1_protos
  38. $old_protoc --js_out=import_style=commonjs,binary:commonjs_out2 -I ../../../src -I commonjs -I . $group2_protos
  39. # Case 3
  40. $old_protoc --js_out=import_style=commonjs,binary:commonjs_out3 -I ../../../src -I commonjs -I . $group1_protos
  41. $new_protoc --js_out=import_style=commonjs,binary:commonjs_out3 -I ../../../src -I commonjs -I . $group2_protos
  42. mkdir -p commonjs_out/binary
  43. for file in *_test.js binary/*_test.js; do
  44. node commonjs/rewrite_tests_for_commonjs.js < "$file" > "commonjs_out/$file"
  45. done
  46. cp commonjs/{jasmine.json,import_test.js} commonjs_out/
  47. mkdir -p commonjs_out/test_node_modules
  48. ../../node_modules/.bin/google-closure-compiler \
  49. --entry_point=commonjs/export_asserts.js \
  50. --js=commonjs/export_asserts.js \
  51. --js=../../node_modules/google-closure-library/closure/goog/**.js \
  52. --js=../../node_modules/google-closure-library/third_party/closure/goog/**.js \
  53. > commonjs_out/test_node_modules/closure_asserts_commonjs.js
  54. ../../node_modules/.bin/google-closure-compiler \
  55. --entry_point=commonjs/export_testdeps.js \
  56. --js=commonjs/export_testdeps.js \
  57. --js=../../binary/*.js \
  58. --js=!../../binary/*_test.js \
  59. --js=../../node_modules/google-closure-library/closure/goog/**.js \
  60. --js=../../node_modules/google-closure-library/third_party/closure/goog/**.js \
  61. > commonjs_out/test_node_modules/testdeps_commonjs.js
  62. cp ../../google-protobuf.js commonjs_out/test_node_modules
  63. cp -r ../../commonjs_out/node_modules commonjs_out
  64. echo
  65. echo "Running tests with CommonJS imports"
  66. echo "-----------------------------------"
  67. for i in 1 2 3; do
  68. cp -r commonjs_out/* "commonjs_out$i"
  69. pushd "commonjs_out$i"
  70. JASMINE_CONFIG_PATH=jasmine.json NODE_PATH=test_node_modules ../../../node_modules/.bin/jasmine
  71. popd
  72. done
  73. #
  74. # Closure tests
  75. #
  76. $old_protoc --js_out=library=testproto_libs1,binary:. -I ../../../src -I commonjs -I . $group1_protos
  77. $old_protoc --js_out=library=testproto_libs2,binary:. -I ../../../src -I commonjs -I . $group2_protos
  78. $new_protoc --js_out=library=testproto_libs1_new,binary:. -I ../../../src -I commonjs -I . $group1_protos
  79. $new_protoc --js_out=library=testproto_libs2_new,binary:. -I ../../../src -I commonjs -I . $group2_protos
  80. echo
  81. echo "Running tests with Closure-style imports"
  82. echo "----------------------------------------"
  83. # Case 1
  84. JASMINE_CONFIG_PATH=jasmine1.json ../../node_modules/.bin/jasmine
  85. # Case 2
  86. JASMINE_CONFIG_PATH=jasmine2.json ../../node_modules/.bin/jasmine
  87. # Case 3
  88. JASMINE_CONFIG_PATH=jasmine3.json ../../node_modules/.bin/jasmine
  89. # Remove these files so that calcdeps.py does not get confused by them the next
  90. # time this script runs.
  91. rm testproto_libs[12]*