Russ Cox | d2cc988 | 2012-02-16 23:50:37 -0500 | [diff] [blame] | 1 | // errorcheck |
Russ Cox | 33f3afa | 2012-01-31 17:29:59 -0500 | [diff] [blame] | 2 | |
| 3 | // Copyright 2009 The Go Authors. All rights reserved. |
| 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file. |
| 6 | |
Anthony Martin | dc38756 | 2012-02-24 14:48:36 -0500 | [diff] [blame] | 7 | // Verify that invalid imports are rejected by the compiler. |
Rob Pike | 501f0b5 | 2012-02-23 18:47:26 +1100 | [diff] [blame] | 8 | // Does not compile. |
Russ Cox | 33f3afa | 2012-01-31 17:29:59 -0500 | [diff] [blame] | 9 | |
| 10 | package main |
| 11 | |
Anthony Martin | dc38756 | 2012-02-24 14:48:36 -0500 | [diff] [blame] | 12 | // Correct import paths. |
| 13 | import _ "fmt" |
| 14 | import _ `time` |
| 15 | import _ "m\x61th" |
| 16 | import _ "go/parser" |
| 17 | |
| 18 | // Correct import paths, but the packages don't exist. |
| 19 | // Don't test. |
| 20 | //import "a.b" |
| 21 | //import "greek/αβ" |
| 22 | |
| 23 | // Import paths must be strings. |
| 24 | import 42 // ERROR "import statement" |
| 25 | import 'a' // ERROR "import statement" |
| 26 | import 3.14 // ERROR "import statement" |
| 27 | import 0.25i // ERROR "import statement" |
| 28 | |
| 29 | // Each of these pairs tests both `` vs "" strings |
| 30 | // and also use of invalid characters spelled out as |
| 31 | // escape sequences and written directly. |
| 32 | // For example `"\x00"` tests import "\x00" |
| 33 | // while "`\x00`" tests import `<actual-NUL-byte>`. |
| 34 | import "" // ERROR "import path" |
| 35 | import `` // ERROR "import path" |
| 36 | import "\x00" // ERROR "import path" |
| 37 | import `\x00` // ERROR "import path" |
| 38 | import "\x7f" // ERROR "import path" |
| 39 | import `\x7f` // ERROR "import path" |
| 40 | import "a!" // ERROR "import path" |
| 41 | import `a!` // ERROR "import path" |
| 42 | import "a b" // ERROR "import path" |
| 43 | import `a b` // ERROR "import path" |
| 44 | import "a\\b" // ERROR "import path" |
| 45 | import `a\\b` // ERROR "import path" |
| 46 | import "\"`a`\"" // ERROR "import path" |
| 47 | import `\"a\"` // ERROR "import path" |
| 48 | import "\x80\x80" // ERROR "import path" |
| 49 | import `\x80\x80` // ERROR "import path" |
| 50 | import "\xFFFD" // ERROR "import path" |
| 51 | import `\xFFFD` // ERROR "import path" |
Russ Cox | d0d251f | 2012-02-29 15:28:36 -0500 | [diff] [blame] | 52 | |
| 53 | // Invalid local imports. |
| 54 | import "/foo" // ERROR "import path cannot be absolute path" |
| 55 | import "c:/foo" // ERROR "import path contains invalid character" |