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