SimpleCompilationTest.java revision 8b1da958f181639d33dfaa907c0ee66add2decd6
19064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar/* 29064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * Copyright (C) 2015 The Android Open Source Project 39064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * 49064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * Licensed under the Apache License, Version 2.0 (the "License"); 59064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * you may not use this file except in compliance with the License. 69064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * You may obtain a copy of the License at 79064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * 89064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * http://www.apache.org/licenses/LICENSE-2.0 99064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * 109064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * Unless required by applicable law or agreed to in writing, software 119064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * distributed under the License is distributed on an "AS IS" BASIS, 129064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * See the License for the specific language governing permissions and 149064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar * limitations under the License. 159064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar */ 169064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 179064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyarpackage android.databinding.compilationTest; 189064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 199064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 209064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyarimport org.apache.commons.lang3.StringUtils; 219064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyarimport org.junit.Test; 229064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 238b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyarimport java.io.File; 249064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyarimport java.io.IOException; 259064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyarimport java.net.URISyntaxException; 269064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 279064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyarimport static org.junit.Assert.assertEquals; 289064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyarimport static org.junit.Assert.assertNotEquals; 299064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyarimport static org.junit.Assert.assertTrue; 309064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 319064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyarpublic class SimpleCompilationTest extends BaseCompilationTest { 329064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 339064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar @Test 349064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar public void listTasks() throws IOException, URISyntaxException, InterruptedException { 359064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar prepareProject(); 369064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar CompilationResult result = runGradle("tasks"); 379064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar assertEquals(0, result.resultCode); 389064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar assertTrue("there should not be any errors", StringUtils.isEmpty(result.error)); 399064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar assertTrue("Test sanity, empty project tasks", 409064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar result.resultContainsText("All tasks runnable from root project")); 419064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar } 429064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 439064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar @Test 449064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar public void testEmptyCompilation() throws IOException, URISyntaxException, InterruptedException { 459064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar prepareProject(); 469064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar CompilationResult result = runGradle("assembleDebug"); 479064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar assertEquals(0, result.resultCode); 489064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar assertTrue("there should not be any errors " + result.error, StringUtils.isEmpty(result.error)); 499064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar assertTrue("Test sanity, should compile fine", 509064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar result.resultContainsText("BUILD SUCCESSFUL")); 519064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar } 529064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar 539064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar @Test 549064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar public void testUndefinedVariable() throws IOException, URISyntaxException, 559064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar InterruptedException { 569064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar prepareProject(); 579064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar copyResourceTo("/layout/undefined_variable_binding.xml", "/app/src/main/res/layout/broken.xml"); 589064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar CompilationResult result = runGradle("assembleDebug"); 599064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar assertNotEquals(0, result.resultCode); 609064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar assertTrue("Undefined variable", 619064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar result.errorContainsText("Identifiers must have user defined types from the XML file. myVariable is missing it")); 629064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar } 638b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar 648b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar @Test 658b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar public void testSingleModule() throws IOException, URISyntaxException, InterruptedException { 668b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar prepareApp(toMap(KEY_DEPENDENCIES, "compile project(':module1')", 678b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar KEY_SETTINGS_INCLUDES, "include ':app'\ninclude ':module1'")); 688b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar prepareModule("module1", "com.example.module1", toMap()); 698b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar copyResourceTo("/layout/basic_layout.xml", "/module1/src/main/res/layout/module_layout.xml"); 708b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar copyResourceTo("/layout/basic_layout.xml", "/app/src/main/res/layout/app_layout.xml"); 718b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar CompilationResult result = runGradle("assembleDebug"); 728b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar assertEquals(result.error, 0, result.resultCode); 738b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar } 748b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar 758b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar @Test 768b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar public void testTwoLevelDependency() throws IOException, URISyntaxException, InterruptedException { 778b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar prepareApp(toMap(KEY_DEPENDENCIES, "compile project(':module1')", 788b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar KEY_SETTINGS_INCLUDES, "include ':app'\ninclude ':module1'\n" 798b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar + "include ':module2'")); 808b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar prepareModule("module1", "com.example.module1", toMap(KEY_DEPENDENCIES, 818b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar "compile project(':module2')")); 828b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar prepareModule("module2", "com.example.module2", toMap()); 838b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar copyResourceTo("/layout/basic_layout.xml", "/module2/src/main/res/layout/module2_layout.xml"); 848b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar copyResourceTo("/layout/basic_layout.xml", "/module1/src/main/res/layout/module1_layout.xml"); 858b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar copyResourceTo("/layout/basic_layout.xml", "/app/src/main/res/layout/app_layout.xml"); 868b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar CompilationResult result = runGradle("assembleDebug"); 878b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar assertEquals(result.error, 0, result.resultCode); 888b1da958f181639d33dfaa907c0ee66add2decd6Yigit Boyar } 899064a1dd60eb8c2f9d2ed705b36bb5f0b1629771Yigit Boyar} 90