fixes
Some checks failed
judge / Build judge (push) Successful in 8s
judge / Linux / gcc / Debug (push) Successful in 7s
judge / Linux / clang / Release (push) Successful in 9s
judge / Linux / gcc / Release (push) Successful in 10s
judge / Linux / clang / Sanitized (push) Successful in 8s
judge / Linux / gcc / Sanitized (push) Successful in 9s
judge / Linux / gcc / Debug (valgrind) (push) Successful in 15s
judge / Windows / clang / Debug (push) Successful in 37s
judge / Windows / clang / Release (push) Successful in 40s
judge / Windows / msvc / Debug (push) Successful in 45s
judge / Windows / msvc / Release (push) Successful in 43s
judge / SUMMARY (push) Failing after 2s
Some checks failed
judge / Build judge (push) Successful in 8s
judge / Linux / gcc / Debug (push) Successful in 7s
judge / Linux / clang / Release (push) Successful in 9s
judge / Linux / gcc / Release (push) Successful in 10s
judge / Linux / clang / Sanitized (push) Successful in 8s
judge / Linux / gcc / Sanitized (push) Successful in 9s
judge / Linux / gcc / Debug (valgrind) (push) Successful in 15s
judge / Windows / clang / Debug (push) Successful in 37s
judge / Windows / clang / Release (push) Successful in 40s
judge / Windows / msvc / Debug (push) Successful in 45s
judge / Windows / msvc / Release (push) Successful in 43s
judge / SUMMARY (push) Failing after 2s
This commit is contained in:
@@ -176,10 +176,11 @@ jobs:
|
|||||||
echo "" >> SUMMARY.md
|
echo "" >> SUMMARY.md
|
||||||
echo "| Configuration | Score |" >> SUMMARY.md
|
echo "| Configuration | Score |" >> SUMMARY.md
|
||||||
echo "|---|---|" >> SUMMARY.md
|
echo "|---|---|" >> SUMMARY.md
|
||||||
|
shopt -s nullglob
|
||||||
for f in reports/*/*.json; do
|
for f in reports/*/*.json; do
|
||||||
cfg=$(basename "$(dirname "$f")" | sed 's/^report_//')
|
cfg=$(basename "$(dirname "$f")" | sed 's/^report_//')
|
||||||
score=$(grep -o '"TotalScore":[^,}]*' "$f" | head -1 | cut -d: -f2)
|
score=$(grep -o '"total_score":[^,}]*' "$f" | head -1 | cut -d: -f2)
|
||||||
echo "| $cfg | $score |" >> SUMMARY.md
|
echo "| $cfg | ${score:- -} |" >> SUMMARY.md
|
||||||
done
|
done
|
||||||
cat SUMMARY.md
|
cat SUMMARY.md
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Mond1c/judge/dsl"
|
"github.com/Mond1c/judge/dsl"
|
||||||
"github.com/Mond1c/judge/reporter"
|
"github.com/Mond1c/judge/reporter"
|
||||||
@@ -28,23 +28,25 @@ Example:
|
|||||||
`
|
`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
args := os.Args[1:]
|
fs := flag.NewFlagSet("judge", flag.ContinueOnError)
|
||||||
|
fs.SetOutput(os.Stderr)
|
||||||
|
fs.Usage = func() { fmt.Fprint(os.Stderr, usage) }
|
||||||
|
|
||||||
if len(args) == 0 || contains(args, "--help") || contains(args, "-h") {
|
jsonOutput := fs.Bool("json", false, "output as JSON")
|
||||||
fmt.Print(usage)
|
wrapper := fs.String("wrapper", "", "exec wrapper command")
|
||||||
os.Exit(0)
|
binary := fs.String("binary", "", "binary name override")
|
||||||
|
|
||||||
|
if err := fs.Parse(os.Args[1:]); err != nil {
|
||||||
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) < 2 {
|
if fs.NArg() < 2 {
|
||||||
fmt.Fprintf(os.Stderr, "error: need <tests.jdg> and <solution-dir>\n\n%s", usage)
|
fmt.Fprintf(os.Stderr, "error: need <tests.jdg> and <solution-dir>\n\n%s", usage)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
testFile := args[0]
|
testFile := fs.Arg(0)
|
||||||
solutionDir := args[1]
|
solutionDir := fs.Arg(1)
|
||||||
jsonOutput := contains(args, "--json")
|
|
||||||
wrapper := flagValue(args, "--wrapper")
|
|
||||||
binary := flagValue(args, "--binary")
|
|
||||||
|
|
||||||
src, err := os.ReadFile(testFile)
|
src, err := os.ReadFile(testFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -65,12 +67,12 @@ func main() {
|
|||||||
|
|
||||||
r := runner.New(f, runner.Config{
|
r := runner.New(f, runner.Config{
|
||||||
WorkDir: solutionDir,
|
WorkDir: solutionDir,
|
||||||
BinaryName: binary,
|
BinaryName: *binary,
|
||||||
Wrapper: wrapper,
|
Wrapper: *wrapper,
|
||||||
})
|
})
|
||||||
result := r.Run()
|
result := r.Run()
|
||||||
|
|
||||||
if jsonOutput {
|
if *jsonOutput {
|
||||||
if err := reporter.JSON(os.Stdout, result); err != nil {
|
if err := reporter.JSON(os.Stdout, result); err != nil {
|
||||||
fatalf("json output error: %v", err)
|
fatalf("json output error: %v", err)
|
||||||
}
|
}
|
||||||
@@ -87,26 +89,3 @@ func fatalf(msg string, args ...any) {
|
|||||||
fmt.Fprintf(os.Stderr, "error: "+msg+"\n", args...)
|
fmt.Fprintf(os.Stderr, "error: "+msg+"\n", args...)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// flagValue returns the value of --name <value> or --name=value, else "".
|
|
||||||
func flagValue(args []string, name string) string {
|
|
||||||
prefix := name + "="
|
|
||||||
for i, a := range args {
|
|
||||||
if a == name && i+1 < len(args) {
|
|
||||||
return args[i+1]
|
|
||||||
}
|
|
||||||
if strings.HasPrefix(a, prefix) {
|
|
||||||
return a[len(prefix):]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
func contains(slice []string, s string) bool {
|
|
||||||
for _, v := range slice {
|
|
||||||
if v == s {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
// Cross-platform C solution test suite.
|
// Cross-platform C solution test suite.
|
||||||
// $CC is supplied by CI matrix (gcc / clang / cl).
|
// $CC is supplied by CI matrix (gcc / clang / msvc).
|
||||||
//
|
//
|
||||||
// Run locally:
|
// Run locally:
|
||||||
// CC=gcc judge sum.jdg .
|
// CC=gcc judge sum.jdg .
|
||||||
// CC=clang judge sum.jdg .
|
// CC=clang judge sum.jdg .
|
||||||
//
|
//
|
||||||
// Under MSVC on CI we use build_windows (cl's CLI is different).
|
// On Windows, build_windows branches on CC because MSVC's cl has a
|
||||||
|
// different CLI from clang. Executed via `cmd /C`, so %VAR% is cmd syntax.
|
||||||
|
|
||||||
build "$CC -O2 -std=c11 -Wall -Wextra solution.c -o solution"
|
build "$CC -O2 -std=c11 -Wall -Wextra solution.c -o solution"
|
||||||
|
build_windows "if /I \"%CC%\"==\"msvc\" (cl /nologo /O2 /W3 solution.c /Fe:solution.exe) else (%CC% -O2 -std=c11 -Wall -Wextra solution.c -o solution.exe)"
|
||||||
|
|
||||||
binary = "solution"
|
binary = "solution"
|
||||||
timeout 5s
|
timeout 5s
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/Mond1c/judge/dsl"
|
"github.com/Mond1c/judge/dsl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func expandPattern(pattern *dsl.Pattern, groupTimeout interface{ IsZero() bool }) ([]*dsl.Test, error) {
|
func expandPattern(pattern *dsl.Pattern) ([]*dsl.Test, error) {
|
||||||
if pattern.IsDirMode() {
|
if pattern.IsDirMode() {
|
||||||
return expandDirPattern(pattern)
|
return expandDirPattern(pattern)
|
||||||
}
|
}
|
||||||
@@ -105,11 +105,11 @@ func expandDirPattern(pattern *dsl.Pattern) ([]*dsl.Test, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func splitGlob(pattern string) (prefix, suffix string) {
|
func splitGlob(pattern string) (prefix, suffix string) {
|
||||||
idx := strings.Index(pattern, "*")
|
before, after, found := strings.Cut(pattern, "*")
|
||||||
if idx < 0 {
|
if !found {
|
||||||
return pattern, ""
|
return pattern, ""
|
||||||
}
|
}
|
||||||
return pattern[:idx], pattern[idx+1:]
|
return before, after
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractWildcard(path, prefix, suffix string) string {
|
func extractWildcard(path, prefix, suffix string) string {
|
||||||
|
|||||||
@@ -44,9 +44,8 @@ type TestResult struct {
|
|||||||
ActualCode int
|
ActualCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *TestResult) fail(msg string, args ...any) {
|
func (r *TestResult) addFailure(msg string, args ...any) {
|
||||||
r.Failures = append(r.Failures, fmt.Sprintf(msg, args...))
|
r.Failures = append(r.Failures, fmt.Sprintf(msg, args...))
|
||||||
r.Status = StatusFail
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type GroupResult struct {
|
type GroupResult struct {
|
||||||
|
|||||||
@@ -15,14 +15,12 @@ import (
|
|||||||
"github.com/Mond1c/judge/dsl"
|
"github.com/Mond1c/judge/dsl"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MaxOutputBytes caps stdout/stderr captured from the solution process.
|
const MaxOutputBytes = 16 * 1024 * 1024
|
||||||
// Prevents runaway student programs from OOM-ing the judge host.
|
|
||||||
const MaxOutputBytes = 16 * 1024 * 1024 // 16 MiB
|
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
WorkDir string
|
WorkDir string
|
||||||
BinaryName string
|
BinaryName string
|
||||||
Wrapper string // CLI override, wins over DSL wrapper
|
Wrapper string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Runner struct {
|
type Runner struct {
|
||||||
@@ -47,7 +45,6 @@ func New(f *dsl.File, cfg Config) *Runner {
|
|||||||
return &Runner{file: f, cfg: cfg, binary: resolveBinary(absWork, name)}
|
return &Runner{file: f, cfg: cfg, binary: resolveBinary(absWork, name)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveBinary picks <work>/name, falling back to <work>/name.exe on Windows.
|
|
||||||
func resolveBinary(workDir, name string) string {
|
func resolveBinary(workDir, name string) string {
|
||||||
primary := filepath.Join(workDir, name)
|
primary := filepath.Join(workDir, name)
|
||||||
if runtime.GOOS == "windows" && !strings.HasSuffix(strings.ToLower(name), ".exe") {
|
if runtime.GOOS == "windows" && !strings.HasSuffix(strings.ToLower(name), ".exe") {
|
||||||
@@ -90,7 +87,6 @@ func (r *Runner) Run() *SuiteResult {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// After build, re-resolve binary (the exe may have been produced just now).
|
|
||||||
r.binary = resolveBinary(r.cfg.WorkDir, filepath.Base(r.binary))
|
r.binary = resolveBinary(r.cfg.WorkDir, filepath.Base(r.binary))
|
||||||
|
|
||||||
for _, g := range r.file.Groups {
|
for _, g := range r.file.Groups {
|
||||||
@@ -102,7 +98,6 @@ func (r *Runner) Run() *SuiteResult {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildCommand picks the most specific build command for this OS.
|
|
||||||
func (r *Runner) buildCommand() string {
|
func (r *Runner) buildCommand() string {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "windows":
|
case "windows":
|
||||||
@@ -148,8 +143,6 @@ func (r *Runner) build() (string, error) {
|
|||||||
return out.String(), nil
|
return out.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// shellCommand runs a command string through the platform's shell so env vars
|
|
||||||
// like $CC expand naturally from the CI matrix.
|
|
||||||
func shellCommand(ctx context.Context, cmdline string) *exec.Cmd {
|
func shellCommand(ctx context.Context, cmdline string) *exec.Cmd {
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
return exec.CommandContext(ctx, "cmd", "/C", cmdline)
|
return exec.CommandContext(ctx, "cmd", "/C", cmdline)
|
||||||
@@ -166,7 +159,7 @@ func (r *Runner) runGroup(g *dsl.Group) *GroupResult {
|
|||||||
tests := g.Tests
|
tests := g.Tests
|
||||||
|
|
||||||
if g.Pattern != nil {
|
if g.Pattern != nil {
|
||||||
expanded, err := expandPattern(g.Pattern, &zeroChecker{})
|
expanded, err := expandPattern(g.Pattern)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gr.Tests = append(gr.Tests, &TestResult{
|
gr.Tests = append(gr.Tests, &TestResult{
|
||||||
Name: "pattern_expand",
|
Name: "pattern_expand",
|
||||||
@@ -177,16 +170,6 @@ func (r *Runner) runGroup(g *dsl.Group) *GroupResult {
|
|||||||
gr.Score = 0
|
gr.Score = 0
|
||||||
return gr
|
return gr
|
||||||
}
|
}
|
||||||
for _, t := range expanded {
|
|
||||||
if t.Timeout == 0 {
|
|
||||||
t.Timeout = g.Timeout
|
|
||||||
}
|
|
||||||
for k, v := range g.Env {
|
|
||||||
if _, ok := t.Env[k]; !ok {
|
|
||||||
t.Env[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tests = append(tests, expanded...)
|
tests = append(tests, expanded...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +217,7 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
|||||||
tmpDir, err := os.MkdirTemp("", "judge-test-*")
|
tmpDir, err := os.MkdirTemp("", "judge-test-*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tr.Status = StatusRuntimeError
|
tr.Status = StatusRuntimeError
|
||||||
tr.Failures = append(tr.Failures, fmt.Sprintf("failed to create temp dir: %v", err))
|
tr.addFailure("failed to create temp dir: %v", err)
|
||||||
return tr
|
return tr
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
@@ -242,11 +225,13 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
|||||||
for name, content := range t.InFiles {
|
for name, content := range t.InFiles {
|
||||||
path := filepath.Join(tmpDir, name)
|
path := filepath.Join(tmpDir, name)
|
||||||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||||
tr.fail("mkdir for file %q: %v", name, err)
|
tr.Status = StatusRuntimeError
|
||||||
|
tr.addFailure("mkdir for file %q: %v", name, err)
|
||||||
return tr
|
return tr
|
||||||
}
|
}
|
||||||
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
|
if err := os.WriteFile(path, []byte(content), 0644); err != nil {
|
||||||
tr.fail("write input file %q: %v", name, err)
|
tr.Status = StatusRuntimeError
|
||||||
|
tr.addFailure("write input file %q: %v", name, err)
|
||||||
return tr
|
return tr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,7 +244,6 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
// Wrapper precedence: CLI flag > test > group (already copied into test).
|
|
||||||
wrapper := r.cfg.Wrapper
|
wrapper := r.cfg.Wrapper
|
||||||
if wrapper == "" {
|
if wrapper == "" {
|
||||||
wrapper = t.Wrapper
|
wrapper = t.Wrapper
|
||||||
@@ -269,8 +253,6 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
|||||||
cmd.Dir = tmpDir
|
cmd.Dir = tmpDir
|
||||||
|
|
||||||
cmd.Env = os.Environ()
|
cmd.Env = os.Environ()
|
||||||
// Force C locale so numeric formatting (decimal separator, etc.) is stable
|
|
||||||
// across runners. Student code can still override via test env.
|
|
||||||
cmd.Env = append(cmd.Env, "LC_ALL=C", "LANG=C")
|
cmd.Env = append(cmd.Env, "LC_ALL=C", "LANG=C")
|
||||||
for k, v := range t.Env {
|
for k, v := range t.Env {
|
||||||
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
|
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
|
||||||
@@ -293,12 +275,12 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
|||||||
tr.ActualStderr = normalizeOutput(stderr.String(), r.file)
|
tr.ActualStderr = normalizeOutput(stderr.String(), r.file)
|
||||||
|
|
||||||
if stdout.truncated || stderr.truncated {
|
if stdout.truncated || stderr.truncated {
|
||||||
tr.fail("output truncated at %d bytes (possible runaway output)", MaxOutputBytes)
|
tr.addFailure("output truncated at %d bytes (possible runaway output)", MaxOutputBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Err() == context.DeadlineExceeded {
|
if ctx.Err() == context.DeadlineExceeded {
|
||||||
tr.Status = StatusTLE
|
tr.Status = StatusTLE
|
||||||
tr.Failures = append(tr.Failures, fmt.Sprintf("time limit exceeded (%v)", timeout))
|
tr.addFailure("time limit exceeded (%v)", timeout)
|
||||||
return tr
|
return tr
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,46 +290,43 @@ func (r *Runner) runTest(t *dsl.Test) *TestResult {
|
|||||||
actualCode = exitErr.ExitCode()
|
actualCode = exitErr.ExitCode()
|
||||||
} else {
|
} else {
|
||||||
tr.Status = StatusRuntimeError
|
tr.Status = StatusRuntimeError
|
||||||
tr.fail("runtime error: %v", runErr)
|
tr.addFailure("runtime error: %v", runErr)
|
||||||
return tr
|
return tr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tr.ActualCode = actualCode
|
tr.ActualCode = actualCode
|
||||||
|
|
||||||
if t.ExitCode != nil && actualCode != *t.ExitCode {
|
if t.ExitCode != nil && actualCode != *t.ExitCode {
|
||||||
tr.fail("exit code: expected %d, got %d", *t.ExitCode, actualCode)
|
tr.addFailure("exit code: expected %d, got %d", *t.ExitCode, actualCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range applyMatcher("stdout", t.Stdout, tr.ActualStdout) {
|
for _, f := range applyMatcher("stdout", t.Stdout, tr.ActualStdout) {
|
||||||
tr.fail("%s", f)
|
tr.addFailure("%s", f)
|
||||||
}
|
}
|
||||||
for _, f := range applyMatcher("stderr", t.Stderr, tr.ActualStderr) {
|
for _, f := range applyMatcher("stderr", t.Stderr, tr.ActualStderr) {
|
||||||
tr.fail("%s", f)
|
tr.addFailure("%s", f)
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, expected := range t.OutFiles {
|
for name, expected := range t.OutFiles {
|
||||||
path := filepath.Join(tmpDir, name)
|
path := filepath.Join(tmpDir, name)
|
||||||
content, err := os.ReadFile(path)
|
content, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tr.fail("output file %q not found: %v", name, err)
|
tr.addFailure("output file %q not found: %v", name, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
actual := normalizeOutput(string(content), r.file)
|
actual := normalizeOutput(string(content), r.file)
|
||||||
for _, f := range applyMatcher(fmt.Sprintf("file(%s)", name), dsl.ExactMatcher{Value: expected}, actual) {
|
for _, f := range applyMatcher(fmt.Sprintf("file(%s)", name), dsl.ExactMatcher{Value: expected}, actual) {
|
||||||
tr.fail("%s", f)
|
tr.addFailure("%s", f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(tr.Failures) > 0 {
|
if tr.Status == StatusPass && len(tr.Failures) > 0 {
|
||||||
tr.Status = StatusFail
|
tr.Status = StatusFail
|
||||||
}
|
}
|
||||||
|
|
||||||
return tr
|
return tr
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildExecCmd creates an exec.Cmd for the solution, optionally prefixed with
|
|
||||||
// a wrapper (gdb, valgrind, qemu, ...). Wrapper is a shell string so users can
|
|
||||||
// pass flags like "valgrind --error-exitcode=99 --leak-check=full".
|
|
||||||
func buildExecCmd(ctx context.Context, wrapper, binary string, args []string) *exec.Cmd {
|
func buildExecCmd(ctx context.Context, wrapper, binary string, args []string) *exec.Cmd {
|
||||||
if wrapper == "" {
|
if wrapper == "" {
|
||||||
return exec.CommandContext(ctx, binary, args...)
|
return exec.CommandContext(ctx, binary, args...)
|
||||||
@@ -358,7 +337,6 @@ func buildExecCmd(ctx context.Context, wrapper, binary string, args []string) *e
|
|||||||
return exec.CommandContext(ctx, full[0], full[1:]...)
|
return exec.CommandContext(ctx, full[0], full[1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// normalizeOutput applies the file-level CRLF / trailing-WS rules.
|
|
||||||
func normalizeOutput(s string, f *dsl.File) string {
|
func normalizeOutput(s string, f *dsl.File) string {
|
||||||
if f.NormalizeCRLF {
|
if f.NormalizeCRLF {
|
||||||
s = strings.ReplaceAll(s, "\r\n", "\n")
|
s = strings.ReplaceAll(s, "\r\n", "\n")
|
||||||
@@ -374,8 +352,6 @@ func normalizeOutput(s string, f *dsl.File) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// cappedBuffer stops writing once limit bytes are captured, but keeps draining
|
|
||||||
// the source so the child process doesn't block on a full pipe.
|
|
||||||
type cappedBuffer struct {
|
type cappedBuffer struct {
|
||||||
buf bytes.Buffer
|
buf bytes.Buffer
|
||||||
limit int
|
limit int
|
||||||
@@ -386,7 +362,7 @@ func (c *cappedBuffer) Write(p []byte) (int, error) {
|
|||||||
room := c.limit - c.buf.Len()
|
room := c.limit - c.buf.Len()
|
||||||
if room <= 0 {
|
if room <= 0 {
|
||||||
c.truncated = true
|
c.truncated = true
|
||||||
return len(p), nil // pretend we wrote, to keep the pipe flowing
|
return len(p), nil
|
||||||
}
|
}
|
||||||
if len(p) > room {
|
if len(p) > room {
|
||||||
c.buf.Write(p[:room])
|
c.buf.Write(p[:room])
|
||||||
@@ -399,7 +375,3 @@ func (c *cappedBuffer) Write(p []byte) (int, error) {
|
|||||||
func (c *cappedBuffer) String() string { return c.buf.String() }
|
func (c *cappedBuffer) String() string { return c.buf.String() }
|
||||||
|
|
||||||
var _ io.Writer = (*cappedBuffer)(nil)
|
var _ io.Writer = (*cappedBuffer)(nil)
|
||||||
|
|
||||||
type zeroChecker struct{}
|
|
||||||
|
|
||||||
func (z *zeroChecker) IsZero() bool { return true }
|
|
||||||
|
|||||||
Reference in New Issue
Block a user