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

Add unit-tests for Joda convert. #45

Merged
merged 2 commits into from
Oct 3, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ os: osx
# Add a TEST_DIR=[directory] row for each library (or group of libraries) to test
# Each will be run as an independent, hermetic test (in parallel when resources permit)
# on Traivs.
# TEST_TASKS specifies the Gradle tasks to run.
env:
- TEST_DIR=com.google.code.gson-gson
- TEST_DIR=org.joda-joda-convert
- TEST_DIR=joda-time-joda-time
- TEST_DIR=org.joda-joda-primitives
- TEST_DIR=org.apache.commons-commons-lang3
- TEST_DIR=com.google.code.gson-gson TEST_TASKS=build
- TEST_DIR=org.joda-joda-convert TEST_TASKS=build
- TEST_DIR=joda-time-joda-time TEST_TASKS=build
- TEST_DIR=org.joda-joda-primitives TEST_TASKS=build
- TEST_DIR=org.apache.commons-commons-lang3 TEST_TASKS=build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is repeated, it's boiler plate that can be removed ;-)
For now assume that all libraries run the build task for testing. I think that's a good assumption anyway.

If it needs something else in the future, then enumerate the exceptions, not the standard way of operating it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'd had a plan to allow 2 entries for a TEST_DIR:

  - TEST_DIR=com.google.code.gson-gson TEST_TASKS=assemble
  - TEST_DIR=com.google.code.gson-gson TEST_TASKS=check

this would allow you to have unit tests in the allowed failures but have translation/compilation in the required successes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either way, i'm removing these changes from this PR as it is only needed in gson, not Joda.


# Uncomment to add a library that should fail to build, along with documentation on why.
# matrix:
Expand Down Expand Up @@ -44,4 +45,4 @@ install:

# Note the install prep leaves us in the libraryBuilds directory.
script:
- ./run-test.sh $TEST_DIR
- ./run-test.sh $TEST_DIR $TEST_TASKS
4 changes: 4 additions & 0 deletions libraryBuilds/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ gradlew.bat
# Generated by prep.sh
common/local.properties
localJ2objcDist/

# Generated by prep-tests.sh
test
test-repo/
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ dependencies {
}

j2objcConfig {
// package-info.java exists in multiple packages.
filenameCollisionCheck false

// Almost always there are no tests provided in an external source jar.
testMinExpectedTests 0
finalConfigure()
Expand Down
28 changes: 28 additions & 0 deletions libraryBuilds/common/prep-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
#
# Copyright (c) 2015 the authors of j2objc-common-libs-e2e-test
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -v
rm -rf test-repo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just be "repo" instead of "test-repo"? Though it's used for testing, it is just a copy of the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this script is currently called prep-tests.sh, and there is no requirement that the repo one specifies to this script have anything but unit tests. if we generalize this script to handle main source set later, then we should rename.

rm -rf src/test
rm -rf src

set -ev
TAG=$1
REPO=$2
TEST_DIR_IN_REPO=$3
git clone --depth 1 --branch $TAG $REPO test-repo
mkdir src
cp -R test-repo/$TEST_DIR_IN_REPO src/test
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ dependencies {
}

j2objcConfig {
// package-info.java in multiple packages.
filenameCollisionCheck false

// Blocked on https://github.com/j2objc-contrib/j2objc-gradle/issues/465
// to support test-sources.jar.
testMinExpectedTests 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@
dependencies {
j2objcTranslation 'org.joda:joda-convert:1.8:sources'
compile 'com.google.guava:guava:18.0'
testCompile 'junit:junit:4.11'
}

j2objcConfig {
testPattern {
// Do not include subdirectories of convert. Their files prefixed with Test
// are support classes, not tests.
include '**/convert/Test*'
// https://github.com/j2objc-contrib/j2objc-common-libs-e2e-test/issues/46
exclude '**/TestGuavaTypeTokenStringConverter*'
exclude '**/TestJDKStringConverters*'
exclude '**/TestNumericObjectArrayStringConverterFactory*'
exclude '**/TestStringConvert*'
}
autoConfigureDeps true

// No tests in the sources.jar.
testMinExpectedTests 0
finalConfigure()
}
17 changes: 17 additions & 0 deletions libraryBuilds/org.joda-joda-convert/org.joda-joda-convert/prep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
#
# Copyright (c) 2015 the authors of j2objc-common-libs-e2e-test
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

../../common/prep-tests.sh v1.8 https://github.com/JodaOrg/joda-convert src/test
10 changes: 5 additions & 5 deletions libraryBuilds/run-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
# Fail if anything fails.
set -ev

./run-test.sh com.google.code.gson-gson
./run-test.sh org.joda-joda-convert
./run-test.sh joda-time-joda-time
./run-test.sh org.joda-joda-primitives
./run-test.sh org.apache.commons-commons-lang3
./run-test.sh com.google.code.gson-gson build
./run-test.sh org.joda-joda-convert build
./run-test.sh joda-time-joda-time build
./run-test.sh org.joda-joda-primitives build
./run-test.sh org.apache.commons-commons-lang3 build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the "build" and just assume it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this functionality from this PR (see above)

21 changes: 19 additions & 2 deletions libraryBuilds/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,26 @@
set -ev

TEST_DIR=$1
echo Running test $TEST_DIR
pushd $TEST_DIR

echo Preparing test $TEST_DIR

# Execute the prep.sh files within this project, if any.
# These are often used to retrieve test sources for the libraries.
# -L follows symbolic links correctly.
find -L . -name prep.sh | while read PREP_SCRIPT_FILE
do
pushd `dirname $PREP_SCRIPT_FILE`
sh prep.sh
popd
done

echo Running test $TEST_DIR
./gradlew wrapper
./gradlew clean
./gradlew build
# 2nd through last arguments are the gradle tasks to test.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing this? It would allow you to control what tasks you're running but you're not including an example of that. At the very least, please explain what this is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this functionality from this PR (see above)

for task in "${@:2}"; do
./gradlew $task --stacktrace
done
./gradlew assemble
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to do "assemble" before the "build" or other testing tasks. That way, we can more easily distinguish between code that can be used (assemble task) and code that's tested (build task).

popd