Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/T8033180.java
32285 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 803318026* @summary Bad newline characters27*/2829import java.io.*;30import java.util.*;3132public class T8033180 {3334public static void main(String... args) throws Exception {35new T8033180().run();36}3738void run() throws Exception {39// fast-track this case, because test cannot fail in this case40if (lineSep.equals(nl))41return;4243test("-help");44test("-version");4546if (errors > 0)47throw new Exception(errors + " errors occurred");48}4950static final String lineSep = System.getProperty("line.separator");51static final String nl = "\n";5253void test(String... opts) throws Exception {54System.err.println("test " + Arrays.asList(opts));55List<String> args = new ArrayList<String>();56args.addAll(Arrays.asList(opts));57StringWriter sw = new StringWriter();58PrintWriter pw = new PrintWriter(sw);59int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);60pw.close();61String out = sw.toString();62if (rc != 0)63throw new Exception("javap failed unexpectedly: rc=" + rc);6465// remove all valid platform newline sequences66String out2 = out.replace(lineSep, "");6768// count the remaining simple newline characters69int count = 0;70int i = out2.indexOf(nl, 0);71while (i != -1) {72count++;73i = out2.indexOf(nl, i + nl.length());74}7576if (count > 0)77error(count + " newline characters found");78}7980void error(String msg) {81System.err.println("Error: " + msg);82errors++;83}8485int errors = 0;86}87888990