Skip to content

Commit

Permalink
fix(std:scanln): don't use buffers because it didn't work well in tes…
Browse files Browse the repository at this point in the history
…t env (and maybe problem was biffer than just tests); fix(e2e): upd tests after movign from interpreter
  • Loading branch information
emil14 committed Oct 6, 2024
1 parent a5dd540 commit 732fc50
Show file tree
Hide file tree
Showing 36 changed files with 304 additions and 185 deletions.
30 changes: 30 additions & 0 deletions e2e/add_nums_from_stdin_naive/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package test

import (
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func Test(t *testing.T) {
for i := 0; i < 1; i++ {
t.Run("Add numbers from stdin", func(t *testing.T) {
cmd := exec.Command("neva", "run", "main")

cmd.Stdin = strings.NewReader("3\n4\n\n")

out, err := cmd.CombinedOutput()
require.NoError(t, err)

require.Equal(
t,
"7\n",
string(out),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
})
}
}
12 changes: 6 additions & 6 deletions e2e/add_nums_from_stdin_naive/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ flow Main(start any) (stop any) {
scanner2 io.Scanln
parser1 strconv.ParseNum<int>
parser2 strconv.ParseNum<int>
adder ReducePort<int> { Add<int> }
add Add<int>
println Println<int>
---
:start -> scanner1:sig
scanner1:data-> parser1:data
parser1:res -> [adder:port[0], scanner2:sig]
scanner2:data -> parser2:data
parser2:res -> adder:port[1]
adder:res -> println:data
scanner1:res -> parser1:data
parser1:res -> [add:acc, scanner2:sig]
scanner2:res -> parser2:data
parser2:res -> add:el
add:res -> println:data
println:sig -> :stop
}
30 changes: 30 additions & 0 deletions e2e/add_nums_from_stdin_with_default_any/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package test

import (
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func Test(t *testing.T) {
for i := 0; i < 1; i++ {
t.Run("Add numbers from stdin", func(t *testing.T) {
cmd := exec.Command("neva", "run", "main")

cmd.Stdin = strings.NewReader("3\n4\n\n")

out, err := cmd.CombinedOutput()
require.NoError(t, err)

require.Equal(
t,
"7\n",
string(out),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
})
}
}
10 changes: 5 additions & 5 deletions e2e/add_nums_from_stdin_with_default_any/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ flow Main(start) (stop) {
flow Aux(sig) (res int, err error) {
reader1 IntReader
reader2 IntReader
adder ReducePort<int> { Add<int> }
add Add<int>
---
:sig -> reader1:sig
reader1:num -> [adder:port[0], reader2:sig]
reader1:num -> [add:acc, reader2:sig]
[reader1:err, reader2:err] -> :err
reader2:num -> adder:port[1]
adder:res -> :res
reader2:num -> add:el
add:res -> :res
}

flow IntReader(sig any) (num int, err error) {
io.Scanln, strconv.ParseNum<int>
---
:sig -> scanln:sig
scanln:data -> parseNum:data
scanln:res -> parseNum:data
parseNum:res -> :num
parseNum:err -> :err
}
30 changes: 30 additions & 0 deletions e2e/add_nums_from_stdin_with_err_handling/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package test

import (
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func Test(t *testing.T) {
for i := 0; i < 1; i++ {
t.Run("Add numbers from stdin", func(t *testing.T) {
cmd := exec.Command("neva", "run", "main")

cmd.Stdin = strings.NewReader("3\n4\n\n")

out, err := cmd.CombinedOutput()
require.NoError(t, err)

require.Equal(
t,
"7\n",
string(out),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
})
}
}
16 changes: 7 additions & 9 deletions e2e/add_nums_from_stdin_with_err_handling/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ flow Main(start any) (stop any) {
scanner2 io.Scanln
parser1 strconv.ParseNum<int>
parser2 strconv.ParseNum<int>
adder ReducePort<int> { Add<int> }
add Add<int>
println Println<any>
---
:start -> scanner1:sig
scanner1:data -> parser1:data
parser1:err -> println:data
parser1:res -> [adder:port[0], scanner2:sig]
scanner2:data -> parser2:data
parser2:err -> println:data
parser2:res -> adder:port[1]
adder:res -> println:data
scanner1:res -> parser1:data
parser1:res -> [add:acc, scanner2:sig]
scanner2:res -> parser2:data
parser2:res -> add:el
println:sig -> :stop
}
[parser1:err, parser2:err, add:res] -> println:data
}
30 changes: 30 additions & 0 deletions e2e/add_nums_from_stdin_with_multuple_senders/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package test

import (
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func Test(t *testing.T) {
for i := 0; i < 1; i++ {
t.Run("Add numbers from stdin", func(t *testing.T) {
cmd := exec.Command("neva", "run", "main")

cmd.Stdin = strings.NewReader("3\n4\n\n")

out, err := cmd.CombinedOutput()
require.NoError(t, err)

require.Equal(
t,
"7\n",
string(out),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
})
}
}
10 changes: 5 additions & 5 deletions e2e/add_nums_from_stdin_with_multuple_senders/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ flow Main(start) (stop) {
flow Aux(sig) (res int, err error) {
reader1 IntReader
reader2 IntReader
adder ReducePort<int> { Add<int> }
add Add<int>
---
:sig -> reader1:sig
reader1:num -> [adder:port[0], reader2:sig]
reader1:num -> [add:acc, reader2:sig]
[reader1:err, reader2:err] -> :err
reader2:num -> adder:port[1]
adder:res -> :res
reader2:num -> add:el
add:res -> :res
}

flow IntReader(sig any) (num int, err error) {
io.Scanln, strconv.ParseNum<int>
---
:sig -> scanln:sig
scanln:data -> parseNum:data
scanln:res -> parseNum:data
parseNum:res -> :num
parseNum:err -> :err
}
30 changes: 30 additions & 0 deletions e2e/add_nums_from_stdin_with_sub_components/e2e_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package test

import (
"os/exec"
"strings"
"testing"

"github.com/stretchr/testify/require"
)

func Test(t *testing.T) {
for i := 0; i < 1; i++ {
t.Run("Add numbers from stdin", func(t *testing.T) {
cmd := exec.Command("neva", "run", "main")

cmd.Stdin = strings.NewReader("3\n4\n\n")

out, err := cmd.CombinedOutput()
require.NoError(t, err)

require.Equal(
t,
"7\n",
string(out),
)

require.Equal(t, 0, cmd.ProcessState.ExitCode())
})
}
}
13 changes: 6 additions & 7 deletions e2e/add_nums_from_stdin_with_sub_components/main/main.neva
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,28 @@ flow Main(start any) (stop any) {
Aux, Println<any>
---
:start -> aux:sig
aux:res -> println:data
aux:err -> println:data
[aux:res, aux:err] -> println:data
println:sig -> :stop
}

flow Aux(sig any) (res int, err error) {
reader1 IntReader
reader2 IntReader
adder ReducePort<int> { Add<int> }
add Add<int>
---
:sig -> reader1:sig
reader1:num -> [adder:port[0], reader2:sig]
reader1:num -> [add:acc, reader2:sig]
reader1:err -> :err
reader2:err -> :err
reader2:num -> adder:port[1]
adder:res -> :res
reader2:num -> add:el
add:res -> :res
}

flow IntReader(sig any) (num int, err error) {
io.Scanln, strconv.ParseNum<int>
---
:sig -> scanln:sig
scanln:data -> parseNum:data
scanln:res -> parseNum:data
parseNum:res -> :num
parseNum:err -> :err
}
8 changes: 2 additions & 6 deletions e2e/add_nums_verbose/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
flow Main(start any) (stop any) {
adder Add<int>
sequencer ArrPortToStream<int>
println Println<int>

---

:start -> [
(1 -> sequencer:port[0]),
(2 -> sequencer:port[1])
(1 -> adder:acc),
(2 -> adder:el)
]
sequencer:data -> adder:data
adder:res -> println:data
println:sig -> :stop
}
22 changes: 0 additions & 22 deletions e2e/add_nums_with_bridge/e2e_test.go

This file was deleted.

13 changes: 0 additions & 13 deletions e2e/add_nums_with_bridge/main/main.neva

This file was deleted.

1 change: 0 additions & 1 deletion e2e/add_nums_with_bridge/neva.yml

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/comments/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Test(t *testing.T) {
require.NoError(t, err)
require.Equal(
t,
"<base>\n",
"{}\n",
string(out),
)

Expand Down
6 changes: 3 additions & 3 deletions e2e/echo_verbose/main/main.neva
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { io }

flow Main(start any) (stop any) {
scanner io.Scanln
io.Scanln
println Println<string>
---
:start -> scanner:sig
scanner:data -> println:data
:start -> scanln:sig
scanln:res -> println:data
println:sig -> :stop
}
2 changes: 1 addition & 1 deletion e2e/enums_verbose/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func Test(t *testing.T) {
require.NoError(t, err)
require.Equal(
t,
"4\n",
"Friday\n",
string(out),
)

Expand Down
Loading

0 comments on commit 732fc50

Please sign in to comment.