private void testScriptFile(String scriptText, List<String> argList, String expectedPattern,
          TestBeeLineWithArgs.OutStream outStream) throws Throwable {
    File scriptFile = File.createTempFile(this.getClass().getSimpleName(), "temp");
    scriptFile.deleteOnExit();
    try (PrintStream os = new PrintStream(new FileOutputStream(scriptFile))) {
      os.print(scriptText);
    }
    List<String> copy = new ArrayList<>(argList);
    copy.add("-f");
    copy.add(scriptFile.getAbsolutePath());
    String output = testCommandLineScript(copy, null, outStream);
    if (scriptText.equals("SELECT UNIX_TIMESTAMP()")) {
      Pattern pattern = Pattern.compile("\\|\\s*(\\d+)\\s*\\|");
      Matcher matcher = pattern.matcher(output);
      long expected = Long.parseLong(expectedPattern), actual = 0;
      if (matcher.find()) {
        actual = Long.parseLong(matcher.group(1));
        if (Math.abs(actual - expected) > 5) {
          output = String.valueOf(actual);
        } else {
          output = expectedPattern;
        }
      }
    }
    if (!Pattern.compile(".*" + expectedPattern + ".*", Pattern.DOTALL).matcher(output).matches()) {
      fail("Output: '" + output + "' should match " + expectedPattern);
    }
    scriptFile.delete();
  }
Start up a local Hive Server 2 for these tests
itests/hive-unit/src/test/java/org/apache/hive/beeline/TestHplSqlViaBeeLine.java