From f29018f9a5ebca12bc49ada6c062b543eb73a320 Mon Sep 17 00:00:00 2001 From: parrt Date: Tue, 24 Nov 2020 12:34:51 -0800 Subject: [PATCH 1/2] allow multiple versions when locating python tool --- .../v4/test/runtime/python/BasePythonTest.java | 15 +++++++++------ .../v4/test/runtime/python2/BasePython2Test.java | 8 ++++++-- .../v4/test/runtime/python3/BasePython3Test.java | 7 +++++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/python/BasePythonTest.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/python/BasePythonTest.java index 06cbfa1af..65545ed26 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/python/BasePythonTest.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/python/BasePythonTest.java @@ -5,6 +5,7 @@ */ package org.antlr.v4.test.runtime.python; +import com.sun.codemodel.internal.JForEach; import org.antlr.v4.Tool; import org.antlr.v4.automata.ATNFactory; import org.antlr.v4.automata.ATNPrinter; @@ -513,31 +514,33 @@ public abstract class BasePythonTest implements RuntimeTestSupport { return null; } - private String locateTool(String tool) { + private String locateTool(List tools) { String[] roots = { "/opt/local/bin", "/usr/bin/", "/usr/local/bin/", "/Users/"+System.getProperty("user.name")+"/anaconda3/bin/" }; for(String root : roots) { - if(new File(root + tool).exists()) { - return root+tool; + for (String tool : tools) { + if ( new File(root+tool).exists() ) { + return root+tool; + } } } - throw new RuntimeException("Could not locate " + tool); + throw new RuntimeException("Could not locate " + tools); } protected String locatePython() { String propName = getPropertyPrefix() + "-python"; String prop = System.getProperty(propName); if(prop==null || prop.length()==0) - prop = locateTool(getPythonExecutable()); + prop = locateTool(getPythonExecutables()); File file = new File(prop); if(!file.exists()) throw new RuntimeException("Missing system property:" + propName); return file.getAbsolutePath(); } - protected abstract String getPythonExecutable(); + protected abstract List getPythonExecutables(); protected String locateRuntime() { return locateRuntime(getLanguage()); } diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/BasePython2Test.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/BasePython2Test.java index aa0eea7e2..ced2665c2 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/BasePython2Test.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/BasePython2Test.java @@ -9,6 +9,10 @@ package org.antlr.v4.test.runtime.python2; import org.antlr.v4.test.runtime.python.BasePythonTest; import org.stringtemplate.v4.ST; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile; public class BasePython2Test extends BasePythonTest { @@ -19,8 +23,8 @@ public class BasePython2Test extends BasePythonTest { } @Override - protected String getPythonExecutable() { - return "python2.7"; + protected List getPythonExecutables() { + return Collections.singletonList("python2.7"); } @Override diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java index 44b0c1294..d0099a4af 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java @@ -8,6 +8,9 @@ package org.antlr.v4.test.runtime.python3; import org.antlr.v4.test.runtime.python.BasePythonTest; import org.stringtemplate.v4.ST; +import java.util.Arrays; +import java.util.List; + import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile; public class BasePython3Test extends BasePythonTest { @@ -18,8 +21,8 @@ public class BasePython3Test extends BasePythonTest { } @Override - protected String getPythonExecutable() { - return "python3.7"; + protected List getPythonExecutables() { + return Arrays.asList("python3.7", "python3.8"); } // force 3.7 @Override From 537eca39715eb02d3ca948f1a68c7e3400e952e1 Mon Sep 17 00:00:00 2001 From: parrt Date: Tue, 24 Nov 2020 12:36:00 -0800 Subject: [PATCH 2/2] tweak doc --- .../test/org/antlr/v4/test/runtime/python3/BasePython3Test.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java index d0099a4af..0c0bc814a 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java @@ -23,7 +23,7 @@ public class BasePython3Test extends BasePythonTest { @Override protected List getPythonExecutables() { return Arrays.asList("python3.7", "python3.8"); - } // force 3.7 + } // force 3.7 or 3.8 @Override protected void writeLexerTestFile(String lexerName, boolean showDFA) {