Skip to content

Commit

Permalink
cpuset: Convert Fatalf to Errrof in tests
Browse files Browse the repository at this point in the history
Use of Fatalf is not apppropriate in any of these cases:
None of these failures are prerequisites.
  • Loading branch information
iancoolidge committed Feb 21, 2023
1 parent 2160ea2 commit 005e850
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions cpuset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestCPUSetSize(t *testing.T) {
for _, c := range testCases {
actual := c.cpuset.Size()
if actual != c.expected {
t.Fatalf("expected: %d, actual: %d, cpuset: [%v]", c.expected, actual, c.cpuset)
t.Errorf("expected: %d, actual: %d, cpuset: [%v]", c.expected, actual, c.cpuset)
}
}
}
Expand All @@ -53,7 +53,7 @@ func TestCPUSetIsEmpty(t *testing.T) {
for _, c := range testCases {
actual := c.cpuset.IsEmpty()
if actual != c.expected {
t.Fatalf("expected: %t, IsEmpty() returned: %t, cpuset: [%v]", c.expected, actual, c.cpuset)
t.Errorf("expected: %t, IsEmpty() returned: %t, cpuset: [%v]", c.expected, actual, c.cpuset)
}
}
}
Expand All @@ -72,12 +72,12 @@ func TestCPUSetContains(t *testing.T) {
for _, c := range testCases {
for _, elem := range c.mustContain {
if !c.cpuset.Contains(elem) {
t.Fatalf("expected cpuset to contain element %d: [%v]", elem, c.cpuset)
t.Errorf("expected cpuset to contain element %d: [%v]", elem, c.cpuset)
}
}
for _, elem := range c.mustNotContain {
if c.cpuset.Contains(elem) {
t.Fatalf("expected cpuset not to contain element %d: [%v]", elem, c.cpuset)
t.Errorf("expected cpuset not to contain element %d: [%v]", elem, c.cpuset)
}
}
}
Expand Down Expand Up @@ -108,12 +108,12 @@ func TestCPUSetEqual(t *testing.T) {

for _, c := range shouldEqual {
if !c.s1.Equals(c.s2) {
t.Fatalf("expected cpusets to be equal: s1: [%v], s2: [%v]", c.s1, c.s2)
t.Errorf("expected cpusets to be equal: s1: [%v], s2: [%v]", c.s1, c.s2)
}
}
for _, c := range shouldNotEqual {
if c.s1.Equals(c.s2) {
t.Fatalf("expected cpusets to not be equal: s1: [%v], s2: [%v]", c.s1, c.s2)
t.Errorf("expected cpusets to not be equal: s1: [%v], s2: [%v]", c.s1, c.s2)
}
}
}
Expand Down Expand Up @@ -151,12 +151,12 @@ func TestCPUSetIsSubsetOf(t *testing.T) {

for _, c := range shouldBeSubset {
if !c.s1.IsSubsetOf(c.s2) {
t.Fatalf("expected s1 to be a subset of s2: s1: [%v], s2: [%v]", c.s1, c.s2)
t.Errorf("expected s1 to be a subset of s2: s1: [%v], s2: [%v]", c.s1, c.s2)
}
}
for _, c := range shouldNotBeSubset {
if c.s1.IsSubsetOf(c.s2) {
t.Fatalf("expected s1 to not be a subset of s2: s1: [%v], s2: [%v]", c.s1, c.s2)
t.Errorf("expected s1 to not be a subset of s2: s1: [%v], s2: [%v]", c.s1, c.s2)
}
}
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestCPUSetUnion(t *testing.T) {
for _, c := range testCases {
result := c.s1.Union(c.others...)
if !result.Equals(c.expected) {
t.Fatalf("expected the union of s1 and s2 to be [%v] (got [%v]), others: [%v]", c.expected, result, c.others)
t.Errorf("expected the union of s1 and s2 to be [%v] (got [%v]), others: [%v]", c.expected, result, c.others)
}
}
}
Expand Down Expand Up @@ -224,7 +224,7 @@ func TestCPUSetIntersection(t *testing.T) {
for _, c := range testCases {
result := c.s1.Intersection(c.s2)
if !result.Equals(c.expected) {
t.Fatalf("expected the intersection of s1 and s2 to be [%v] (got [%v]), s1: [%v], s2: [%v]", c.expected, result, c.s1, c.s2)
t.Errorf("expected the intersection of s1 and s2 to be [%v] (got [%v]), s1: [%v], s2: [%v]", c.expected, result, c.s1, c.s2)
}
}
}
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestCPUSetDifference(t *testing.T) {
for _, c := range testCases {
result := c.s1.Difference(c.s2)
if !result.Equals(c.expected) {
t.Fatalf("expected the difference of s1 and s2 to be [%v] (got [%v]), s1: [%v], s2: [%v]", c.expected, result, c.s1, c.s2)
t.Errorf("expected the difference of s1 and s2 to be [%v] (got [%v]), s1: [%v], s2: [%v]", c.expected, result, c.s1, c.s2)
}
}
}
Expand All @@ -274,15 +274,15 @@ func TestCPUSetList(t *testing.T) {
for _, c := range testCases {
result := c.set.List()
if !reflect.DeepEqual(result, c.expected) {
t.Fatalf("unexpected List() contents. got [%v] want [%v] (set: [%v])", result, c.expected, c.set)
t.Errorf("unexpected List() contents. got [%v] want [%v] (set: [%v])", result, c.expected, c.set)
}

// We cannot rely on internal storage order details for a unit test.
// The best we can do is to sort the output of 'UnsortedList'.
result = c.set.UnsortedList()
sort.Ints(result)
if !reflect.DeepEqual(result, c.expected) {
t.Fatalf("unexpected UnsortedList() contents. got [%v] want [%v] (set: [%v])", result, c.expected, c.set)
t.Errorf("unexpected UnsortedList() contents. got [%v] want [%v] (set: [%v])", result, c.expected, c.set)
}
}
}
Expand All @@ -301,7 +301,7 @@ func TestCPUSetString(t *testing.T) {
for _, c := range testCases {
result := c.set.String()
if result != c.expected {
t.Fatalf("expected set as string to be %s (got \"%s\"), s: [%v]", c.expected, result, c.set)
t.Errorf("expected set as string to be %s (got \"%s\"), s: [%v]", c.expected, result, c.set)
}
}
}
Expand All @@ -324,10 +324,10 @@ func TestParse(t *testing.T) {
for _, c := range positiveTestCases {
result, err := Parse(c.cpusetString)
if err != nil {
t.Fatalf("expected error not to have occurred: %v", err)
t.Errorf("expected error not to have occurred: %v", err)
}
if !result.Equals(c.expected) {
t.Fatalf("expected string \"%s\" to parse as [%v] (got [%v])", c.cpusetString, c.expected, result)
t.Errorf("expected string \"%s\" to parse as [%v] (got [%v])", c.cpusetString, c.expected, result)
}
}

Expand All @@ -343,7 +343,7 @@ func TestParse(t *testing.T) {
for _, c := range negativeTestCases {
result, err := Parse(c)
if err == nil {
t.Fatalf("expected parse failure of \"%s\", but it succeeded as \"%s\"", c, result.String())
t.Errorf("expected parse failure of \"%s\", but it succeeded as \"%s\"", c, result.String())
}
}
}
Expand Down

0 comments on commit 005e850

Please sign in to comment.