@@ -15,18 +15,19 @@ import (
1515 "github.com/stretchr/testify/require"
1616)
1717
18+ type sourceCallout func (dir string ) string
1819type compareCallout func (output string , err error )
1920type transpilerFunc func (t * testing.T , source string , compare compareCallout )
2021
21- func transpile (t * testing.T , source string , targetFileName string , converter transpiler.Converter , compare compareCallout ) {
22+ func transpileFunc (t * testing.T , source sourceCallout , targetFileName string , converter transpiler.Converter , compare compareCallout ) {
2223 trans := transpiler .New ()
2324 dir , err := os .MkdirTemp ("" , "typeshell_tests" )
2425
2526 require .Nil (t , err )
2627 defer os .RemoveAll (dir )
2728
2829 file := filepath .Join (dir , "test.tsh" )
29- err = os .WriteFile (file , []byte (source ), 0x777 )
30+ err = os .WriteFile (file , []byte (source ( dir ) ), 0x777 )
3031
3132 require .Nil (t , err )
3233 code , err := trans .Transpile (file , converter )
@@ -48,14 +49,28 @@ func transpile(t *testing.T, source string, targetFileName string, converter tra
4849 compare (outputString , err )
4950}
5051
52+ func transpile (t * testing.T , source string , targetFileName string , converter transpiler.Converter , compare compareCallout ) {
53+ transpileFunc (t , func (_ string ) string {
54+ return source
55+ }, targetFileName , converter , compare )
56+ }
57+
5158func transpileBash (t * testing.T , source string , compare compareCallout ) {
5259 transpile (t , source , "test.sh" , bash .New (), compare )
5360}
5461
62+ func transpileBashFunc (t * testing.T , source sourceCallout , compare compareCallout ) {
63+ transpileFunc (t , source , "test.sh" , bash .New (), compare )
64+ }
65+
5566func transpileBatch (t * testing.T , source string , compare compareCallout ) {
5667 transpile (t , source , "test.bat" , batch .New (), compare )
5768}
5869
70+ func transpileBatchFunc (t * testing.T , source sourceCallout , compare compareCallout ) {
71+ transpileFunc (t , source , "test.bat" , batch .New (), compare )
72+ }
73+
5974func shortenError (err error ) error {
6075 if err != nil {
6176 s := err .Error ()
0 commit comments