Skip to content

Commit 90f8294

Browse files
committed
Update: CmdTest
1 parent e2ce1f4 commit 90f8294

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

helper/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The commands are:
1717
page build index.md file
1818
tag build all tags file
1919
helper build helper file
20-
question build problem description file
20+
question build problem solution file
2121
open open a problem solution in browser
2222
test run go test
2323
description build all problems description file

internal/test/test.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,36 @@ package test
33
import (
44
"os"
55
"os/exec"
6+
"strconv"
67

78
"github.com/openset/leetcode/internal/base"
9+
"github.com/openset/leetcode/internal/leetcode"
810
)
911

1012
var CmdTest = &base.Command{
1113
Run: runTest,
12-
UsageLine: "test",
14+
UsageLine: "test [QuestionId]",
1315
Short: "run go test",
1416
Long: "automates testing the packages.",
1517
}
1618

1719
func runTest(cmd *base.Command, args []string) {
18-
if len(args) != 0 {
20+
if len(args) > 1 {
1921
cmd.Usage()
2022
}
21-
c := exec.Command("go", "test", "./...")
23+
target := "./..."
24+
if len(args) == 1 {
25+
if questionId, err := strconv.Atoi(args[0]); err == nil {
26+
problems := leetcode.ProblemsAll()
27+
for _, problem := range problems.StatStatusPairs {
28+
if problem.Stat.FrontendQuestionId == questionId {
29+
target = "./problems/" + problem.Stat.QuestionTitleSlug
30+
break
31+
}
32+
}
33+
}
34+
}
35+
c := exec.Command("go", "test", target)
2236
c.Stdout = os.Stdout
2337
c.Stderr = os.Stderr
2438
err := c.Run()

0 commit comments

Comments
 (0)