langtools/test/tools/javac/classfiles/attributes/lib/TestBase.java
author anazarov
Thu, 24 Jul 2014 15:12:48 -0700
changeset 25845 14935053bb07
parent 25434 823512a72660
child 26101 d5dd2ecd2353
permissions -rw-r--r--
8050979: Provide javadoc for "framework" classes in langtools tests Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
     1
/*
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
     4
 *
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
     8
 *
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    13
 * accompanied this code).
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    14
 *
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    18
 *
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    21
 * questions.
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    22
 */
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    23
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    24
import java.io.File;
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    25
import java.io.IOException;
25845
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    26
import java.util.List;
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    27
import java.util.Objects;
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    28
import java.util.function.Function;
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    29
import java.util.stream.Stream;
25845
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    30
import javax.tools.DiagnosticCollector;
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    31
import javax.tools.JavaCompiler;
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    32
import javax.tools.JavaFileObject;
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    33
import javax.tools.ToolProvider;
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    34
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    35
import static java.lang.String.format;
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    36
import static java.lang.System.lineSeparator;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    37
import static java.util.Arrays.asList;
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    38
import static java.util.Collections.emptyList;
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    39
import static java.util.stream.Collectors.joining;
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    40
import static java.util.stream.Collectors.toList;
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    41
25845
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    42
/**
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    43
 * Base class for class file attribute tests.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    44
 * Contains methods for compiling generated sources in memory,
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    45
 * for reading files from disk and a lot of assert* methods.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    46
 */
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    47
public class TestBase {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
    48
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    49
    public static final String LINE_SEPARATOR = lineSeparator();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    50
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    51
    private <S> InMemoryFileManager compile(
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    52
            List<String> options,
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    53
            Function<S, ? extends JavaFileObject> src2JavaFileObject,
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    54
            List<S> sources)
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    55
            throws IOException, CompilationException {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    56
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    57
        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    58
        List<? extends JavaFileObject> src = sources.stream()
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    59
                .map(src2JavaFileObject)
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    60
                .collect(toList());
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    61
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    62
        DiagnosticCollector<? super JavaFileObject> dc = new DiagnosticCollector<>();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    63
        try (InMemoryFileManager fileManager
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    64
                     = new InMemoryFileManager(compiler.getStandardFileManager(null, null, null))) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    65
            JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, dc, options, null, src);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    66
            boolean success = task.call();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    67
            if (!success) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    68
                String errorMessage = dc.getDiagnostics().stream()
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    69
                        .map(Object::toString)
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    70
                        .collect(joining("\n"));
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    71
                throw new CompilationException("Compilation Error\n\n" + errorMessage);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    72
            }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    73
            return fileManager;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    74
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    75
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    76
25845
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    77
    /**
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    78
     * Compiles sources in memory.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    79
     *
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    80
     * @param sources to compile.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    81
     * @return memory file manager which contains class files and class loader.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    82
     */
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    83
    public InMemoryFileManager compile(String... sources)
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    84
            throws IOException, CompilationException {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    85
        return compile(emptyList(), sources);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    86
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    87
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    88
    /**
25845
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    89
     * Compiles sources in memory.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    90
     *
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    91
     * @param options compiler options.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    92
     * @param sources sources to compile.
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    93
     * @return map where key is className, value is corresponding ClassFile.
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    94
     */
25845
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
    95
    public InMemoryFileManager compile(List<String> options, String... sources)
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    96
            throws IOException, CompilationException {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    97
        return compile(options, ToolBox.JavaSource::new, asList(sources));
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    98
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
    99
25845
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   100
    /**
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   101
     * Compiles sources in memory.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   102
     *
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   103
     * @param sources sources[i][0] - name of file, sources[i][1] - sources.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   104
     * @return map where key is className, value is corresponding ClassFile.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   105
     */
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   106
    public InMemoryFileManager compile(String[]... sources) throws IOException,
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   107
            CompilationException {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   108
        return compile(emptyList(), sources);
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   109
    }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   110
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   111
    /**
25845
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   112
     * Compiles sources in memory.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   113
     *
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   114
     * @param options compiler options
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   115
     * @param sources sources[i][0] - name of file, sources[i][1] - sources.
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   116
     * @return map where key is className, value is corresponding ClassFile.
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   117
     */
25845
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   118
    public InMemoryFileManager compile(List<String> options, String[]... sources)
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   119
            throws IOException, CompilationException {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   120
        return compile(options, src -> new ToolBox.JavaSource(src[0], src[1]), asList(sources));
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   121
    }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   122
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   123
    public void assertEquals(Object actual, Object expected, String message) {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   124
        if (!Objects.equals(actual, expected))
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   125
            throw new AssertionFailedException(format("%s%nGot: %s, Expected: %s", message, actual, expected));
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   126
    }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   127
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   128
    public void assertNull(Object actual, String message) {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   129
        assertEquals(actual, null, message);
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   130
    }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   131
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   132
    public void assertNotNull(Object actual, String message) {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   133
        if (Objects.isNull(actual)) {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   134
            throw new AssertionFailedException(message + " : Expected not null value");
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   135
        }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   136
    }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   137
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   138
    public void assertTrue(boolean actual, String message) {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   139
        assertEquals(actual, true, message);
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   140
    }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   141
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   142
    public void assertFalse(boolean actual, String message) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   143
        assertEquals(actual, false, message);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   144
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   145
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   146
    public File getSourceDir() {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   147
        return new File(System.getProperty("test.src", "."));
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   148
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   149
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   150
    public File getClassDir() {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   151
        return new File(System.getProperty("test.classes", TestBase.class.getResource(".").getPath()));
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   152
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   153
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   154
    public File getSourceFile(String fileName) {
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   155
        return new File(getSourceDir(), fileName);
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   156
    }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   157
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   158
    public File getClassFile(String fileName) {
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   159
        return new File(getClassDir(), fileName);
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   160
    }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   161
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   162
    public File getClassFile(Class clazz) {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   163
        return getClassFile(clazz.getName().replace(".", "/") + ".class");
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   164
    }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   165
25845
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   166
    /**
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   167
     * Prints message to standard error. New lines are converted to system dependent NL.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   168
     *
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   169
     * @param message string to print.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   170
     */
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   171
    public void echo(String message) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   172
        System.err.println(message.replace("\n", LINE_SEPARATOR));
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   173
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   174
25845
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   175
    /**
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   176
     * Substitutes args in template and prints result to standard error. New lines are converted to system dependent NL.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   177
     *
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   178
     * @param template template in standard String.format(...) format.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   179
     * @param args arguments to substitute in template.
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   180
     */
14935053bb07 8050979: Provide javadoc for "framework" classes in langtools tests
anazarov
parents: 25434
diff changeset
   181
    public void printf(String template, Object... args) {
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   182
        System.err.printf(template, Stream.of(args)
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   183
                .map(Objects::toString)
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   184
                .map(m -> m.replace("\n", LINE_SEPARATOR))
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   185
                .collect(toList())
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   186
                .toArray());
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   187
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   188
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents: 24223
diff changeset
   189
24223
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   190
    public static class CompilationException extends Exception {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   191
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   192
        public CompilationException(String message) {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   193
            super(message);
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   194
        }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   195
    }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   196
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   197
    public static class AssertionFailedException extends RuntimeException {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   198
        public AssertionFailedException(String message) {
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   199
            super(message);
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   200
        }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   201
    }
90b07e33a49d 8040097: Implement classfile tests for LocalVariableTable and LocalVariableTypeTable attribute.
anazarov
parents:
diff changeset
   202
}