T6907575.java revision 2942:08092deced3f
1/*
2 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26/*
27 * @test
28 * @bug 6907575
29 * @modules jdk.jdeps/com.sun.tools.classfile
30 *          jdk.compiler/com.sun.tools.javac.file
31 *          jdk.compiler/com.sun.tools.javac.util
32 * @build GetDeps p.C1
33 * @run main T6907575
34 */
35
36import java.io.*;
37
38public class T6907575 {
39    public static void main(String... args) throws Exception {
40        new T6907575().run();
41    }
42
43    void run() throws Exception {
44        String testSrc = System.getProperty("test.src");
45        String testClasses = System.getProperty("test.classes");
46
47        StringWriter sw = new StringWriter();
48        PrintWriter pw = new PrintWriter(sw);
49        GetDeps gd = new GetDeps();
50        gd.run(pw, "-classpath", testClasses, "-t", "-p", "p", "p/C1");
51        pw.close();
52        System.out.println(sw);
53
54        String ref = readFile(new File(testSrc, "T6907575.out"));
55        diff(sw.toString().replaceAll("[\r\n]+", "\n"), ref);
56    }
57
58    void diff(String actual, String ref) throws Exception {
59        System.out.println("EXPECT:>>>" + ref + "<<<");
60        System.out.println("ACTUAL:>>>" + actual + "<<<");
61        if (!actual.equals(ref))
62            throw new Exception("output not as expected");
63    }
64
65    String readFile(File f) throws IOException {
66        Reader r = new FileReader(f);
67        char[] buf = new char[(int) f.length()];
68        int offset = 0;
69        int n;
70        while (offset < buf.length && (n = r.read(buf, offset, buf.length - offset)) != -1)
71            offset += n;
72        return new String(buf, 0, offset);
73    }
74}
75