Skip to content

Commit 9a5d497

Browse files
committed
replace usages of ioutil with io and os
1 parent b2efebc commit 9a5d497

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-33
lines changed

init.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package task
33
import (
44
"fmt"
55
"io"
6-
"io/ioutil"
76
"os"
87
"path/filepath"
98
)
@@ -30,7 +29,7 @@ func InitTaskfile(w io.Writer, dir string) error {
3029
return ErrTaskfileAlreadyExists
3130
}
3231

33-
if err := ioutil.WriteFile(f, []byte(defaultTaskfile), 0644); err != nil {
32+
if err := os.WriteFile(f, []byte(defaultTaskfile), 0644); err != nil {
3433
return err
3534
}
3635
fmt.Fprintf(w, "Taskfile.yml created in the current directory\n")

internal/status/checksum.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"crypto/md5"
55
"fmt"
66
"io"
7-
"io/ioutil"
87
"os"
98
"path/filepath"
109
"regexp"
@@ -30,7 +29,7 @@ func (c *Checksum) IsUpToDate() (bool, error) {
3029

3130
checksumFile := c.checksumFilePath()
3231

33-
data, _ := ioutil.ReadFile(checksumFile)
32+
data, _ := os.ReadFile(checksumFile)
3433
oldMd5 := strings.TrimSpace(string(data))
3534

3635
sources, err := globs(c.TaskDir, c.Sources)
@@ -45,7 +44,7 @@ func (c *Checksum) IsUpToDate() (bool, error) {
4544

4645
if !c.Dry {
4746
_ = os.MkdirAll(filepath.Join(c.BaseDir, ".task", "checksum"), 0755)
48-
if err = ioutil.WriteFile(checksumFile, []byte(newMd5+"\n"), 0644); err != nil {
47+
if err = os.WriteFile(checksumFile, []byte(newMd5+"\n"), 0644); err != nil {
4948
return false, err
5049
}
5150
}

task_test.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"os"
99
"path/filepath"
1010
"runtime"
@@ -41,15 +41,15 @@ func (fct fileContentTest) Run(t *testing.T) {
4141

4242
e := &task.Executor{
4343
Dir: fct.Dir,
44-
Stdout: ioutil.Discard,
45-
Stderr: ioutil.Discard,
44+
Stdout: io.Discard,
45+
Stderr: io.Discard,
4646
}
4747
assert.NoError(t, e.Setup(), "e.Setup()")
4848
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: fct.Target}), "e.Run(target)")
4949

5050
for name, expectContent := range fct.Files {
5151
t.Run(fct.name(name), func(t *testing.T) {
52-
b, err := ioutil.ReadFile(filepath.Join(fct.Dir, name))
52+
b, err := os.ReadFile(filepath.Join(fct.Dir, name))
5353
assert.NoError(t, err, "Error reading file")
5454
s := string(b)
5555
if fct.TrimSpace {
@@ -63,8 +63,8 @@ func (fct fileContentTest) Run(t *testing.T) {
6363
func TestEmptyTask(t *testing.T) {
6464
e := &task.Executor{
6565
Dir: "testdata/empty_task",
66-
Stdout: ioutil.Discard,
67-
Stderr: ioutil.Discard,
66+
Stdout: io.Discard,
67+
Stderr: io.Discard,
6868
}
6969
assert.NoError(t, e.Setup(), "e.Setup()")
7070
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "default"}))
@@ -168,8 +168,8 @@ func TestVarsInvalidTmpl(t *testing.T) {
168168

169169
e := &task.Executor{
170170
Dir: dir,
171-
Stdout: ioutil.Discard,
172-
Stderr: ioutil.Discard,
171+
Stdout: io.Discard,
172+
Stderr: io.Discard,
173173
}
174174
assert.NoError(t, e.Setup(), "e.Setup()")
175175
assert.EqualError(t, e.Run(context.Background(), taskfile.Call{Task: target}), expectError, "e.Run(target)")
@@ -183,8 +183,8 @@ func TestConcurrency(t *testing.T) {
183183

184184
e := &task.Executor{
185185
Dir: dir,
186-
Stdout: ioutil.Discard,
187-
Stderr: ioutil.Discard,
186+
Stdout: io.Discard,
187+
Stderr: io.Discard,
188188
Concurrency: 1,
189189
}
190190
assert.NoError(t, e.Setup(), "e.Setup()")
@@ -236,8 +236,8 @@ func TestDeps(t *testing.T) {
236236

237237
e := &task.Executor{
238238
Dir: dir,
239-
Stdout: ioutil.Discard,
240-
Stderr: ioutil.Discard,
239+
Stdout: io.Discard,
240+
Stderr: io.Discard,
241241
}
242242
assert.NoError(t, e.Setup())
243243
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "default"}))
@@ -557,7 +557,7 @@ func TestInit(t *testing.T) {
557557
t.Errorf("Taskfile.yml should not exist")
558558
}
559559

560-
if err := task.InitTaskfile(ioutil.Discard, dir); err != nil {
560+
if err := task.InitTaskfile(io.Discard, dir); err != nil {
561561
t.Error(err)
562562
}
563563

@@ -571,8 +571,8 @@ func TestCyclicDep(t *testing.T) {
571571

572572
e := task.Executor{
573573
Dir: dir,
574-
Stdout: ioutil.Discard,
575-
Stderr: ioutil.Discard,
574+
Stdout: io.Discard,
575+
Stderr: io.Discard,
576576
}
577577
assert.NoError(t, e.Setup())
578578
assert.IsType(t, &task.MaximumTaskCallExceededError{}, e.Run(context.Background(), taskfile.Call{Task: "task-1"}))
@@ -590,8 +590,8 @@ func TestTaskVersion(t *testing.T) {
590590
t.Run(test.Dir, func(t *testing.T) {
591591
e := task.Executor{
592592
Dir: test.Dir,
593-
Stdout: ioutil.Discard,
594-
Stderr: ioutil.Discard,
593+
Stdout: io.Discard,
594+
Stderr: io.Discard,
595595
}
596596
assert.NoError(t, e.Setup())
597597
assert.Equal(t, test.Version, e.Taskfile.Version)
@@ -605,8 +605,8 @@ func TestTaskIgnoreErrors(t *testing.T) {
605605

606606
e := task.Executor{
607607
Dir: dir,
608-
Stdout: ioutil.Discard,
609-
Stderr: ioutil.Discard,
608+
Stdout: io.Discard,
609+
Stderr: io.Discard,
610610
}
611611
assert.NoError(t, e.Setup())
612612

@@ -668,8 +668,8 @@ func TestDryChecksum(t *testing.T) {
668668

669669
e := task.Executor{
670670
Dir: dir,
671-
Stdout: ioutil.Discard,
672-
Stderr: ioutil.Discard,
671+
Stdout: io.Discard,
672+
Stderr: io.Discard,
673673
Dry: true,
674674
}
675675
assert.NoError(t, e.Setup())
@@ -769,8 +769,8 @@ func TestIncludesOptional(t *testing.T) {
769769
func TestIncludesOptionalImplicitFalse(t *testing.T) {
770770
e := task.Executor{
771771
Dir: "testdata/includes_optional_implicit_false",
772-
Stdout: ioutil.Discard,
773-
Stderr: ioutil.Discard,
772+
Stdout: io.Discard,
773+
Stderr: io.Discard,
774774
}
775775

776776
err := e.Setup()
@@ -781,8 +781,8 @@ func TestIncludesOptionalImplicitFalse(t *testing.T) {
781781
func TestIncludesOptionalExplicitFalse(t *testing.T) {
782782
e := task.Executor{
783783
Dir: "testdata/includes_optional_explicit_false",
784-
Stdout: ioutil.Discard,
785-
Stderr: ioutil.Discard,
784+
Stdout: io.Discard,
785+
Stderr: io.Discard,
786786
}
787787

788788
err := e.Setup()
@@ -804,7 +804,7 @@ func TestSummary(t *testing.T) {
804804
assert.NoError(t, e.Setup())
805805
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task-with-summary"}, taskfile.Call{Task: "other-task-with-summary"}))
806806

807-
data, err := ioutil.ReadFile(filepath.Join(dir, "task-with-summary.txt"))
807+
data, err := os.ReadFile(filepath.Join(dir, "task-with-summary.txt"))
808808
assert.NoError(t, err)
809809

810810
expectedOutput := string(data)
@@ -895,8 +895,8 @@ func TestDynamicVariablesShouldRunOnTheTaskDir(t *testing.T) {
895895
func TestDisplaysErrorOnUnsupportedVersion(t *testing.T) {
896896
e := task.Executor{
897897
Dir: "testdata/version/v1",
898-
Stdout: ioutil.Discard,
899-
Stderr: ioutil.Discard,
898+
Stdout: io.Discard,
899+
Stderr: io.Discard,
900900
}
901901
err := e.Setup()
902902
assert.Error(t, err)

0 commit comments

Comments
 (0)