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

hectorespert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new fa7acbc  [NETBEANS-4500] Fixed tests for PHP Editor on Windows
     new f21769a  Merge pull request #2223 from 
KacerCZ/netbeans-4500-fix-php-editor-tests
fa7acbc is described below

commit fa7acbcde97aa081c42dca2696e8129258cb5493
Author: Tomas Prochazka <ka...@razdva.cz>
AuthorDate: Mon Jun 29 20:54:43 2020 +0200

    [NETBEANS-4500] Fixed tests for PHP Editor on Windows
    
    - Use UTF-8 when opening files.
    - Use system-specific directory separators.
    - Enabled tests in Github Actions.
---
 .github/workflows/main.yml                         |  2 +-
 .travis.yml                                        |  1 +
 .../netbeans/modules/csl/api/test/CslTestBase.java |  2 +-
 .../editor/verification/IntroduceSuggestion.java   |  5 +++--
 ...Suggestion.php.testIntroduceSuggestion_01.hints |  2 +-
 .../php/editor/js/JsFormatterEmbeddedTest.java     | 12 ++++++++++++
 .../php/editor/parser/PhpParserErrorTest.java      | 12 ++++++++++++
 .../modules/php/editor/verification/HintsTest.java | 22 ++++++++++++++++++++++
 8 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 29ef6f5..abab7a7 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -62,7 +62,7 @@ jobs:
           ant -f php/php.composer test
           ant -f php/php.dbgp test
           ant -f php/php.doctrine2 test
-          # ant -f php/php.editor test
+          ant -f php/php.editor test
           ant -f php/php.latte test
           ant -f php/php.nette.tester test
           ant -f php/php.phpunit test
diff --git a/.travis.yml b/.travis.yml
index a73199c..12dc8ed 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -679,6 +679,7 @@ matrix:
             - ant $OPTS -f php/php.composer test
             #- ant $OPTS -f php/php.dbgp test
             - ant $OPTS -f php/php.doctrine2 test
+            # PHP Editor tests can't be run on Travis because they run 90 
minutes.
             #- ant $OPTS -f php/php.editor test
             - ant $OPTS -f php/php.latte test
             - ant $OPTS -f php/php.nette.tester test
diff --git 
a/ide/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java 
b/ide/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java
index bb1448f..711b019 100644
--- 
a/ide/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java
+++ 
b/ide/csl.api/test/unit/src/org/netbeans/modules/csl/api/test/CslTestBase.java
@@ -423,7 +423,7 @@ public abstract class CslTestBase extends NbTestCase {
                     }
 
                     InputStream is = fo.getInputStream();
