Skip to content

Commit 0806f25

Browse files
committed
Let app/program call also return stderr (actual stderr capturing is not implemented yet) (#28)
1 parent b264fdb commit 0806f25

5 files changed

Lines changed: 27 additions & 16 deletions

File tree

converters/bash/converter.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,11 @@ func (c *converter) FuncCall(name string, args []string, returnTypes []parser.Va
459459
returnValues = append(returnValues, eval)
460460
}
461461
}
462+
463+
// Make sure return values contain as many values as expected.
464+
for len(returnValues) < len(returnTypes) {
465+
returnValues = append(returnValues, "")
466+
}
462467
return returnValues, nil
463468
}
464469

@@ -497,10 +502,10 @@ func (c *converter) AppCall(calls []transpiler.AppCall, valueUsed bool) ([]strin
497502
return nil, err
498503
}
499504
c.VarDefinition(helper2, "$?", false)
500-
return []string{eval, c.varEvaluationString(helper2, false)}, nil
505+
return []string{eval, "", c.varEvaluationString(helper2, false)}, nil // TODO: Return stderr (https://github.com/monstermichl/TypeShell/issues/28).
501506
}
502507
c.addLine(callString)
503-
return []string{}, nil
508+
return []string{"", "", "0"}, nil
504509
}
505510

506511
func (c *converter) Input(prompt string, valueUsed bool) (string, error) {

converters/batch/converter.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,11 @@ func (c *converter) FuncCall(name string, args []string, returnTypes []parser.Va
678678
returnValues = append(returnValues, eval)
679679
}
680680
}
681+
682+
// Make sure return values contain as many values as expected.
683+
for len(returnValues) < len(returnTypes) {
684+
returnValues = append(returnValues, "")
685+
}
681686
return returnValues, nil
682687
}
683688

@@ -718,10 +723,10 @@ func (c *converter) AppCall(calls []transpiler.AppCall, valueUsed bool) ([]strin
718723
return nil, err
719724
}
720725
c.VarAssignment(helper2, c.varEvaluationString("_te", true), false)
721-
return []string{eval, c.varEvaluationString(helper2, false)}, nil
726+
return []string{eval, "", c.varEvaluationString(helper2, false)}, nil // TODO: Return stderr (https://github.com/monstermichl/TypeShell/issues/28).
722727
}
723728
c.addLine(fmt.Sprintf("call %s", strings.Join(callStrings, " | ")))
724-
return []string{}, nil
729+
return []string{"", "", "0"}, nil
725730
}
726731

727732
func (c *converter) Input(prompt string, valueUsed bool) (string, error) {

parser/appcall.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ func (a AppCall) Next() *AppCall {
2828

2929
func (a AppCall) ReturnTypes() []ValueType {
3030
return []ValueType{
31-
NewValueType(DATA_TYPE_STRING, false),
32-
NewValueType(DATA_TYPE_INTEGER, false),
31+
NewValueType(DATA_TYPE_STRING, false), // stdout
32+
NewValueType(DATA_TYPE_STRING, false), // stderr
33+
NewValueType(DATA_TYPE_INTEGER, false), // error code
3334
}
3435
}

tests/appcall_linux_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
func TestLsCallSuccess(t *testing.T) {
1111
transpileBashFunc(t, func(dir string) (string, error) {
1212
return `
13-
` + fmt.Sprintf(`var a, code = @ls("%s")`, dir) + `
13+
` + fmt.Sprintf(`var stdout, stderr, code = @ls("%s")`, dir) + `
1414
15-
print(a, code)
15+
print(stdout, code)
1616
`, nil
1717
}, func(output string, err error) {
1818
require.Nil(t, err)
@@ -23,9 +23,9 @@ func TestLsCallSuccess(t *testing.T) {
2323
func TestLsCallPipeToGrepCallSuccess(t *testing.T) {
2424
transpileBashFunc(t, func(dir string) (string, error) {
2525
return `
26-
` + fmt.Sprintf(`var a, code = @ls("%s") | @grep(".tsh")`, dir) + `
26+
` + fmt.Sprintf(`var stdout, stderr, code = @ls("%s") | @grep(".tsh")`, dir) + `
2727
28-
print(a, code)
28+
print(stdout, code)
2929
`, nil
3030
}, func(output string, err error) {
3131
require.Nil(t, err)
@@ -36,7 +36,7 @@ func TestLsCallPipeToGrepCallSuccess(t *testing.T) {
3636
func TestLsCallFail(t *testing.T) {
3737
transpileBashFunc(t, func(dir string) (string, error) {
3838
return `
39-
var a, code = @ls("not-present-dir")
39+
var stdout, stderr, code = @ls("not-present-dir")
4040
4141
print(code)
4242
`, nil

tests/appcall_windows_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
func TestDirCallSuccess(t *testing.T) {
1212
transpileBatchFunc(t, func(dir string) (string, error) {
1313
return `
14-
` + fmt.Sprintf(`var a, code = @dir("/B", "%s")`, strings.ReplaceAll(dir, `\`, `\\`)) + `
14+
` + fmt.Sprintf(`var stdout, stderr, code = @dir("/B", "%s")`, strings.ReplaceAll(dir, `\`, `\\`)) + `
1515
16-
print(a, code)
16+
print(stdout, code)
1717
`, nil
1818
}, func(output string, err error) {
1919
require.Nil(t, err)
@@ -24,9 +24,9 @@ func TestDirCallSuccess(t *testing.T) {
2424
func TestDirCallPipeToFindstrCallSuccess(t *testing.T) {
2525
transpileBatchFunc(t, func(dir string) (string, error) {
2626
return `
27-
` + fmt.Sprintf(`var a, code = @dir("/B", "%s") | @findstr(".tsh")`, strings.ReplaceAll(dir, `\`, `\\`)) + `
27+
` + fmt.Sprintf(`var stdout, stderr, code = @dir("/B", "%s") | @findstr(".tsh")`, strings.ReplaceAll(dir, `\`, `\\`)) + `
2828
29-
print(a, code)
29+
print(stdout, code)
3030
`, nil
3131
}, func(output string, err error) {
3232
require.Nil(t, err)
@@ -37,7 +37,7 @@ func TestDirCallPipeToFindstrCallSuccess(t *testing.T) {
3737
func TestDirCallFail(t *testing.T) {
3838
transpileBatchFunc(t, func(dir string) (string, error) {
3939
return `
40-
var a, code = @dir("/B", "not-present-dir")
40+
var stdout, stderr, code = @dir("/B", "not-present-dir")
4141
4242
print(code)
4343
`, nil

0 commit comments

Comments
 (0)