@@ -40,11 +40,16 @@ var (
40
40
htmlGolden = filepath .Join (testdata , "html" , "html.golden" )
41
41
42
42
// Temporary files.
43
- tmpTestMain string
44
- coverInput string
45
- coverOutput string
46
- htmlProfile string
47
- htmlHTML string
43
+ tmpTestMain string
44
+ coverInput string
45
+ coverOutput string
46
+ htmlProfile string
47
+ htmlHTML string
48
+ htmlUDir string
49
+ htmlU string
50
+ htmlUTest string
51
+ htmlUProfile string
52
+ htmlUHTML string
48
53
)
49
54
50
55
var (
@@ -85,6 +90,11 @@ func TestMain(m *testing.M) {
85
90
coverOutput = filepath .Join (dir , "test_cover.go" )
86
91
htmlProfile = filepath .Join (dir , "html.cov" )
87
92
htmlHTML = filepath .Join (dir , "html.html" )
93
+ htmlUDir = filepath .Join (dir , "htmlunformatted" )
94
+ htmlU = filepath .Join (htmlUDir , "htmlunformatted.go" )
95
+ htmlUTest = filepath .Join (htmlUDir , "htmlunformatted_test.go" )
96
+ htmlUProfile = filepath .Join (htmlUDir , "htmlunformatted.cov" )
97
+ htmlUHTML = filepath .Join (htmlUDir , "htmlunformatted.html" )
88
98
89
99
status := m .Run ()
90
100
@@ -427,12 +437,54 @@ func TestCoverHTML(t *testing.T) {
427
437
}
428
438
}
429
439
440
+ // Test HTML processing with a source file not run through gofmt.
441
+ // Issue #27350.
442
+ func TestHtmlUnformatted (t * testing.T ) {
443
+ t .Parallel ()
444
+ testenv .MustHaveGoRun (t )
445
+ buildCover (t )
446
+
447
+ if err := os .Mkdir (htmlUDir , 0777 ); err != nil {
448
+ t .Fatal (err )
449
+ }
450
+
451
+ const htmlUContents = `
452
+ package htmlunformatted
453
+
454
+ var g int
455
+
456
+ func F() {
457
+ //line x.go:1
458
+ { { F(); goto lab } }
459
+ lab:
460
+ }`
461
+
462
+ const htmlUTestContents = `package htmlunformatted`
463
+
464
+ if err := ioutil .WriteFile (htmlU , []byte (htmlUContents ), 0444 ); err != nil {
465
+ t .Fatal (err )
466
+ }
467
+ if err := ioutil .WriteFile (htmlUTest , []byte (htmlUTestContents ), 0444 ); err != nil {
468
+ t .Fatal (err )
469
+ }
470
+
471
+ // go test -covermode=count -coverprofile TMPDIR/htmlunformatted.cov
472
+ cmd := exec .Command (testenv .GoToolPath (t ), "test" , toolexecArg , "-covermode=count" , "-coverprofile" , htmlUProfile )
473
+ cmd .Dir = htmlUDir
474
+ run (cmd , t )
475
+
476
+ // testcover -html TMPDIR/htmlunformatted.cov -o unformatted.html
477
+ cmd = exec .Command (testcover , "-html" , htmlUProfile , "-o" , htmlUHTML )
478
+ run (cmd , t )
479
+ }
480
+
430
481
func run (c * exec.Cmd , t * testing.T ) {
431
482
t .Helper ()
432
483
t .Log ("running" , c .Args )
433
- c .Stdout = os .Stdout
434
- c .Stderr = os .Stderr
435
- err := c .Run ()
484
+ out , err := c .CombinedOutput ()
485
+ if len (out ) > 0 {
486
+ t .Logf ("%s" , out )
487
+ }
436
488
if err != nil {
437
489
t .Fatal (err )
438
490
}
0 commit comments