File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -800,3 +800,17 @@ func TestContentAddressableSymbols(t *testing.T) {
800
800
t .Errorf ("command %s failed: %v\n %s" , cmd , err , out )
801
801
}
802
802
}
803
+
804
+ func TestReadOnly (t * testing.T ) {
805
+ // Test that read-only data is indeed read-only.
806
+ testenv .MustHaveGoBuild (t )
807
+
808
+ t .Parallel ()
809
+
810
+ src := filepath .Join ("testdata" , "testRO" , "x.go" )
811
+ cmd := exec .Command (testenv .GoToolPath (t ), "run" , src )
812
+ out , err := cmd .CombinedOutput ()
813
+ if err == nil {
814
+ t .Errorf ("running test program did not fail. output:\n %s" , out )
815
+ }
816
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2020 The Go Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ // Test that read-only data is indeed read-only. This
6
+ // program attempts to modify read-only data, and it
7
+ // should fail.
8
+
9
+ package main
10
+
11
+ import "unsafe"
12
+
13
+ var s = "hello"
14
+
15
+ func main () {
16
+ println (s )
17
+ * (* struct {
18
+ p * byte
19
+ l int
20
+ })(unsafe .Pointer (& s )).p = 'H'
21
+ println (s )
22
+ }
You can’t perform that action at this time.
0 commit comments