From 5cd5143b80d17cd40a80277c2aa48f13be006ba8 Mon Sep 17 00:00:00 2001 From: William Cheng Date: Mon, 27 Aug 2018 20:46:50 +0800 Subject: [PATCH] Add test case to detect stack overflow error (#904) * add test case to detect stackoverflow errors * use bash insted of sh --- bin/tests/run-all-test | 33 +++++++++++++ bin/tests/test-debug-supporting-files.sh | 38 +++++++++++++++ .../src/test/resources/3_0/issue_241.yaml | 47 +++++++++++++++++++ shippable.yml | 2 + 4 files changed, 120 insertions(+) create mode 100755 bin/tests/run-all-test create mode 100755 bin/tests/test-debug-supporting-files.sh create mode 100644 modules/openapi-generator/src/test/resources/3_0/issue_241.yaml diff --git a/bin/tests/run-all-test b/bin/tests/run-all-test new file mode 100755 index 00000000000..963f0d2ec63 --- /dev/null +++ b/bin/tests/run-all-test @@ -0,0 +1,33 @@ +#!/bin/bash +# this bash script will loop through all the .sh files under bin/tests +# execute the script and check the result (exit code) to see if +# there's any error + +echo "IMPORTANT: this script should be run by the CI (e.g. Shippable) only. There's no need to run this script manually." +echo "Please press CTRL+C to stop or the script will continue in 10 seconds." + +sleep 10 + +successes=0 +failures=0 +for SCRIPT in $(ls -l ./bin/tests/*.sh | grep -v all) +do + if [ -f ${SCRIPT} -a -x ${SCRIPT} ]; then + echo "Running $SCRIPT (output to /dev/null)" + ${SCRIPT} 2>&1 > /dev/null + rc=$? + if [[ ${rc} != 0 ]]; then + >&2 echo "ERROR!! FAILED TO RUN ${SCRIPT}" + ((failures+=1)) + else + ((successes+=1)) + fi + fi +done + +if (( failures > 0 )); then + >&2 echo "[ERROR] ${failures} out of $((failures+successes)) scripts failed." + exit 1 +else + echo "[SUCCESS] ${successes} generators finished." +fi diff --git a/bin/tests/test-debug-supporting-files.sh b/bin/tests/test-debug-supporting-files.sh new file mode 100755 index 00000000000..7360313f5c8 --- /dev/null +++ b/bin/tests/test-debug-supporting-files.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +SCRIPT="$0" +echo "# START SCRIPT: $SCRIPT" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar" + +if [ ! -f "$executable" ] +then + mvn -B clean package $@ +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="generate -t modules/openapi-generator/src/main/resources/python -i modules/openapi-generator/src/test/resources/3_0/issue_241.yaml -g python -o /tmp/test-debug-supporting-files/ -DpackageName=petstore_api -DdebugSupportingFiles=true $@" + +if [[ $(java $JAVA_OPTS -jar $executable $ags 2>&1 | grep "StackOverflowError") ]]; then + echo "There are StackOverflowError. Please check the result." + exit 1 +else + echo "No StackOverflowError found." +fi + diff --git a/modules/openapi-generator/src/test/resources/3_0/issue_241.yaml b/modules/openapi-generator/src/test/resources/3_0/issue_241.yaml new file mode 100644 index 00000000000..982f18a2d6b --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_0/issue_241.yaml @@ -0,0 +1,47 @@ +openapi: "3.0.0" +info: + description: "test" + version: "1.0.0" + title: "myTest" + contact: + email: "my@mail.com" +servers: +- url: "http://localhost:9998/v1" +tags: +- name: "users" +paths: + /users/create/{username}: + post: + tags: + - "user" + operationId: "createUser" + parameters: + - name: "username" + in: "path" + required: true + schema: + type: "string" + responses: + 200: + description: "The User just created" + content: + application/json: + schema: + $ref: "#/components/schemas/User" +components: + schemas: + User: + allOf: + - $ref: "#/components/schemas/UserDetail" + - type: "object" + description: "The User" + required: + - "userid" + - "username" + UserDetail: + type: "object" + description: "Detail of a User" + properties: + name: + type: "string" + description: "the name of the user" diff --git a/shippable.yml b/shippable.yml index 27c3ccec46e..efb7e072864 100644 --- a/shippable.yml +++ b/shippable.yml @@ -39,3 +39,5 @@ build: - ./bin/run-all-petstore # generate all petstore samples (openapi3) - ./bin/openapi3/run-all-petstore + # generate test scripts + - ./bin/tests/run-all-test