test.sh 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/google-closure-library/closure/bin/calcdeps.py -i commonjs/export_asserts.js -p . -p ../../node_modules/google-closure-library/closure -o compiled --compiler_jar ../../node_modules/google-closure-compiler/compiler.jar > commonjs_out/test_node_modules/closure_asserts_commonjs.js
  49. ../../node_modules/google-closure-library/closure/bin/calcdeps.py -i commonjs/export_testdeps.js -p ../.. -p ../../node_modules/google-closure-library/closure -o compiled --compiler_jar ../../node_modules/google-closure-compiler/compiler.jar > commonjs_out/test_node_modules/testdeps_commonjs.js
  50. cp ../../google-protobuf.js commonjs_out/test_node_modules
  51. cp -r ../../commonjs_out/node_modules commonjs_out
  52. echo
  53. echo "Running tests with CommonJS imports"
  54. echo "-----------------------------------"
  55. for i in 1 2 3; do
  56. cp -r commonjs_out/* "commonjs_out$i"
  57. pushd "commonjs_out$i"
  58. JASMINE_CONFIG_PATH=jasmine.json NODE_PATH=test_node_modules ../../../node_modules/.bin/jasmine
  59. popd
  60. done
  61. #
  62. # Closure tests
  63. #
  64. $old_protoc --js_out=library=testproto_libs1,binary:. -I ../../../src -I commonjs -I . $group1_protos
  65. $old_protoc --js_out=library=testproto_libs2,binary:. -I ../../../src -I commonjs -I . $group2_protos
  66. $new_protoc --js_out=library=testproto_libs1_new,binary:. -I ../../../src -I commonjs -I . $group1_protos
  67. $new_protoc --js_out=library=testproto_libs2_new,binary:. -I ../../../src -I commonjs -I . $group2_protos
  68. echo
  69. echo "Running tests with Closure-style imports"
  70. echo "----------------------------------------"
  71. # Case 1
  72. JASMINE_CONFIG_PATH=jasmine1.json ../../node_modules/.bin/jasmine
  73. # Case 2
  74. JASMINE_CONFIG_PATH=jasmine2.json ../../node_modules/.bin/jasmine
  75. # Case 3
  76. JASMINE_CONFIG_PATH=jasmine3.json ../../node_modules/.bin/jasmine
  77. # Remove these files so that calcdeps.py does not get confused by them the next
  78. # time this script runs.
  79. rm testproto_libs[12]*