From 8103faa8b6708716fd6dfc55b9f53f6918977a9a Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 9 Jul 2024 12:13:59 +0200 Subject: [PATCH] Simplified tests --- tests/programs_test.go | 72 ++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 38 deletions(-) diff --git a/tests/programs_test.go b/tests/programs_test.go index 3b494c5..5dcc84c 100644 --- a/tests/programs_test.go +++ b/tests/programs_test.go @@ -15,26 +15,26 @@ var programs = []struct { ExpectedOutput string ExpectedExitCode int }{ - {"empty.q", "", 0}, - {"math.q", "", 10}, - {"precedence.q", "", 10}, - {"square-sum.q", "", 25}, - {"chained-calls.q", "", 9}, - {"nested-calls.q", "", 4}, - {"overwrite.q", "", 3}, - {"reuse.q", "", 3}, - {"return.q", "", 6}, - {"reassign.q", "", 2}, - {"branch.q", "", 0}, - {"branch-and.q", "", 0}, - {"branch-or.q", "", 0}, - {"branch-combined.q", "", 0}, + {"empty", "", 0}, + {"math", "", 10}, + {"precedence", "", 10}, + {"square-sum", "", 25}, + {"chained-calls", "", 9}, + {"nested-calls", "", 4}, + {"overwrite", "", 3}, + {"reuse", "", 3}, + {"return", "", 6}, + {"reassign", "", 2}, + {"branch", "", 0}, + {"branch-and", "", 0}, + {"branch-or", "", 0}, + {"branch-combined", "", 0}, } func TestPrograms(t *testing.T) { for _, test := range programs { t.Run(test.Name, func(t *testing.T) { - run(t, filepath.Join("programs", test.Name), test.ExpectedOutput, test.ExpectedExitCode) + run(t, filepath.Join("programs", test.Name+".q"), test.ExpectedOutput, test.ExpectedExitCode) }) } } @@ -57,34 +57,30 @@ func run(t *testing.T, name string, expectedOutput string, expectedExitCode int) b := build.New(name) assert.True(t, len(b.Executable()) > 0) - t.Run("Compile", func(t *testing.T) { - result, err := b.Run() - assert.Nil(t, err) + result, err := b.Run() + assert.Nil(t, err) - err = result.Write(b.Executable()) - assert.Nil(t, err) + err = result.Write(b.Executable()) + assert.Nil(t, err) - stat, err := os.Stat(b.Executable()) - assert.Nil(t, err) - assert.True(t, stat.Size() > 0) - }) + stat, err := os.Stat(b.Executable()) + assert.Nil(t, err) + assert.True(t, stat.Size() > 0) - t.Run("Output", func(t *testing.T) { - cmd := exec.Command(b.Executable()) - output, err := cmd.Output() - exitCode := 0 + cmd := exec.Command(b.Executable()) + output, err := cmd.Output() + exitCode := 0 - if err != nil { - exitError, ok := err.(*exec.ExitError) + if err != nil { + exitError, ok := err.(*exec.ExitError) - if !ok { - t.Fatal(exitError) - } - - exitCode = exitError.ExitCode() + if !ok { + t.Fatal(exitError) } - assert.Equal(t, exitCode, expectedExitCode) - assert.DeepEqual(t, string(output), expectedOutput) - }) + exitCode = exitError.ExitCode() + } + + assert.Equal(t, exitCode, expectedExitCode) + assert.DeepEqual(t, string(output), expectedOutput) }