File tree 2 files changed +43
-6
lines changed
2 files changed +43
-6
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ import (
24
24
"os"
25
25
"sort"
26
26
"strings"
27
- "time"
27
+ "time"
28
28
29
29
"github.com/arduino/arduino-cli/commands/monitor"
30
30
"github.com/arduino/arduino-cli/configuration"
@@ -250,33 +250,33 @@ func contains(s []string, searchterm string) bool {
250
250
}
251
251
252
252
type timeStampWriter struct {
253
- writer io.Writer
253
+ writer io.Writer
254
254
sendTimeStampNext bool
255
255
}
256
256
257
257
func newTimeStampWriter (writer io.Writer ) * timeStampWriter {
258
258
return & timeStampWriter {
259
- writer : writer ,
259
+ writer : writer ,
260
260
sendTimeStampNext : true ,
261
261
}
262
262
}
263
263
264
264
func (t * timeStampWriter ) Write (p []byte ) (int , error ) {
265
265
written := 0
266
266
for _ , b := range p {
267
- if ( t .sendTimeStampNext ) {
267
+ if t .sendTimeStampNext {
268
268
_ , err := t .writer .Write ([]byte (time .Now ().Format ("[2006-01-02 15:04:05] " )))
269
269
if err != nil {
270
270
return written , err
271
271
}
272
- t .sendTimeStampNext = false ;
272
+ t .sendTimeStampNext = false
273
273
}
274
274
n , err := t .writer .Write ([]byte {b })
275
275
written += n
276
276
if err != nil {
277
277
return written , err
278
278
}
279
- t .sendTimeStampNext = b == '\n' ;
279
+ t .sendTimeStampNext = b == '\n'
280
280
}
281
281
return written , nil
282
282
}
Original file line number Diff line number Diff line change
1
+ // This file is part of arduino-cli.
2
+ //
3
+ // Copyright 2023 ARDUINO SA (http://www.arduino.cc/)
4
+ //
5
+ // This software is released under the GNU General Public License version 3,
6
+ // which covers the main part of arduino-cli.
7
+ // The terms of this license can be found at:
8
+ // https://www.gnu.org/licenses/gpl-3.0.en.html
9
+ //
10
+ // You can be released from the requirements of the above licenses by purchasing
11
+ // a commercial license. Buying such a license is mandatory if you want to
12
+ // modify or otherwise use the software for commercial activities involving the
13
+ // Arduino software without disclosing the source code of your own applications.
14
+ // To purchase a commercial license, send an email to [email protected] .
15
+
16
+ package monitor
17
+
18
+ import (
19
+ "bytes"
20
+ "testing"
21
+
22
+ "github.com/stretchr/testify/require"
23
+ )
24
+
25
+ func TestTimeStampWriter (t * testing.T ) {
26
+ buf := & bytes.Buffer {}
27
+ writer := newTimeStampWriter (buf )
28
+
29
+ writer .Write ([]byte ("foo" ))
30
+ // The first received bytes get a timestamp prepended
31
+ require .Regexp (t , `^\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\] foo$` , buf )
32
+
33
+ buf .Reset ()
34
+ writer .Write ([]byte ("\n bar\n " ))
35
+ // A timestamp should be inserted before the first char of the next line
36
+ require .Regexp (t , "^\n " + `\[\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\] bar` + "\n $" , buf )
37
+ }
You can’t perform that action at this time.
0 commit comments