Added more tests
This commit is contained in:
@ -5,7 +5,8 @@ import "bytes"
|
||||
// Data represents the static read-only data.
|
||||
type Data []byte
|
||||
|
||||
// Add adds the given bytes to the data block and returns the address relative to the start of the data section.
|
||||
// Add adds the given bytes to the data block if this sequence of bytes doesn't exist yet.
|
||||
// It returns the address relative to the start of the data section.
|
||||
func (data *Data) Add(block []byte) Address {
|
||||
position := bytes.Index(*data, block)
|
||||
|
||||
|
44
src/cli/Main_test.go
Normal file
44
src/cli/Main_test.go
Normal file
@ -0,0 +1,44 @@
|
||||
package cli_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/cli"
|
||||
"git.akyoto.dev/cli/q/src/log"
|
||||
"git.akyoto.dev/go/assert"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
log.Info.SetOutput(io.Discard)
|
||||
log.Error.SetOutput(io.Discard)
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestCLI(t *testing.T) {
|
||||
type cliTest struct {
|
||||
arguments []string
|
||||
expectedExitCode int
|
||||
}
|
||||
|
||||
tests := []cliTest{
|
||||
{[]string{}, 2},
|
||||
{[]string{"invalid"}, 2},
|
||||
{[]string{"system"}, 0},
|
||||
{[]string{"build", "non-existing-directory"}, 1},
|
||||
{[]string{"build", "../../examples/hello/hello.q"}, 1},
|
||||
{[]string{"build", "../../examples/hello", "--invalid"}, 2},
|
||||
{[]string{"build", "../../examples/hello", "--dry"}, 0},
|
||||
{[]string{"build", "../../examples/hello", "--dry", "--verbose"}, 0},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Log(test.arguments)
|
||||
directory, _ := os.Getwd()
|
||||
fmt.Println(directory)
|
||||
exitCode := cli.Main(test.arguments)
|
||||
assert.Equal(t, exitCode, test.expectedExitCode)
|
||||
}
|
||||
}
|
19
src/directory/Walk_test.go
Normal file
19
src/directory/Walk_test.go
Normal file
@ -0,0 +1,19 @@
|
||||
package directory_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/directory"
|
||||
"git.akyoto.dev/go/assert"
|
||||
)
|
||||
|
||||
func TestWalk(t *testing.T) {
|
||||
var files []string
|
||||
|
||||
directory.Walk(".", func(file string) {
|
||||
files = append(files, file)
|
||||
})
|
||||
|
||||
assert.Contains(t, files, "Walk.go")
|
||||
assert.Contains(t, files, "Walk_test.go")
|
||||
}
|
13
src/elf/ELF_test.go
Normal file
13
src/elf/ELF_test.go
Normal file
@ -0,0 +1,13 @@
|
||||
package elf_test
|
||||
|
||||
import (
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"git.akyoto.dev/cli/q/src/elf"
|
||||
)
|
||||
|
||||
func TestELF(t *testing.T) {
|
||||
exe := elf.New(nil, nil)
|
||||
exe.Write(io.Discard)
|
||||
}
|
Reference in New Issue
Block a user