1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.cli.commands.metapath;
7   
8   import static org.assertj.core.api.Assertions.assertThat;
9   
10  import gov.nist.secauto.metaschema.cli.CLI;
11  
12  import org.junit.jupiter.api.Test;
13  import org.junit.jupiter.api.parallel.Execution;
14  import org.junit.jupiter.api.parallel.ExecutionMode;
15  
16  import java.io.OutputStream;
17  import java.io.PrintStream;
18  
19  import nl.altindag.log.LogCaptor;
20  
21  @Execution(value = ExecutionMode.SAME_THREAD, reason = "Log capturing needs to be single threaded")
22  class EvaluateMetapathSubCommandTest {
23  
24    /**
25     * A PrintStream that discards all output, used to suppress CLI console output
26     * during tests.
27     */
28    private static final PrintStream NULL_STREAM = new PrintStream(new OutputStream() {
29      @Override
30      public void write(int b) {
31        // discard
32      }
33    });
34  
35    @Test
36    void test() {
37      try (LogCaptor captor = LogCaptor.forRoot()) {
38        String[] args
39            = {
40                "metapath",
41                "eval",
42                "-e",
43                "3 + 4 + 5",
44                "--show-stack-trace" };
45        CLI.runCli(NULL_STREAM, args);
46        assertThat(captor.getInfoLogs().contains("12"));
47      }
48    }
49  }