@@ -17,17 +17,34 @@ def test_separate_crates(self) -> None:
17
17
""" ).encode (),
18
18
pathlib .Path ('Cargo.toml' ): textwrap .dedent ("""\
19
19
[workspace]
20
- members = ["crates/*/", "verification/"]
20
+ members = ["verification"]
21
+
22
+ [package]
23
+ name = "my_competitive_library"
24
+ version = "0.0.0"
25
+ edition = "2018"
26
+
27
+ [dependencies]
28
+ my-competitive-library-a = { path = "./crates/a" }
29
+ my-competitive-library-b = { path = "./crates/b" }
30
+ my-competitive-library-c = { path = "./crates/c" }
31
+ """ ).encode (),
32
+ pathlib .Path ('src' , 'lib.rs' ): textwrap .dedent ("""\
33
+ macro_rules! re_export(($($name:ident),* $(,)?) => ($(pub mod $name { pub use $name::*; })*));
34
+ re_export!(a, b, c);
21
35
""" ).encode (),
22
36
pathlib .Path ('crates' , 'a' , 'Cargo.toml' ): textwrap .dedent ("""\
23
37
[package]
24
- name = "a"
38
+ name = "my-competitive-library- a"
25
39
version = "0.0.0"
26
40
edition = "2018"
27
41
42
+ [lib]
43
+ name = "a"
44
+
28
45
[dependencies]
29
- b = { path = "../b" }
30
- c = { path = "../c" }
46
+ my-competitive-library- b = { path = "../b" }
47
+ my-competitive-library- c = { path = "../c" }
31
48
""" ).encode (),
32
49
pathlib .Path ('crates' , 'a' , 'src' , 'lib.rs' ): textwrap .dedent ("""\
33
50
use b::B;
@@ -37,18 +54,24 @@ def test_separate_crates(self) -> None:
37
54
""" ).encode (),
38
55
pathlib .Path ('crates' , 'b' , 'Cargo.toml' ): textwrap .dedent ("""\
39
56
[package]
40
- name = "b"
57
+ name = "my-competitive-library- b"
41
58
version = "0.0.0"
42
59
edition = "2018"
60
+
61
+ [lib]
62
+ name = "b"
43
63
""" ).encode (),
44
64
pathlib .Path ('crates' , 'b' , 'src' , 'lib.rs' ): textwrap .dedent ("""\
45
65
pub struct B;
46
66
""" ).encode (),
47
67
pathlib .Path ('crates' , 'c' , 'Cargo.toml' ): textwrap .dedent ("""\
48
68
[package]
49
- name = "c"
69
+ name = "my-competitive-library- c"
50
70
version = "0.0.0"
51
71
edition = "2018"
72
+
73
+ [lib]
74
+ name = "c"
52
75
""" ).encode (),
53
76
pathlib .Path ('crates' , 'c' , 'src' , 'lib.rs' ): textwrap .dedent ("""\
54
77
pub struct C;
@@ -60,7 +83,7 @@ def test_separate_crates(self) -> None:
60
83
edition = "2018"
61
84
62
85
[dependencies]
63
- a = { path = "../crates/a" }
86
+ my-competitive-library- a = { path = "../crates/a" }
64
87
""" ).encode (),
65
88
pathlib .Path ('verification' , 'src' , 'bin' , 'aizu-online-judge-itp1-1-a.rs' ): textwrap .dedent ("""\
66
89
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A
@@ -74,12 +97,28 @@ def test_separate_crates(self) -> None:
74
97
}
75
98
76
99
with tests .utils .load_files_pathlib (files ) as tempdir :
77
- expected = sorted (tempdir / 'crates' / name / 'src' / 'lib.rs' for name in ['a' , 'b' , 'c' ])
78
- actual = sorted (RustLanguage (config = None ).list_dependencies (tempdir / 'crates' / 'a' / 'src' / 'lib.rs' , basedir = tempdir ))
100
+
101
+ def sub_crate_src_path (crate_name : str ) -> pathlib .Path :
102
+ return tempdir / 'crates' / crate_name / 'src' / 'lib.rs'
103
+
104
+ top_lib_src_path = tempdir / 'src' / 'lib.rs'
105
+ verification_src_path = tempdir / 'verification' / 'src' / 'bin' / 'aizu-online-judge-itp1-1-a.rs'
106
+
107
+ expected = [sub_crate_src_path ('a' ), sub_crate_src_path ('b' ), sub_crate_src_path ('c' ), top_lib_src_path ]
108
+ actual = sorted (RustLanguage (config = None ).list_dependencies (top_lib_src_path , basedir = tempdir ))
109
+ self .assertEqual (actual , expected )
110
+
111
+ expected = [sub_crate_src_path ('a' ), sub_crate_src_path ('b' ), sub_crate_src_path ('c' )]
112
+ actual = sorted (RustLanguage (config = None ).list_dependencies (sub_crate_src_path ('a' ), basedir = tempdir ))
79
113
self .assertEqual (actual , expected )
80
114
81
- expected = [tempdir / 'crates' / 'a' / 'src' / 'lib.rs' , tempdir / 'verification' / 'src' / 'bin' / 'aizu-online-judge-itp1-1-a.rs' ]
82
- actual = sorted (RustLanguage (config = None ).list_dependencies (tempdir / 'verification' / 'src' / 'bin' / 'aizu-online-judge-itp1-1-a.rs' , basedir = tempdir ))
115
+ for src_path in [sub_crate_src_path ('b' ), sub_crate_src_path ('c' )]:
116
+ expected = [src_path ]
117
+ actual = sorted (RustLanguage (config = None ).list_dependencies (src_path , basedir = tempdir ))
118
+ self .assertEqual (actual , expected )
119
+
120
+ expected = [sub_crate_src_path ('a' ), verification_src_path ]
121
+ actual = sorted (RustLanguage (config = None ).list_dependencies (verification_src_path , basedir = tempdir ))
83
122
self .assertEqual (actual , expected )
84
123
85
124
def test_separate_workspaces (self ) -> None :
@@ -89,13 +128,27 @@ def test_separate_workspaces(self) -> None:
89
128
""" ).encode (),
90
129
pathlib .Path ('Cargo.toml' ): textwrap .dedent ("""\
91
130
[workspace]
92
- members = ["crates/*"]
131
+
132
+ [package]
133
+ name = "my_competitive_library"
134
+ version = "0.0.0"
135
+ edition = "2018"
136
+
137
+ [dependencies]
138
+ my-competitive-library-a = { path = "./crates/a" }
139
+ """ ).encode (),
140
+ pathlib .Path ('src' , 'lib.rs' ): textwrap .dedent ("""\
141
+ macro_rules! re_export(($($name:ident),* $(,)?) => ($(pub mod $name { pub use $name::*; })*));
142
+ re_export!(a);
93
143
""" ).encode (),
94
144
pathlib .Path ('crates' , 'a' , 'Cargo.toml' ): textwrap .dedent ("""\
95
145
[package]
96
- name = "a"
146
+ name = "my-competitive-library- a"
97
147
version = "0.0.0"
98
148
edition = "2018"
149
+
150
+ [lib]
151
+ name = "a"
99
152
""" ).encode (),
100
153
pathlib .Path ('crates' , 'a' , 'src' , 'lib.rs' ): b'' ,
101
154
pathlib .Path ('verification' , 'aizu-online-judge' , 'Cargo.toml' ): textwrap .dedent ("""\
@@ -107,7 +160,7 @@ def test_separate_workspaces(self) -> None:
107
160
edition = "2018"
108
161
109
162
[dependencies]
110
- a = { path = "../../crates/a" }
163
+ my-competitive-library- a = { path = "../../crates/a" }
111
164
""" ).encode (),
112
165
pathlib .Path ('verification' , 'aizu-online-judge' , 'src' , 'bin' , 'itp1-1-a.rs' ): textwrap .dedent ("""\
113
166
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A
@@ -121,15 +174,20 @@ def test_separate_workspaces(self) -> None:
121
174
}
122
175
123
176
with tests .utils .load_files_pathlib (files ) as tempdir :
124
- library_path = tempdir / 'crates' / 'a' / 'src' / 'lib.rs'
125
- verification_path = tempdir / 'verification' / 'aizu-online-judge' / 'src' / 'bin' / 'itp1-1-a.rs'
177
+ top_lib_src_path = tempdir / 'src' / 'lib.rs'
178
+ sub_lib_src_path = tempdir / 'crates' / 'a' / 'src' / 'lib.rs'
179
+ verification_src_path = tempdir / 'verification' / 'aizu-online-judge' / 'src' / 'bin' / 'itp1-1-a.rs'
180
+
181
+ expected = [sub_lib_src_path , top_lib_src_path ]
182
+ actual = sorted (RustLanguage (config = None ).list_dependencies (top_lib_src_path , basedir = tempdir ))
183
+ self .assertEqual (actual , expected )
126
184
127
- expected = [library_path ]
128
- actual = sorted (RustLanguage (config = None ).list_dependencies (library_path , basedir = tempdir ))
185
+ expected = [sub_lib_src_path ]
186
+ actual = sorted (RustLanguage (config = None ).list_dependencies (sub_lib_src_path , basedir = tempdir ))
129
187
self .assertEqual (actual , expected )
130
188
131
- expected = [library_path , verification_path ]
132
- actual = sorted (RustLanguage (config = None ).list_dependencies (verification_path , basedir = tempdir ))
189
+ expected = [sub_lib_src_path , verification_src_path ]
190
+ actual = sorted (RustLanguage (config = None ).list_dependencies (verification_src_path , basedir = tempdir ))
133
191
self .assertEqual (actual , expected )
134
192
135
193
def test_gathered_source_files (self ) -> None :
@@ -222,16 +280,28 @@ def test_gathered_source_files(self) -> None:
222
280
}
223
281
224
282
with tests .utils .load_files_pathlib (files ) as tempdir :
225
- expected = [* [tempdir / 'crates' / 'sourcefiles' / f'{ name } .rs' for name in ['a' , 'b' , 'c' ]], tempdir / 'src' / 'lib.rs' ]
226
- actual = sorted (RustLanguage (config = None ).list_dependencies (tempdir / 'src' / 'lib.rs' , basedir = tempdir ))
283
+
284
+ def sub_lib_src_path (crate_name : str ) -> pathlib .Path :
285
+ return tempdir / 'crates' / 'sourcefiles' / f'{ crate_name } .rs'
286
+
287
+ top_lib_src_path = tempdir / 'src' / 'lib.rs'
288
+ verification_src_path = tempdir / 'verification' / 'src' / 'bin' / 'aizu-online-judge-itp1-1-a.rs'
289
+
290
+ expected = [* map (sub_lib_src_path , ['a' , 'b' , 'c' ]), top_lib_src_path ]
291
+ actual = sorted (RustLanguage (config = None ).list_dependencies (top_lib_src_path , basedir = tempdir ))
227
292
self .assertEqual (actual , expected )
228
293
229
- expected = [ tempdir / 'crates' / 'sourcefiles' / f' { name } .rs' for name in ['a' , 'b' , 'c' ]]
230
- actual = sorted (RustLanguage (config = None ).list_dependencies (tempdir / 'crates' / 'sourcefiles' / 'a.rs' , basedir = tempdir ))
294
+ expected = list ( map ( sub_lib_src_path , ['a' , 'b' , 'c' ]))
295
+ actual = sorted (RustLanguage (config = None ).list_dependencies (sub_lib_src_path ( 'a' ) , basedir = tempdir ))
231
296
self .assertEqual (actual , expected )
232
297
233
- expected = [tempdir / 'crates' / 'sourcefiles' / 'a.rs' , tempdir / 'verification' / 'src' / 'bin' / 'aizu-online-judge-itp1-1-a.rs' ]
234
- actual = sorted (RustLanguage (config = None ).list_dependencies (tempdir / 'verification' / 'src' / 'bin' / 'aizu-online-judge-itp1-1-a.rs' , basedir = tempdir ))
298
+ for src_path in map (sub_lib_src_path , ['b' , 'c' ]):
299
+ expected = [src_path ]
300
+ actual = sorted (RustLanguage (config = None ).list_dependencies (src_path , basedir = tempdir ))
301
+ self .assertEqual (actual , expected )
302
+
303
+ expected = [sub_lib_src_path ('a' ), verification_src_path ]
304
+ actual = sorted (RustLanguage (config = None ).list_dependencies (verification_src_path , basedir = tempdir ))
235
305
self .assertEqual (actual , expected )
236
306
237
307
def test_mono_package (self ) -> None :
@@ -275,6 +345,33 @@ def test_mono_package(self) -> None:
275
345
actual = sorted (RustLanguage (config = None ).list_dependencies (tempdir / 'examples' / 'aizu-online-judge-itp1-1-a.rs' , basedir = tempdir ))
276
346
self .assertEqual (actual , expected )
277
347
348
+ def test_external_crates (self ) -> None :
349
+ files = {
350
+ pathlib .Path ('rust-toolchain' ): textwrap .dedent ("""\
351
+ 1.42.0
352
+ """ ).encode (),
353
+ pathlib .Path ('Cargo.toml' ): textwrap .dedent ("""\
354
+ [package]
355
+ name = "my_competitive_library"
356
+ version = "0.0.0"
357
+ edition = "2018"
358
+
359
+ [dependencies]
360
+ ac-library-rs = { git = "https://github.com/rust-lang-ja/ac-library-rs", rev = "19509cd5103313b884f89b3001510d5155bbb4db" }
361
+ maplit = "=1.0.2"
362
+ """ ).encode (),
363
+ pathlib .Path ('src' , 'lib.rs' ): textwrap .dedent ("""\
364
+ use {ac_library_rs as _, maplit as _};
365
+ """ ).encode (),
366
+ }
367
+
368
+ with tests .utils .load_files_pathlib (files ) as tempdir :
369
+ src_path = tempdir / 'src' / 'lib.rs'
370
+
371
+ expected = [src_path ]
372
+ actual = sorted (RustLanguage (config = None ).list_dependencies (src_path , basedir = tempdir ))
373
+ self .assertEqual (actual , expected )
374
+
278
375
def test_build_dependencies (self ) -> None :
279
376
files = {
280
377
pathlib .Path ('rust-toolchain' ): textwrap .dedent ("""\
0 commit comments