-                    BufferedReader reader = new BufferedReader(new 
InputStreamReader(is));
+                    BufferedReader reader = new BufferedReader(new 
InputStreamReader(is, StandardCharsets.UTF_8));
 
                     while (true) {
                         String line = reader.readLine();
diff --git 
a/php/php.editor/src/org/netbeans/modules/php/editor/verification/IntroduceSuggestion.java
 
b/php/php.editor/src/org/netbeans/modules/php/editor/verification/IntroduceSuggestion.java
index c5c0e085..b622ffc 100644
--- 
a/php/php.editor/src/org/netbeans/modules/php/editor/verification/IntroduceSuggestion.java
+++ 
b/php/php.editor/src/org/netbeans/modules/php/editor/verification/IntroduceSuggestion.java
@@ -18,6 +18,7 @@
  */
 package org.netbeans.modules.php.editor.verification;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collection;
@@ -465,11 +466,11 @@ public class IntroduceSuggestion extends SuggestionRule {
             int length = fileName.length();
             if (length > 30) {
                 fileName = fileName.substring(length - 30);
-                final int indexOf = fileName.indexOf("/");
+                final int indexOf = fileName.indexOf(File.separator);
                 if (indexOf != -1) { //NOI18N
                     fileName = fileName.substring(indexOf);
                 }
-                fileName = String.format("...%s/%s.php", fileName, className); 
//NOI18N
+                fileName = String.format("...%s%s%s.php", fileName, 
File.separator, className); //NOI18N
             }
             return Bundle.IntroduceHintClassDesc(classNameWithNsPart, 
fileName);
         }
diff --git 
a/php/php.editor/test/unit/data/testfiles/verification/testIntroduceSuggestion.php.testIntroduceSuggestion_01.hints
 
b/php/php.editor/test/unit/data/testfiles/verification/testIntroduceSuggestion.php.testIntroduceSuggestion_01.hints
index 16058db..6162b63 100644
--- 
a/php/php.editor/test/unit/data/testfiles/verification/testIntroduceSuggestion.php.testIntroduceSuggestion_01.hints
+++ 
b/php/php.editor/test/unit/data/testfiles/verification/testIntroduceSuggestion.php.testIntroduceSuggestion_01.hints
@@ -1,4 +1,4 @@
 new MyClass();^
 -------------
 HINT:Introduce Hint
-FIX:Create Class "MyClass" in .../data/testfiles/verification/MyClass.php
+FIX:Create Class "MyClass" in 
...%SEP%data%SEP%testfiles%SEP%verification%SEP%MyClass.php
diff --git 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/js/JsFormatterEmbeddedTest.java
 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/js/JsFormatterEmbeddedTest.java
index 2621b90..4782dee 100644
--- 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/js/JsFormatterEmbeddedTest.java
+++ 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/js/JsFormatterEmbeddedTest.java
@@ -19,6 +19,8 @@
 
 package org.netbeans.modules.php.editor.js;
 
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import junit.framework.Test;
 import org.netbeans.api.html.lexer.HTMLTokenId;
 import org.netbeans.junit.NbModuleSuite;
@@ -27,6 +29,9 @@ import org.netbeans.modules.html.editor.lib.api.HtmlVersion;
 import org.netbeans.modules.javascript2.lexer.api.JsTokenId;
 import org.netbeans.modules.php.editor.PHPTestBase;
 import org.netbeans.modules.php.editor.lexer.PHPTokenId;
+import org.netbeans.spi.queries.FileEncodingQueryImplementation;
+import org.openide.filesystems.FileObject;
+import org.openide.util.test.MockLookup;
 
 public class JsFormatterEmbeddedTest extends PHPTestBase {
 
@@ -58,6 +63,13 @@ public class JsFormatterEmbeddedTest extends PHPTestBase {
         } catch (IllegalStateException ise) {
             // Ignore -- we've already registered this either via layers or 
other means
         }
+
+        MockLookup.setInstances(new FileEncodingQueryImplementation() {
+            @Override
+            public Charset getEncoding(FileObject file) {
+                return StandardCharsets.UTF_8;
+            }
+        });
     }
 
     public void testEmbeddedSimple1() throws Exception {
diff --git 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/parser/PhpParserErrorTest.java
 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/parser/PhpParserErrorTest.java
index 9124b7b..b01e16b 100644
--- 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/parser/PhpParserErrorTest.java
+++ 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/parser/PhpParserErrorTest.java
@@ -18,7 +18,12 @@
  */
 package org.netbeans.modules.php.editor.parser;
 
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import org.netbeans.modules.php.editor.PHPTestBase;
+import org.netbeans.spi.queries.FileEncodingQueryImplementation;
+import org.openide.filesystems.FileObject;
+import org.openide.util.test.MockLookup;
 
 /**
  *
@@ -33,6 +38,13 @@ public class PhpParserErrorTest extends PHPTestBase {
     @Override
     protected void setUp() throws Exception {
         super.setUp();
+
+        MockLookup.setInstances(new FileEncodingQueryImplementation() {
+            @Override
+            public Charset getEncoding(FileObject file) {
+                return StandardCharsets.UTF_8;
+            }
+        });
     }
 
     @Override
diff --git 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/HintsTest.java
 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/HintsTest.java
index 222662a..ffcbc01 100644
--- 
a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/HintsTest.java
+++ 
b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/verification/HintsTest.java
@@ -18,6 +18,11 @@
  */
 package org.netbeans.modules.php.editor.verification;
 
+import java.io.File;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import org.netbeans.modules.php.api.PhpVersion;
 import org.openide.filesystems.FileObject;
 
@@ -31,6 +36,13 @@ public class HintsTest extends PHPHintsTestBase {
         super(testName);
     }
 
+    @Override
+    protected File getDataFile(String relFilePath) {
+        // Overriden because CslTestBase loads file from different location.
+        File inputFile = new File(getDataDir(), relFilePath);
+        return inputFile;
+    }
+
     public void testModifiersCheckHint() throws Exception {
         checkHints(new ModifiersCheckHintError(), 
"testModifiersCheckHint.php");
     }
@@ -149,6 +161,8 @@ public class HintsTest extends PHPHintsTestBase {
     }
 
     public void testIntroduceSuggestion_01() throws Exception {
+        // Needs to replace directory separators in expected result.
+        fixContent(new File(getDataDir(), getTestDirectory() + 
"testIntroduceSuggestion.php.testIntroduceSuggestion_01.hints"));
         checkHints(new IntroduceSuggestion(), "testIntroduceSuggestion.php", 
"new MyClass();^");
     }
 
@@ -730,6 +744,14 @@ public class HintsTest extends PHPHintsTestBase {
         checkHints(new FieldRedeclarationHintError(), 
"testFieldRedeclarationTypedProperties20Hint_02.php");
     }
 
+    private void fixContent(File file) throws Exception {
+        Path path = file.toPath();
+        Charset charset = StandardCharsets.UTF_8;
+        String content = new String(Files.readAllBytes(path), charset);
+        content = content.replace("%SEP%", File.separator);
+        Files.write(path, content.getBytes(charset));
+    }
+
     //~ Inner classes
     private static final class ImplementAbstractMethodsHintErrorStub extends 
ImplementAbstractMethodsHintError {
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to