Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Add scripts to detect carriage return and tab #4526

Merged
merged 7 commits into from Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions .travis.yml
Expand Up @@ -34,7 +34,15 @@ install:
- export PATH="${TRAVIS_BUILD_DIR}/Godeps/_workspace/bin:$PATH"

script:
# fail fast
- set -e
# fail if templates/generators contain carriage return '\r'
- /bin/bash ./bin/utils/detect_carriage_return.sh
# fail if generators contain tab '\t'
- /bin/bash ./bin/utils/detect_tab_in_java_class.sh
# run integration tests defined in maven pom.xml
- mvn verify -Psamples
# docker test
- if [ $DOCKER_HUB_USERNAME ]; then docker login --email=$DOCKER_HUB_EMAIL --username=$DOCKER_HUB_USERNAME --password=$DOCKER_HUB_PASSWORD && docker build -t $DOCKER_IMAGE_NAME ./modules/swagger-generator && if [ ! -z "$TRAVIS_TAG" ]; then docker tag $DOCKER_IMAGE_NAME:latest $DOCKER_IMAGE_NAME:$TRAVIS_TAG; fi && docker push $DOCKER_IMAGE_NAME; fi

env:
Expand Down
18 changes: 18 additions & 0 deletions bin/utils/detect_carriage_return.sh
@@ -0,0 +1,18 @@
#!/bin/bash

# grep for \r in the templates
grep -RUIl $'\r$' modules/swagger-codegen/src/main/resources/*

if [ $? -ne 1 ]; then
echo "Templates contain carriage return '/r'. Please remove it and try again."
exit 1;
fi


# grep for \r in the generators
grep -RUIl $'\r$' modules/swagger-codegen/src/main/java/io/swagger/codegen/*.java

if [ $? -ne 1 ]; then
echo "Generators contain carriage return '/r'. Please remove it and try again."
exit 1;
fi
10 changes: 10 additions & 0 deletions bin/utils/detect_tab_in_java_class.sh
@@ -0,0 +1,10 @@
#!/bin/bash

# grep for \t in the generators
grep -RUIl $'\t$' modules/swagger-codegen/src/main/java/io/swagger/codegen/*.java

if [ $? -ne 1 ]; then
echo "Generators (Java class files) contain tab '/t'. Please remove it and try again."
exit 1;
fi

Expand Up @@ -25,9 +25,9 @@
*/
@Deprecated
public class Codegen extends DefaultGenerator {

private static final Logger LOGGER = LoggerFactory.getLogger(Codegen.class);

static Map<String, CodegenConfig> configs = new HashMap<String, CodegenConfig>();
static String configString;
static String debugInfoOptions = "\nThe following additional debug options are available for all codegen targets:" +
Expand Down
90 changes: 45 additions & 45 deletions modules/swagger-codegen/src/main/resources/Java/api_test.mustache
@@ -1,45 +1,45 @@
{{>licenseInfo}}
package {{package}};
import {{invokerPackage}}.ApiException;
{{#imports}}import {{import}};
{{/imports}}
import org.junit.Test;
import org.junit.Ignore;
{{^fullJavaUtil}}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}
/**
* API tests for {{classname}}
*/
@Ignore
public class {{classname}}Test {
private final {{classname}} api = new {{classname}}();
{{#operations}}{{#operation}}
/**
* {{summary}}
*
* {{notes}}
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void {{operationId}}Test() throws ApiException {
{{#allParams}}
{{{dataType}}} {{paramName}} = null;
{{/allParams}}
{{#returnType}}{{{returnType}}} response = {{/returnType}}api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
// TODO: test validations
}
{{/operation}}{{/operations}}
}
{{>licenseInfo}}

package {{package}};

import {{invokerPackage}}.ApiException;
{{#imports}}import {{import}};
{{/imports}}
import org.junit.Test;
import org.junit.Ignore;

{{^fullJavaUtil}}
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
{{/fullJavaUtil}}

/**
* API tests for {{classname}}
*/
@Ignore
public class {{classname}}Test {

private final {{classname}} api = new {{classname}}();

{{#operations}}{{#operation}}
/**
* {{summary}}
*
* {{notes}}
*
* @throws ApiException
* if the Api call fails
*/
@Test
public void {{operationId}}Test() throws ApiException {
{{#allParams}}
{{{dataType}}} {{paramName}} = null;
{{/allParams}}
{{#returnType}}{{{returnType}}} response = {{/returnType}}api.{{operationId}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});

// TODO: test validations
}
{{/operation}}{{/operations}}
}