View Javadoc
1   package io.jawk.gawk;
2   
3   /*-
4    * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5    * Jawk
6    * ჻჻჻჻჻჻
7    * Copyright (C) 2006 - 2026 MetricsHub
8    * ჻჻჻჻჻჻
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU Lesser General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Lesser Public License for more details.
18   *
19   * You should have received a copy of the GNU General Lesser Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
23   */
24  
25  import static org.junit.Assume.assumeTrue;
26  
27  import java.io.IOException;
28  import java.nio.charset.StandardCharsets;
29  import java.nio.file.Files;
30  import java.nio.file.Path;
31  import io.jawk.CompatibilityTestResources;
32  
33  /**
34   * Shared helpers for the explicit gawk compatibility integration suites
35   * transcribed from the vendored GNU Awk test suite.
36   */
37  abstract class AbstractGawkSuite {
38  
39  	protected static final Path GAWK_DIRECTORY = CompatibilityTestResources
40  			.resourceDirectory(AbstractGawkSuite.class, "gawk");
41  	protected static final String NON_ZERO_TRANSCRIPT_REASON = "This case compares a non-zero gawk CLI transcript, which is intentionally skipped in the explicit AwkTestSupport.cliTest suite.";
42  	protected static final String NON_UTF8_STDIN_REASON = "This case redirects stdin that is not valid UTF-8, which is intentionally skipped in the explicit AwkTestSupport.cliTest suite.";
43  	protected static final String NON_UTF8_EXPECTED_REASON = "This case uses an expected .ok file that is not valid UTF-8, which is intentionally skipped in the explicit AwkTestSupport.cliTest suite.";
44  	protected static final String MANUAL_SKIP_REASON = "Handwritten gawk case from Makefile.am not yet expressed as an AwkTestSupport.cliTest case.";
45  
46  	protected static Path gawkPath(String fileName) {
47  		return GAWK_DIRECTORY.resolve(fileName);
48  	}
49  
50  	protected static String gawkFile(String fileName) {
51  		return gawkPath(fileName).toString();
52  	}
53  
54  	protected static String gawkText(String fileName) throws IOException {
55  		return new String(Files.readAllBytes(gawkPath(fileName)), StandardCharsets.UTF_8);
56  	}
57  
58  	protected static void skip(String reason) {
59  		assumeTrue(reason, false);
60  	}
61  }