This is an automated email from the ASF dual-hosted git repository.

Harbs pushed a commit to branch codegraph
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/codegraph by this push:
     new 1428821a8 Add tests for compiler defines in Code Graph: implement 
testCompilerDefinesSelectTargetMembers to verify target labels and 
active-member selection for JS and SWF outputs.
1428821a8 is described below

commit 1428821a82f4cea22ee8f7fcf6a244514fc6ab32
Author: Harbs <[email protected]>
AuthorDate: Fri Jul 31 14:45:25 2026 +0300

    Add tests for compiler defines in Code Graph: implement 
testCompilerDefinesSelectTargetMembers to verify target labels and 
active-member selection for JS and SWF outputs.
---
 CODEGRAPH_EXPORTER_IMPLEMENTATION_PLAN.md          |  2 +-
 .../royale/compiler/clients/TestCODEGRAPH.java     | 32 ++++++++++++++++++++++
 .../codegraph/conditional/ConditionalGraph.as      | 15 ++++++++++
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/CODEGRAPH_EXPORTER_IMPLEMENTATION_PLAN.md 
b/CODEGRAPH_EXPORTER_IMPLEMENTATION_PLAN.md
index ca667d30d..5db62fc7d 100644
--- a/CODEGRAPH_EXPORTER_IMPLEMENTATION_PLAN.md
+++ b/CODEGRAPH_EXPORTER_IMPLEMENTATION_PLAN.md
@@ -294,7 +294,7 @@ Passing the existing suite is necessary but not sufficient: 
the new client must
 - Graph model and deterministic JSON writer.
 - Compiler-backed collection of public types and directly declared members.
 - ASDoc and metadata extraction.
-- JS/SWF fixture tests.
+- JS/SWF fixture tests. Implemented with opposite compiler define sets that 
verify target labels and active-member selection.
 - CLI entry point in `compiler-jx`.
 
 ### PR 2: Completeness
diff --git 
a/compiler-jx/src/test/java/org/apache/royale/compiler/clients/TestCODEGRAPH.java
 
b/compiler-jx/src/test/java/org/apache/royale/compiler/clients/TestCODEGRAPH.java
index c6873fa50..30489930b 100644
--- 
a/compiler-jx/src/test/java/org/apache/royale/compiler/clients/TestCODEGRAPH.java
+++ 
b/compiler-jx/src/test/java/org/apache/royale/compiler/clients/TestCODEGRAPH.java
@@ -94,6 +94,28 @@ public class TestCODEGRAPH
         assertEquals(goldenOutput, firstOutput);
     }
 
+    @Test
+    public void testCompilerDefinesSelectTargetMembers() throws IOException
+    {
+        File sourceDirectory = testAdapter.getUnitTestBaseDir();
+        File sourceFile = new File(sourceDirectory, 
"codegraph/conditional/ConditionalGraph.as");
+        outputFile = new File(testAdapter.getTempDir(), 
"codegraph/ConditionalGraph.json");
+
+        int jsExitCode = compile(sourceFile, sourceDirectory, false, false);
+        assertEquals(problems.toString(), 0, jsExitCode);
+        String jsOutput = FileUtils.readFileToString(outputFile, "UTF-8");
+        assertTrue(jsOutput, jsOutput.contains("\"target\": \"js\""));
+        assertTrue(jsOutput, jsOutput.contains("#jsOnly()"));
+        assertFalse(jsOutput, jsOutput.contains("#swfOnly()"));
+
+        int swfExitCode = compile(sourceFile, sourceDirectory, false, true);
+        assertEquals(problems.toString(), 0, swfExitCode);
+        String swfOutput = FileUtils.readFileToString(outputFile, "UTF-8");
+        assertTrue(swfOutput, swfOutput.contains("\"target\": \"swf\""));
+        assertTrue(swfOutput, swfOutput.contains("#swfOnly()"));
+        assertFalse(swfOutput, swfOutput.contains("#jsOnly()"));
+    }
+
     private int compile(boolean createTargetWithErrors)
     {
         File sourceFile = new File(testAdapter.getUnitTestBaseDir(), 
"codegraph/InvalidCodeGraph.as");
@@ -101,6 +123,11 @@ public class TestCODEGRAPH
     }
 
     private int compile(File sourceFile, File sourceDirectory, boolean 
createTargetWithErrors)
+    {
+        return compile(sourceFile, sourceDirectory, createTargetWithErrors, 
null);
+    }
+
+    private int compile(File sourceFile, File sourceDirectory, boolean 
createTargetWithErrors, Boolean swf)
     {
         File jsSWC = new File("../compiler-externc/target/js.swc");
         List<String> arguments = new ArrayList<String>();
@@ -111,6 +138,11 @@ public class TestCODEGRAPH
             arguments.add("-source-path=" + sourceDirectory.getPath());
         if (createTargetWithErrors)
             arguments.add("-create-target-with-errors=true");
+        if (swf != null)
+        {
+            arguments.add("-define=COMPILE::JS," + !swf);
+            arguments.add("-define+=COMPILE::SWF," + swf);
+        }
         arguments.add(sourceFile.getPath());
 
         problems = new ArrayList<ICompilerProblem>();
diff --git 
a/compiler-jx/src/test/resources/codegraph/conditional/ConditionalGraph.as 
b/compiler-jx/src/test/resources/codegraph/conditional/ConditionalGraph.as
new file mode 100644
index 000000000..608ca0e8e
--- /dev/null
+++ b/compiler-jx/src/test/resources/codegraph/conditional/ConditionalGraph.as
@@ -0,0 +1,15 @@
+package codegraph.conditional
+{
+    public class ConditionalGraph
+    {
+        COMPILE::JS
+        public function jsOnly():void
+        {
+        }
+
+        COMPILE::SWF
+        public function swfOnly():void
+        {
+        }
+    }
+}
\ No newline at end of file

Reply via email to