Skip to content

Commit 052da00

Browse files
committed
Add more tests
1 parent 8ea259c commit 052da00

File tree

1 file changed

+154
-1
lines changed

1 file changed

+154
-1
lines changed

tests/test_rust.py

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,160 @@ def test_separate_crates(self) -> None:
8282
actual = sorted(RustLanguage(config=None).list_dependencies(tempdir / 'verification' / 'src' / 'bin' / 'aizu-online-judge-itp1-1-a.rs', basedir=tempdir))
8383
self.assertEqual(actual, expected)
8484

85-
def test_mono_crate(self) -> None:
85+
def test_separate_workspaces(self) -> None:
86+
files = {
87+
pathlib.Path('rust-toolchain'): textwrap.dedent("""\
88+
1.42.0
89+
""").encode(),
90+
pathlib.Path('Cargo.toml'): textwrap.dedent("""\
91+
[workspace]
92+
members = ["crates/*"]
93+
""").encode(),
94+
pathlib.Path('crates', 'a', 'Cargo.toml'): textwrap.dedent("""\
95+
[package]
96+
name = "a"
97+
version = "0.0.0"
98+
edition = "2018"
99+
""").encode(),
100+
pathlib.Path('crates', 'a', 'src', 'lib.rs'): b'',
101+
pathlib.Path('verification', 'aizu-online-judge', 'Cargo.toml'): textwrap.dedent("""\
102+
[workspace]
103+
104+
[package]
105+
name = "aizu-online-judge"
106+
version = "0.0.0"
107+
edition = "2018"
108+
109+
[dependencies]
110+
a = { path = "../../crates/a" }
111+
""").encode(),
112+
pathlib.Path('verification', 'aizu-online-judge', 'src', 'bin', 'itp1-1-a.rs'): textwrap.dedent("""\
113+
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A
114+
115+
use a as _;
116+
117+
fn main() {
118+
println!("Hello World");
119+
}
120+
""").encode(),
121+
}
122+
123+
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'
126+
127+
expected = [library_path]
128+
actual = sorted(RustLanguage(config=None).list_dependencies(library_path, basedir=tempdir))
129+
self.assertEqual(actual, expected)
130+
131+
expected = [library_path, verification_path]
132+
actual = sorted(RustLanguage(config=None).list_dependencies(verification_path, basedir=tempdir))
133+
self.assertEqual(actual, expected)
134+
135+
def test_gathered_source_files(self) -> None:
136+
files = {
137+
pathlib.Path('rust-toolchain'): textwrap.dedent("""\
138+
1.42.0
139+
""").encode(),
140+
pathlib.Path('Cargo.toml'): textwrap.dedent("""\
141+
[workspace]
142+
members = ["verification"]
143+
144+
[package]
145+
name = "my_competitive_library"
146+
version = "0.0.0"
147+
edition = "2018"
148+
149+
[dependencies]
150+
my-competitive-library-a = { path = "./crates/manifests/a" }
151+
my-competitive-library-b = { path = "./crates/manifests/b" }
152+
my-competitive-library-c = { path = "./crates/manifests/c" }
153+
""").encode(),
154+
pathlib.Path('src', 'lib.rs'): textwrap.dedent("""\
155+
macro_rules! re_export(($($name:ident),* $(,)?) => ($(pub mod $name { pub use $name::*; })*));
156+
re_export!(a, b, c);
157+
""").encode(),
158+
pathlib.Path('crates', 'manifests', 'a', 'Cargo.toml'): textwrap.dedent("""\
159+
[package]
160+
name = "my-competitive-library-a"
161+
version = "0.0.0"
162+
edition = "2018"
163+
164+
[lib]
165+
name = "a"
166+
path = "../../sourcefiles/a.rs"
167+
168+
[dependencies]
169+
my-competitive-library-b = { path = "../b" }
170+
my-competitive-library-c = { path = "../c" }
171+
""").encode(),
172+
pathlib.Path('crates', 'manifests', 'b', 'Cargo.toml'): textwrap.dedent("""\
173+
[package]
174+
name = "my-competitive-library-b"
175+
version = "0.0.0"
176+
edition = "2018"
177+
178+
[lib]
179+
name = "b"
180+
path = "../../sourcefiles/b.rs"
181+
""").encode(),
182+
pathlib.Path('crates', 'manifests', 'c', 'Cargo.toml'): textwrap.dedent("""\
183+
[package]
184+
name = "my-competitive-library-c"
185+
version = "0.0.0"
186+
edition = "2018"
187+
188+
[lib]
189+
name = "c"
190+
path = "../../sourcefiles/c.rs"
191+
""").encode(),
192+
pathlib.Path('crates', 'sourcefiles', 'a.rs'): textwrap.dedent("""\
193+
use b::B;
194+
use c::C;
195+
196+
pub struct A(B, C);
197+
""").encode(),
198+
pathlib.Path('crates', 'sourcefiles', 'b.rs'): textwrap.dedent("""\
199+
pub struct B;
200+
""").encode(),
201+
pathlib.Path('crates', 'sourcefiles', 'c.rs'): textwrap.dedent("""\
202+
pub struct C;
203+
""").encode(),
204+
pathlib.Path('verification', 'Cargo.toml'): textwrap.dedent("""\
205+
[package]
206+
name = "verification"
207+
version = "0.0.0"
208+
edition = "2018"
209+
210+
[dependencies]
211+
my-competitive-library-a = { path = "../crates/manifests/a" }
212+
""").encode(),
213+
pathlib.Path('verification', 'src', 'bin', 'aizu-online-judge-itp1-1-a.rs'): textwrap.dedent("""\
214+
// verification-helper: PROBLEM http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_1_A
215+
216+
use a as _;
217+
218+
fn main() {
219+
println!("Hello World");
220+
}
221+
""").encode(),
222+
}
223+
224+
with tests.utils.load_files_pathlib(files) as tempdir:
225+
expected = [*[tempdir / 'crates' / 'manifests' / name / '..' / '..' / '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))
227+
self.assertEqual(actual, expected)
228+
229+
# FIXME: should pass. something is wrong
230+
# expected = [tempdir / 'crates' / 'manifests' / name / '..' / '..' / 'sourcefiles' / f'{name}.rs' for name in ['a', 'b', 'c']]
231+
# actual = sorted(RustLanguage(config=None).list_dependencies(tempdir / 'crates' / 'sourcefiles' / 'a.rs', basedir=tempdir))
232+
# self.assertEqual(actual, expected)
233+
234+
expected = [tempdir / 'crates' / 'manifests' / 'a' / '..' / '..' / 'sourcefiles' / 'a.rs', tempdir / 'verification' / 'src' / 'bin' / 'aizu-online-judge-itp1-1-a.rs']
235+
actual = sorted(RustLanguage(config=None).list_dependencies(tempdir / 'verification' / 'src' / 'bin' / 'aizu-online-judge-itp1-1-a.rs', basedir=tempdir))
236+
self.assertEqual(actual, expected)
237+
238+
def test_mono_package(self) -> None:
86239
files = {
87240
pathlib.Path('rust-toolchain'): textwrap.dedent("""\
88241
1.42.0

0 commit comments

Comments
 (0)