Skip to content

Commit

Permalink
Cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
wunderbarb committed Nov 24, 2024
1 parent f570cce commit 28995a1
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 157 deletions.
41 changes: 10 additions & 31 deletions 4test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// V 0.9.0
// v0.9.1
// Author: DIEHL E.
// (C) Sony Pictures Entertainment, Jan 2021
// © Sony Pictures Entertainment, Nov 2024

package test

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

Expand All @@ -20,37 +19,16 @@ var (
testCounter = 1
)

// CLI executes the command `app` with the parameters `params`.
// `expErr` indicates whether an error is expected. If the expectation
// is not met, then it outputs the full CLI command that failed.
//
// DEPRECATED CLI should be repalced by githyb.com/wunderbarb/syst.Run using
// option WithVerboseTest.
func CLI(expErr bool, app string, params ...string) ([]byte, error) {
cmd := exec.Command(app, params...)
answer, err := cmd.Output()
if (err == nil) == expErr {
s := app
for _, p := range params {
s += " " + p
}
fmt.Printf("failed on: %s\n", s)
}
return answer, err
}

// CompareFiles returns true if files f1 and f2 are identical
func CompareFiles(f1 string, f2 string) bool {
cmp := equalfile.New(nil, equalfile.Options{}) // compare using single mode
equal, _ := cmp.CompareFile(f1, f2)
return equal
}

// Describe displays the order of the test, the name of the function
// and its optional description provided by 'msg'. It initializes an assert
// and a require and returns them.
func Describe(t *testing.T, msg ...string) (*require.Assertions,
*assert.Assertions) {
// Describe displays the order of the test, the name of the function and its optional description provided by 'msg'.
// It initializes an assert and require and returns them.
func Describe(t *testing.T, msg ...string) (*require.Assertions, *assert.Assertions) {

dispMsg := ""
if len(msg) != 0 {
Expand All @@ -63,14 +41,15 @@ func Describe(t *testing.T, msg ...string) (*require.Assertions,
}

// Describeb displays the order of the test, the name of the function
// and its optional description provided by 'msg'.
//
// and its optional description provided by 'msg'.
func Describeb(b *testing.B, msg ...string) {

dispMsg := ""
dspMsg := ""
if len(msg) != 0 {
dispMsg = msg[0]
dspMsg = msg[0]
}
name := strings.TrimPrefix(b.Name(), "Bench_")
fmt.Printf("Bench %d: %s %s\n", testCounter, name, dispMsg)
fmt.Printf("Bench %d: %s %s\n", testCounter, name, dspMsg)
testCounter++
}
13 changes: 2 additions & 11 deletions 4test_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
// V0.7.2
// V0.7.3
// Author: DIEHL E.
// (C) Sony Pictures Entertainment, Feb 2021
// © Nov 2024

package test

import (
"testing"
)

func Test_CLI(t *testing.T) {
_, assert := Describe(t)

_, err := CLI(false, "ls")
assert.NoError(err)
_, err = CLI(false, "ls", "~/Dev1")
assert.Error(err)
}

func Test_CompareFiles(t *testing.T) {
_, assert := Describe(t)

Expand Down
22 changes: 22 additions & 0 deletions changelog.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# changelog
## [0.7.0] - 2024-11-23
### Added
- `SwapCase` randomly swaps the case of the alphabetic characters in a string. It is useful to test case-insensitive functions.
## [0.6.0] - 2024-07-11
### Changed
- Uses the new `math/rand/v2` that is concurrent-safe.
### Removed
- The type `Option` with its method `WithConcurrentSafe`.
## [0.5.5] - 2023-08-24
### Added
- `RandomEmail` generates a random email address.
### Fixed
- A raced condition with `RandomFileWithDir` when using With.RandomSafe() is fixed.
## [0.5.4] - 2023-08-03
### Removed
- `ErrReader` is now removed. Use `FaultyReader` instead.
## [0.5.3] - 2023-01-23
### Changed
- `FaultyReader` is now compliant with `io.ReadSeekCloser` interface.
## [0.5.2] - 2022-09-8
The initial released version
15 changes: 8 additions & 7 deletions inram_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// v0.3.2
// v0.3.3
// Author: DIEHL E.
// © Sony Pictures Entertainment, Apr 2021
// © Nov 2024

package test

import (
"math/rand/v2"
"testing"
)

func Test_InRAMReader_Read(t *testing.T) {
require, assert := Describe(t)

p := RandomSlice(Rng.Intn(10000) + 256)
p := RandomSlice(rand.IntN(10000) + 256)
rd := NewInRAMReader(p)
b := make([]byte, 128)

Expand All @@ -20,7 +21,7 @@ func Test_InRAMReader_Read(t *testing.T) {
assert.Equal(128, n)
assert.Equal(p[:128], b)

rd.Close()
_ = rd.Close()
_, err = rd.Read(b)
assert.EqualError(err, ErrClosed.Error())

Expand All @@ -30,7 +31,7 @@ func Test_InRAMWriter_Write(t *testing.T) {
require, assert := Describe(t)

wr := NewInRAMWriter()
defer wr.Close()
defer func() { _ = wr.Close() }()
buffer := RandomSlice(256)

n, err := wr.Write(buffer[:128])
Expand All @@ -47,10 +48,10 @@ func Test_InRAMWriter_WriteAt(t *testing.T) {

wr := NewInRAMWriter()
buffer := RandomSlice(256)
wr.Write(buffer)
_, _ = wr.Write(buffer)

buf2 := RandomSlice(128)
off := Rng.Int63n(64)
off := rand.Int64N(64)
n, err := wr.WriteAt(buf2, off)
require.NoError(err)
assert.Equal(128, n)
Expand Down
2 changes: 1 addition & 1 deletion leak.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// v0.1.0
// Author: DIEHL E.
// (©) Sony Pictures Entertainment, Apr 2022
// © Jul 2024

package test

Expand Down
4 changes: 2 additions & 2 deletions ram.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// V 0.9.0
// V 0.9.1
// Author: DIEHL E.
// (C) Sony Pictures Entertainment, Feb 2021
// (C) Jul 2021

package test

Expand Down
Loading

0 comments on commit 28995a1

Please sign in to comment.