Skip to content

Commit 7a53122

Browse files
committed
update (20 Aug 2023)
1 parent af1cf59 commit 7a53122

22 files changed

+2165
-565
lines changed

.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "gomod"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"

.github/workflows/ci.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
14+
test:
15+
name: Test
16+
runs-on: ubuntu-latest
17+
18+
strategy:
19+
matrix:
20+
go_version: [1.21.x]
21+
steps:
22+
23+
- name: Set up Go 1.x
24+
uses: actions/setup-go@v4
25+
with:
26+
go-version: ${{ matrix.go_version }}
27+
28+
- name: Check out code into the Go module directory
29+
uses: actions/checkout@v3
30+
31+
- name: Test
32+
run: go test -v ./...

.github/workflows/codeql-analysis.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches: [ master ]
17+
pull_request:
18+
# The branches below must be a subset of the branches above
19+
branches: [ master ]
20+
schedule:
21+
- cron: '24 11 * * 6'
22+
23+
jobs:
24+
analyze:
25+
name: Analyze
26+
runs-on: ubuntu-latest
27+
permissions:
28+
actions: read
29+
contents: read
30+
security-events: write
31+
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
language: [ 'go']
36+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37+
# Learn more:
38+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39+
40+
steps:
41+
- name: Checkout repository
42+
uses: actions/checkout@v3
43+
44+
# Initializes the CodeQL tools for scanning.
45+
- name: Initialize CodeQL
46+
uses: github/codeql-action/init@v2
47+
with:
48+
languages: ${{ matrix.language }}
49+
# If you wish to specify custom queries, you can do so here or in a config file.
50+
# By default, queries listed here will override any specified in a config file.
51+
# Prefix the list here with "+" to use these queries and those in the config file.
52+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
53+
54+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55+
# If this step fails, then you should remove it and run the build manually (see below)
56+
- name: Autobuild
57+
uses: github/codeql-action/autobuild@v2
58+
59+
# ℹ️ Command-line programs to run using the OS shell.
60+
# 📚 https://git.io/JvXDl
61+
62+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63+
# and modify them (or add more) to build your code if your project
64+
# uses a compiled language
65+
66+
#- run: |
67+
# make bootstrap
68+
# make release
69+
70+
- name: Perform CodeQL Analysis
71+
uses: github/codeql-action/analyze@v2

array.go

+107-123
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,115 @@ func (a *Array) Element(index int) *Value {
191191
return a.Value(index)
192192
}
193193

