[FalconJX] imports project test Added a test of a full project aimed at testing the correct creation of 'goog.required' statements. Right now the 'result' files DO NOT represent the eventual expected outcome; this test is more a proof of concept for the 'full project test' capability of TestBase.java.
Signed-off-by: Erik de Bruin <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/c050380d Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/c050380d Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/c050380d Branch: refs/heads/develop Commit: c050380d90c8bd1277e98ef0aaf4b918fe1310a4 Parents: 248da58 Author: Erik de Bruin <[email protected]> Authored: Wed Apr 10 12:05:10 2013 +0200 Committer: Erik de Bruin <[email protected]> Committed: Wed Apr 10 12:05:10 2013 +0200 ---------------------------------------------------------------------- .../internal/codegen/js/goog/TestGoogProject.java | 94 +++++++++++++++ .../test-files/goog/projects/imports/Case.as | 12 ++ .../goog/projects/imports/Case_result.js | 11 ++ .../test-files/goog/projects/imports/comps/A.as | 10 ++ .../goog/projects/imports/comps/A_result.js | 9 ++ .../test-files/goog/projects/imports/comps/B.as | 9 ++ .../goog/projects/imports/comps/B_result.js | 7 + 7 files changed, 152 insertions(+), 0 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c050380d/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogProject.java ---------------------------------------------------------------------- diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogProject.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogProject.java new file mode 100644 index 0000000..1100824 --- /dev/null +++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/goog/TestGoogProject.java @@ -0,0 +1,94 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.flex.compiler.internal.codegen.js.goog; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +import java.io.File; +import java.util.List; + +import org.apache.flex.compiler.driver.IBackend; +import org.apache.flex.compiler.internal.driver.js.goog.GoogBackend; +import org.apache.flex.compiler.internal.test.ASTestBase; +import org.apache.flex.utils.FilenameNormalization; +import org.junit.Test; + +/** + * This class tests the production of valid 'goog' JS code from an external + * project. + * + * @author Erik de Bruin + */ +public class TestGoogProject extends ASTestBase +{ + + private static String projectDirPath = "goog/projects"; + + @Test + public void test_imports() + { + String testDirPath = projectDirPath + "/imports"; + + String fileName = "Case"; + + List<String> compiledFileNames = compileProject(fileName, "test-files" + + File.separator + testDirPath); + + assertProjectOut(compiledFileNames, testDirPath); + } + + @Override + protected void addSourcePaths(List<File> sourcePaths) + { + sourcePaths.add(new File(FilenameNormalization.normalize("test-files" + + File.separator + projectDirPath + "/imports"))); + + super.addSourcePaths(sourcePaths); + } + + @Override + protected IBackend createBackend() + { + return new GoogBackend(); + } + + protected void assertProjectOut(List<String> compiledFileNames, + String testDirPath) + { + for (String compiledFileName : compiledFileNames) + { + String compiledFilePath = tempDir.getAbsolutePath() + + File.separator + testDirPath + File.separator + + compiledFileName + "_output" + "." + + backend.getOutputExtension(); + String compiledResult = readCodeFile(new File(compiledFilePath)); + + String expectedFilePath = new File("test-files").getAbsolutePath() + + File.separator + testDirPath + File.separator + + compiledFileName + "_result" + "." + + backend.getOutputExtension(); + String expectedResult = readCodeFile(new File(expectedFilePath)); + + assertThat(compiledResult, is(expectedResult)); + } + } + +} http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c050380d/compiler.jx.tests/test-files/goog/projects/imports/Case.as ---------------------------------------------------------------------- diff --git a/compiler.jx.tests/test-files/goog/projects/imports/Case.as b/compiler.jx.tests/test-files/goog/projects/imports/Case.as new file mode 100644 index 0000000..4aed38d --- /dev/null +++ b/compiler.jx.tests/test-files/goog/projects/imports/Case.as @@ -0,0 +1,12 @@ +package +{ + import comps.A; + + public class Case + { + public function Case() + { + var bar:A = new A(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c050380d/compiler.jx.tests/test-files/goog/projects/imports/Case_result.js ---------------------------------------------------------------------- diff --git a/compiler.jx.tests/test-files/goog/projects/imports/Case_result.js b/compiler.jx.tests/test-files/goog/projects/imports/Case_result.js new file mode 100644 index 0000000..928234a --- /dev/null +++ b/compiler.jx.tests/test-files/goog/projects/imports/Case_result.js @@ -0,0 +1,11 @@ +goog.provide('Case'); + +goog.require('comps.A'); + +/** + * @constructor + */ +Case = function() { + var self = this; + var /** @type {comps.A} */ bar = new comps.A(); +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c050380d/compiler.jx.tests/test-files/goog/projects/imports/comps/A.as ---------------------------------------------------------------------- diff --git a/compiler.jx.tests/test-files/goog/projects/imports/comps/A.as b/compiler.jx.tests/test-files/goog/projects/imports/comps/A.as new file mode 100644 index 0000000..fda31a6 --- /dev/null +++ b/compiler.jx.tests/test-files/goog/projects/imports/comps/A.as @@ -0,0 +1,10 @@ +package comps +{ + public class A + { + public function A() + { + var foo:B = new B(); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c050380d/compiler.jx.tests/test-files/goog/projects/imports/comps/A_result.js ---------------------------------------------------------------------- diff --git a/compiler.jx.tests/test-files/goog/projects/imports/comps/A_result.js b/compiler.jx.tests/test-files/goog/projects/imports/comps/A_result.js new file mode 100644 index 0000000..5280574 --- /dev/null +++ b/compiler.jx.tests/test-files/goog/projects/imports/comps/A_result.js @@ -0,0 +1,9 @@ +goog.provide('comps.A'); + +/** + * @constructor + */ +comps.A = function() { + var self = this; + var /** @type {comps.B} */ foo = new B(); +}; \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c050380d/compiler.jx.tests/test-files/goog/projects/imports/comps/B.as ---------------------------------------------------------------------- diff --git a/compiler.jx.tests/test-files/goog/projects/imports/comps/B.as b/compiler.jx.tests/test-files/goog/projects/imports/comps/B.as new file mode 100644 index 0000000..38addd5 --- /dev/null +++ b/compiler.jx.tests/test-files/goog/projects/imports/comps/B.as @@ -0,0 +1,9 @@ +package comps +{ + public class B + { + public function B() + { + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c050380d/compiler.jx.tests/test-files/goog/projects/imports/comps/B_result.js ---------------------------------------------------------------------- diff --git a/compiler.jx.tests/test-files/goog/projects/imports/comps/B_result.js b/compiler.jx.tests/test-files/goog/projects/imports/comps/B_result.js new file mode 100644 index 0000000..d487b8a --- /dev/null +++ b/compiler.jx.tests/test-files/goog/projects/imports/comps/B_result.js @@ -0,0 +1,7 @@ +goog.provide('comps.B'); + +/** + * @constructor + */ +comps.B = function() { +}; \ No newline at end of file
