From 298aa3c80d3eef800b6eba58f74ea17f84743e8f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mikl=C3=B3s=20T=C3=B3th?= <tothmiklostibor@gmail.com>
Date: Tue, 16 Mar 2021 14:25:39 +0100
Subject: [PATCH] oof

---
 plab/main.go               |  3 +-
 plab/tests/runtest.go      | 34 ++++++++++++++++++
 plab/tests/testsToLatex.go | 72 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+), 1 deletion(-)
 create mode 100644 plab/tests/runtest.go
 create mode 100644 plab/tests/testsToLatex.go

diff --git a/plab/main.go b/plab/main.go
index db1be0c..5d3a708 100644
--- a/plab/main.go
+++ b/plab/main.go
@@ -2,11 +2,12 @@ package main
 
 import (
 	"git.sch.bme.hu/insert-epic-projlab-team-name-here/tooling/plab/helpers"
+	"git.sch.bme.hu/insert-epic-projlab-team-name-here/tooling/plab/tests"
 	"os"
 )
 
 func main() {
-	mainCmds := helpers.CmdFrom(os.Args[0], "go projlab tool", Timetable, Javadoc, Classdiag, Check)
+	mainCmds := helpers.CmdFrom(os.Args[0], "go projlab tool", Timetable, Javadoc, Classdiag, Check, tests.TestsToLatex)
 	if len(os.Args) < 2 {
 		os.Args = append(os.Args, "help")
 	}
diff --git a/plab/tests/runtest.go b/plab/tests/runtest.go
new file mode 100644
index 0000000..2582245
--- /dev/null
+++ b/plab/tests/runtest.go
@@ -0,0 +1,34 @@
+package tests
+
+import (
+	"fmt"
+	"io"
+	"os"
+	"os/exec"
+)
+
+func runTest(name string) error {
+	fmt.Println(name)
+	cmd := exec.Command("java", "-jar", "../src/projlab.jar")
+	file, err := os.Open(name)
+	if err != nil {
+		return err
+	}
+	stdin, err := cmd.StdinPipe()
+	if err != nil {
+		return err
+	}
+	_, err = io.Copy(stdin, file)
+	if err != nil {
+		return err
+	}
+	err = stdin.Close()
+	if err != nil {
+		return err
+	}
+	b, err := cmd.CombinedOutput()
+	if err != nil {
+		fmt.Println(string(b))
+	}
+	return err
+}
diff --git a/plab/tests/testsToLatex.go b/plab/tests/testsToLatex.go
new file mode 100644
index 0000000..653c1eb
--- /dev/null
+++ b/plab/tests/testsToLatex.go
@@ -0,0 +1,72 @@
+package tests
+
+import (
+	"bytes"
+	"fmt"
+	"git.sch.bme.hu/insert-epic-projlab-team-name-here/tooling/plab/helpers"
+	"io/ioutil"
+	"os"
+	"os/exec"
+	"strings"
+)
+
+var TestsToLatex = helpers.Subcommand{
+	Name: "testtolatex",
+	Command: func(args []string) {
+		const dir = "../tests/"
+		tests, e := ioutil.ReadDir(dir)
+		if e != nil {
+			panic(e)
+		}
+		var buf bytes.Buffer
+		for _, t := range tests {
+			e := runTest(dir + t.Name())
+			if e != nil {
+				panic(e)
+			}
+			e = plantumlToLatex()
+			if e != nil {
+				panic(e)
+			}
+			b, e := ioutil.ReadFile("../seq.latex")
+			buf.WriteString("\\subsubsection{")
+			testname := ""
+			tmp := strings.Split(t.Name(), ".")
+			for i, part := range tmp {
+				if i < len(tmp)-1 {
+					testname += part
+				}
+				if i < len(tmp)-2 {
+					testname += "."
+				}
+			}
+			buf.WriteString(testname)
+			buf.WriteString("}\n")
+			buf.WriteString(`
+\begin{figure}[H]
+    \begin{center}
+        \resizebox*{!}{\textheight-2cm}{`)
+			buf.Write(b)
+			buf.WriteString(`
+        }
+    \end{center}
+\end{figure}
+`)
+			buf.WriteString("\n\\newpage\n")
+		}
+		e = ioutil.WriteFile("/tmp/testseq.latex", buf.Bytes(), os.ModePerm)
+		if e != nil {
+			panic(e)
+		}
+	},
+	Help: "gen seq from test into latex",
+}
+
+func plantumlToLatex() error {
+	b, e := exec.Command("plantuml", "-tlatex:nopreamble", "../seq.puml").CombinedOutput()
+	if e != nil {
+		fmt.Println(string(b))
+		return e
+	}
+	return nil
+}
-- 
GitLab