194-
// First returns a new Value instance for the first element of array.
194+
// HasValue succeeds if array's value at the given index is equal to given value.
195195
//
196-
// If given array is empty, First reports failure and returns empty
197-
// (but non-nil) instance.
196+
// Before comparison, both values are converted to canonical form. value should be
197+
// map[string]interface{} or struct.
198198
//
199199
// Example:
200200
//
201-
// array := NewArray(t, []interface{}{"foo", 123})
202-
// array.First().String().IsEqual("foo")
201+
// array := NewArray(t, []interface{}{"foo", "123"})
202+
// array.HasValue(1, 123)
203+
func (a *Array) HasValue(index int, value interface{}) *Array {
204+
opChain := a.chain.enter("HasValue(%d)", index)
205+
defer opChain.leave()
206+
207+
if opChain.failed() {
208+
return a
209+
}
210+
211+
if index < 0 || index >= len(a.value) {
212+
opChain.fail(AssertionFailure{
213+
Type: AssertInRange,
214+
Actual: &AssertionValue{index},
215+
Expected: &AssertionValue{AssertionRange{
216+
Min: 0,
217+
Max: len(a.value) - 1,
218+
}},
219+
Errors: []error{
220+
errors.New("expected: valid element index"),
221+
},
222+
})
223+
return a
224+
}
225+
226+
expected, ok := canonValue(opChain, value)
227+
if !ok {
228+
return a
229+
}
230+
231+
if !reflect.DeepEqual(expected, a.value[index]) {
232+
opChain.fail(AssertionFailure{
233+
Type: AssertEqual,
234+
Actual: &AssertionValue{a.value[index]},
235+
Expected: &AssertionValue{value},
236+
Errors: []error{
237+
fmt.Errorf(
238+
"expected: array value at index %d is equal to given value",
239+
index),
240+
},
241+
})
242+
return a
243+
}
244+
245+
return a
246+
}
247+
248+
// NotHasValue succeeds if array's value at the given index is not equal to given value.
249+
//
250+
// Before comparison, both values are converted to canonical form. value should be
251+
// map[string]interface{} or struct.
252+
//
253+
// Example:
254+
//
255+
// array := NewArray(t, []interface{}{"foo", "123"})
256+
// array.NotHasValue(1, 234)
257+
func (a *Array) NotHasValue(index int, value interface{}) *Array {
258+
opChain := a.chain.enter("NotHasValue(%d)", index)
259+
defer opChain.leave()
260+
261+
if opChain.failed() {
262+
return a
263+
}
264+
265+
if index < 0 || index >= len(a.value) {
266+
opChain.fail(AssertionFailure{
267+
Type: AssertInRange,
268+
Actual: &AssertionValue{index},
269+
Expected: &AssertionValue{AssertionRange{
270+
Min: 0,
271+
Max: len(a.value) - 1,
272+
}},
273+
Errors: []error{
274+
errors.New("expected: valid element index"),
275+
},
276+
})
277+
return a
278+
}
279+
280+
expected, ok := canonValue(opChain, value)
281+
if !ok {
282+
return a
283+
}
284+
285+
if reflect.DeepEqual(expected, a.value[index]) {
286+
opChain.fail(AssertionFailure{
287+
Type: AssertNotEqual,
288+
Actual: &AssertionValue{a.value[index]},
289+
Expected: &AssertionValue{value},
290+
Errors: []error{
291+
fmt.Errorf(
292+
"expected: array value at index %d is not equal to given value",
293+
index),
294+
},
295+
})
296+
return a
297+
}
298+
299+
return a
300+
}
301+
302+
// Deprecated: use Value or HasValue instead.
203303
func (a *Array) First() *Value {
204304
opChain := a.chain.enter("First()")
205305
defer opChain.leave()
@@ -222,15 +322,7 @@ func (a *Array) First() *Value {
222322
return newValue(opChain, a.value[0])
223323
}
224324

225-
// Last returns a new Value instance for the last element of array.
226-
//
227-
// If given array is empty, Last reports failure and returns empty
228-
// (but non-nil) instance.
229-
//
230-
// Example:
231-
//
232-
// array := NewArray(t, []interface{}{"foo", 123})
233-
// array.Last().Number().IsEqual(123)
325+
// Deprecated: use Value or HasValue instead.
234326
func (a *Array) Last() *Value {
235327
opChain := a.chain.enter("Last()")
236328
defer opChain.leave()
@@ -261,7 +353,7 @@ func (a *Array) Last() *Value {
261353
// array := NewArray(t, strings)
262354
//
263355
// for index, value := range array.Iter() {
264-
// value.String().IsEqual(strings[index])
356+
// value.String().IsEqual(strings[index])
265357
// }
266358
func (a *Array) Iter() []Value {
267359
opChain := a.chain.enter("Iter()")
@@ -1452,114 +1544,6 @@ func (a *Array) NotContainsOnly(values ...interface{}) *Array {
14521544
return a
14531545
}
14541546

1455-
// IsValueEqual succeeds if array's value at the given index is equal to given value.
1456-
//
1457-
// Before comparison, both values are converted to canonical form. value should be
1458-
// map[string]interface{} or struct.
1459-
//
1460-
// Example:
1461-
//
1462-
// array := NewArray(t, []interface{}{"foo", "123"})
1463-
// array.IsValueEqual(1, 123)
1464-
func (a *Array) IsValueEqual(index int, value interface{}) *Array {
1465-
opChain := a.chain.enter("IsValueEqual(%d)", index)
1466-
defer opChain.leave()
1467-
1468-
if opChain.failed() {
1469-
return a
1470-
}
1471-
1472-
if index < 0 || index >= len(a.value) {
1473-
opChain.fail(AssertionFailure{
1474-
Type: AssertInRange,
1475-
Actual: &AssertionValue{index},
1476-
Expected: &AssertionValue{AssertionRange{
1477-
Min: 0,
1478-
Max: len(a.value) - 1,
1479-
}},
1480-
Errors: []error{
1481-
errors.New("expected: valid element index"),
1482-
},
1483-
})
1484-
return a
1485-
}
1486-
1487-
expected, ok := canonValue(opChain, value)
1488-
if !ok {
1489-
return a
1490-
}
1491-
1492-
if !reflect.DeepEqual(expected, a.value[index]) {
1493-
opChain.fail(AssertionFailure{
1494-
Type: AssertEqual,
1495-
Actual: &AssertionValue{a.value[index]},
1496-
Expected: &AssertionValue{value},
1497-
Errors: []error{
1498-
fmt.Errorf(
1499-
"expected: array value at index %d is equal to given value",
1500-
index),
1501-
},
1502-
})
1503-
return a
1504-
}
1505-
1506-
return a
1507-
}
1508-
1509-
// NotValueEqual succeeds if array's value at the given index is not equal to given value.
1510-
//
1511-
// Before comparison, both values are converted to canonical form. value should be
1512-
// map[string]interface{} or struct.
1513-
//
1514-
// Example:
1515-
//
1516-
// array := NewArray(t, []interface{}{"foo", "123"})
1517-
// array.NotValueEqual(1, 234)
1518-
func (a *Array) NotValueEqual(index int, value interface{}) *Array {
1519-
opChain := a.chain.enter("NotValueEqual(%d)", index)
1520-
defer opChain.leave()
1521-
1522-
if opChain.failed() {
1523-
return a
1524-
}
1525-
1526-
if index < 0 || index >= len(a.value) {
1527-
opChain.fail(AssertionFailure{
1528-
Type: AssertInRange,
1529-
Actual: &AssertionValue{index},
1530-
Expected: &AssertionValue{AssertionRange{
1531-
Min: 0,
1532-
Max: len(a.value) - 1,
1533-
}},
1534-
Errors: []error{
1535-
errors.New("expected: valid element index"),
1536-
},
1537-
})
1538-
return a
1539-
}
1540-
1541-
expected, ok := canonValue(opChain, value)
1542-
if !ok {
1543-
return a
1544-
}
1545-
1546-
if reflect.DeepEqual(expected, a.value[index]) {
1547-
opChain.fail(AssertionFailure{
1548-
Type: AssertNotEqual,
1549-
Actual: &AssertionValue{a.value[index]},
1550-
Expected: &AssertionValue{value},
1551-
Errors: []error{
1552-
fmt.Errorf(
1553-
"expected: array value at index %d is not equal to given value",
1554-
index),
1555-
},
1556-
})
1557-
return a
1558-
}
1559-
1560-
return a
1561-
}
1562-
15631547
// IsOrdered succeeds if every element is not less than the previous element
15641548
// as defined on the given `less` comparator function.
15651549
// For default, it will use built-in comparator function for each data type.

assertion.go

+7
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ type AssertionContext struct {
134134
// Environment shared between tests
135135
// Comes from Expect instance
136136
Environment *Environment
137+
138+
// Whether reporter is known to output to testing.TB
139+
// For example, true when reporter is testing.T or testify-based reporter.
140+
TestingTB bool
137141
}
138142

139143
// AssertionFailure provides detailed information about failed assertion.
@@ -188,6 +192,9 @@ type AssertionFailure struct {
188192

189193
// Allowed delta between actual and expected
190194
Delta *AssertionValue
195+
196+
// Stacktrace of the failure
197+
Stacktrace []StacktraceEntry
191198
}
192199

193200
// AssertionValue holds expected or actual value

0 commit comments

Comments
 (0)