From e8a7f502d699028313d129957ad0ba5a0cbe1412 Mon Sep 17 00:00:00 2001 From: Advay Mengle Date: Mon, 24 Aug 2015 14:19:04 -0700 Subject: [PATCH] Multi-project system test. Fixes #407 --- systemTests/multiProject1/base/build.gradle | 32 ++++++++++++++++ .../base/src/main/java/com/example/Cube.java | 37 ++++++++++++++++++ .../src/test/java/com/example/CubeTest.java | 33 ++++++++++++++++ systemTests/multiProject1/build.gradle | 36 ++++++++++++++++++ .../multiProject1/extended/build.gradle | 35 +++++++++++++++++ .../main/java/com/example/ExtendedCube.java | 38 +++++++++++++++++++ .../java/com/example/ExtendedCubeTest.java | 33 ++++++++++++++++ systemTests/multiProject1/gradlew | 1 + systemTests/multiProject1/local.properties | 1 + systemTests/multiProject1/settings.gradle | 16 ++++++++ systemTests/run-all.sh | 21 +++++++++- 11 files changed, 281 insertions(+), 2 deletions(-) create mode 100644 systemTests/multiProject1/base/build.gradle create mode 100644 systemTests/multiProject1/base/src/main/java/com/example/Cube.java create mode 100644 systemTests/multiProject1/base/src/test/java/com/example/CubeTest.java create mode 100644 systemTests/multiProject1/build.gradle create mode 100644 systemTests/multiProject1/extended/build.gradle create mode 100644 systemTests/multiProject1/extended/src/main/java/com/example/ExtendedCube.java create mode 100644 systemTests/multiProject1/extended/src/test/java/com/example/ExtendedCubeTest.java create mode 120000 systemTests/multiProject1/gradlew create mode 120000 systemTests/multiProject1/local.properties create mode 100644 systemTests/multiProject1/settings.gradle diff --git a/systemTests/multiProject1/base/build.gradle b/systemTests/multiProject1/base/build.gradle new file mode 100644 index 00000000..6a6908e4 --- /dev/null +++ b/systemTests/multiProject1/base/build.gradle @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ + +apply plugin: 'java' +apply plugin: 'com.github.j2objccontrib.j2objcgradle' + +repositories { + jcenter() +} + +dependencies { + // Intentionally testing e2e use of a built-in j2objc library, Guava. + compile 'com.google.guava:guava:17.0' + testCompile 'junit:junit:4.12' +} + +j2objcConfig { + finalConfigure() +} diff --git a/systemTests/multiProject1/base/src/main/java/com/example/Cube.java b/systemTests/multiProject1/base/src/main/java/com/example/Cube.java new file mode 100644 index 00000000..f6d84cdd --- /dev/null +++ b/systemTests/multiProject1/base/src/main/java/com/example/Cube.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ + +package com.example; + +import com.google.common.base.Joiner; + +public class Cube { + + protected final int dimension; + + public Cube(int dimension) { + this.dimension = dimension; + } + + @Override + public String toString() { + return String.format("[Cube %d]", dimension); + } + + public String exerciseGuava() { + return Joiner.on(' ').join('a', 'b', 'c'); + } +} diff --git a/systemTests/multiProject1/base/src/test/java/com/example/CubeTest.java b/systemTests/multiProject1/base/src/test/java/com/example/CubeTest.java new file mode 100644 index 00000000..9c3a39cb --- /dev/null +++ b/systemTests/multiProject1/base/src/test/java/com/example/CubeTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ + +package com.example; + +import org.junit.Assert; +import org.junit.Test; + +public class CubeTest { + + @Test + public void testToString() { + Assert.assertEquals("[Cube 7]", new Cube(7).toString()); + } + + @Test + public void testExerciseGuava() { + Assert.assertEquals("a b c", new Cube(7).exerciseGuava()); + } +} diff --git a/systemTests/multiProject1/build.gradle b/systemTests/multiProject1/build.gradle new file mode 100644 index 00000000..0282b5b1 --- /dev/null +++ b/systemTests/multiProject1/build.gradle @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ + +buildscript { + repositories { + jcenter() + } + dependencies { + // This is the build output of the plugin itself. + classpath fileTree(dir: '../../build/libs', include: ['*.jar']) + } +} + +allprojects { + apply plugin: 'java' + test { + testLogging { + // Provide full exception info on failure, instead + // of just pointing to an HTML file. + exceptionFormat = 'full' + } + } +} diff --git a/systemTests/multiProject1/extended/build.gradle b/systemTests/multiProject1/extended/build.gradle new file mode 100644 index 00000000..4102b325 --- /dev/null +++ b/systemTests/multiProject1/extended/build.gradle @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ + +apply plugin: 'java' +apply plugin: 'com.github.j2objccontrib.j2objcgradle' + +repositories { + jcenter() +} + +dependencies { + compile project(':base') + // Intentionally testing e2e use of a built-in j2objc library, Guava. + compile 'com.google.guava:guava:17.0' + testCompile 'junit:junit:4.12' +} + +j2objcConfig { + dependsOnJ2objcLib project(':base') + + finalConfigure() +} diff --git a/systemTests/multiProject1/extended/src/main/java/com/example/ExtendedCube.java b/systemTests/multiProject1/extended/src/main/java/com/example/ExtendedCube.java new file mode 100644 index 00000000..405df92d --- /dev/null +++ b/systemTests/multiProject1/extended/src/main/java/com/example/ExtendedCube.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ + +package com.example; + +import java.lang.Override; + +import com.google.common.base.Joiner; + +public class ExtendedCube extends Cube { + + public ExtendedCube(int dimension) { + super(dimension); + } + + @Override + public String toString() { + return String.format("[ExtendedCube %d]", dimension); + } + + @Override + public String exerciseGuava() { + return Joiner.on(';').join('a', 'b', 'c'); + } +} diff --git a/systemTests/multiProject1/extended/src/test/java/com/example/ExtendedCubeTest.java b/systemTests/multiProject1/extended/src/test/java/com/example/ExtendedCubeTest.java new file mode 100644 index 00000000..a79ffa03 --- /dev/null +++ b/systemTests/multiProject1/extended/src/test/java/com/example/ExtendedCubeTest.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ + +package com.example; + +import org.junit.Assert; +import org.junit.Test; + +public class ExtendedCubeTest { + + @Test + public void testToString() { + Assert.assertEquals("[ExtendedCube 7]", new ExtendedCube(7).toString()); + } + + @Test + public void testExerciseGuava() { + Assert.assertEquals("a;b;c", new ExtendedCube(7).exerciseGuava()); + } +} diff --git a/systemTests/multiProject1/gradlew b/systemTests/multiProject1/gradlew new file mode 120000 index 00000000..343e0d2c --- /dev/null +++ b/systemTests/multiProject1/gradlew @@ -0,0 +1 @@ +../../gradlew \ No newline at end of file diff --git a/systemTests/multiProject1/local.properties b/systemTests/multiProject1/local.properties new file mode 120000 index 00000000..217624b1 --- /dev/null +++ b/systemTests/multiProject1/local.properties @@ -0,0 +1 @@ +../common/local.properties \ No newline at end of file diff --git a/systemTests/multiProject1/settings.gradle b/systemTests/multiProject1/settings.gradle new file mode 100644 index 00000000..6d7aacc9 --- /dev/null +++ b/systemTests/multiProject1/settings.gradle @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2015 the authors of j2objc-gradle (see AUTHORS file) + * + * 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. + */ +include ':base', ':extended' diff --git a/systemTests/run-all.sh b/systemTests/run-all.sh index cb449786..618bb88e 100755 --- a/systemTests/run-all.sh +++ b/systemTests/run-all.sh @@ -17,5 +17,22 @@ # Fail if anything fails. set -e -echo Running test simple1 -pushd simple1 && ./gradlew wrapper && ./gradlew clean && ./gradlew build && popd +function runTest { + TEST_DIR=$1 + echo Running test $TEST_DIR + set -e + pushd $TEST_DIR + ./gradlew wrapper + ./gradlew clean + ./gradlew build + popd +} + +# TODO: Might want to infer the directories that have build.gradle files in them. + +# Simplest possible set-up. A single project with no dependencies. +runTest simple1 + +# Two gradle projects, `extended` depends on `base`. They also both test +# dependency on built-in j2objc libraries, like Guava. +runTest multiProject1