Repository: j178/leetgo (language: python)

Issue:
`testcases.txt` is only used for local testing 
Currently, `testcases.txt` is only used for local testing (`leetgo test -L`). By default (`leetgo test`), tests are run remotely on LeetCode judge server, which is why the cases you added are not working. I will fix this issue in the next version.

_Originally posted by @j178 in https://github.com/j178/leetgo/discussions/220#discussioncomment-6871841_


Discussion / hints:

Fix patch:
diff --git a/lang/gen.go b/lang/gen.go
index 9ab29b6a..4dc5e72f 100644
--- a/lang/gen.go
+++ b/lang/gen.go
@@ -279,3 +279,15 @@ func UpdateSolutionCode(q *leetcode.QuestionData, newCode string) error {
 	log.Info("updated", "file", utils.RelToCwd(codeFile.GetPath()))
 	return nil
 }
+
+func GetTestCases(q *leetcode.QuestionData) (TestCases, error) {
+	result, err := GeneratePathsOnly(q)
+	if err != nil {
+		return TestCases{}, err
+	}
+	testCasesFile := result.GetFile(TestCasesFile)
+	if testCasesFile == nil {
+		return TestCases{}, fmt.Errorf("no test cases file generated")
+	}
+	return ParseTestCases(q, testCasesFile)
+}


Test patch:
diff --git a/cmd/test.go b/cmd/test.go
index bdf585bc..0213958d 100644
--- a/cmd/test.go
+++ b/cmd/test.go
@@ -3,7 +3,6 @@ package cmd
 import (
 	"fmt"
 	"io"
-	"strings"
 	"time"
 
 	"github.com/briandowns/spinner"
@@ -21,7 +20,6 @@ var (
 	runRemotely bool = true
 	runBoth     bool
 	autoSubmit  bool
-	customCases []string
 	targetCase  string
 )
 
@@ -40,7 +38,6 @@ func init() {
 		false,
 		"run test both locally and remotely",
 	)
-	testCmd.Flags().StringSliceVarP(&customCases, "cases", "c", nil, "additional test cases for remote test")
 	testCmd.Flags().BoolVarP(&autoSubmit, "submit", "s", false, "auto submit if all tests passed")
 	testCmd.Flags().StringVarP(&targetCase, "target", "t", "-", "only run the specified test case, e.g. 1, 1-3, -1, 1-")
 }
@@ -161,12 +158,13 @@ func runTestRemotely(
 	if err != nil {
 		return nil, fmt.Errorf("failed to fetch question: %s", err)
 	}
-	cases := q.GetExampleTestCases()
-	cases = append(cases, getCustomCases()...)
-	if len(cases) == 0 {
+	cases, err := lang.GetTestCases(q)
+	if err != nil {
+		return nil, fmt.Errorf("failed to get test cases: %w", err)
+	}
+	if len(cases.Cases) == 0 {
 		return nil, fmt.Errorf("no test cases found")
 	}
-	casesStr := strings.Join(cases, "\n")
 
 	spin := newSpinner(cmd.ErrOrStderr())
 	spin.Suffix = " Running tests..."
@@ -177,7 +175,7 @@ func runTestRemotely(
 	limiter.Take()
 	spin.Reverse()
 
-	interResult, err := c.RunCode(q, gen.Slug(), solution, casesStr)
+	interResult, err := c.RunCode(q, gen.Slug(), solution, cases.InputString())
 	if err != nil {
 		return nil, fmt.Errorf("failed to run test: %w", err)
 	}
@@ -195,14 +193,6 @@ func runTestRemotely(
 	return r, nil
 }
 
-func getCustomCases() []string {
-	cases := make([]string, len(customCases))
-	for i, c := range customCases {
-		cases[i] = strings.ReplaceAll(c, `\n`, "\n")
-	}
-	return cases
-}
-
 func waitResult(c leetcode.Client, submissionId string) (
 	leetcode.CheckResult,
 	error,
diff --git a/lang/test.go b/lang/test.go
index 7f75e0db..ecaf17fa 100644
--- a/lang/test.go
+++ b/lang/test.go
@@ -153,6 +153,8 @@ type TestCases struct {
 }
 
 func (tc *TestCases) AddCase(c TestCase) {
+	c.No = len(tc.Cases) + 1
+	c.Question = tc.Question
 	tc.Cases = append(tc.Cases, c)
 }
 
@@ -179,6 +181,14 @@ func (tc *TestCases) String() string {
 	return buf.String()
 }
 
+func (tc *TestCases) InputString() string {
+	buf := new(bytes.Buffer)
+	for _, c := range tc.Cases {
+		buf.WriteString(c.InputString())
+	}
+	return buf.String()
+}
+
 func (tc *TestCases) Check() error {
 	q := tc.Question
 	err := q.Fulfill()
diff --git a/testutils/cpp/stdc++.h b/testutils/cpp/stdc++.h
index 3bb958f0..e9e8d3a2 100644
--- a/testutils/cpp/stdc++.h
+++ b/testutils/cpp/stdc++.h
@@ -124,7 +124,7 @@
 
 #if __cplusplus >= 201703L
 #include <any>
-#include <charconv>
+// #include <charconv>
 // #include <execution>
 #include <filesystem>
 #include <optional>