Skip to content

Commit 685bf6e

Browse files
committed
Add tests
1 parent ddfcd5f commit 685bf6e

File tree

1 file changed

+151
-3
lines changed

1 file changed

+151
-3
lines changed

β€Žtests/attributes.rs

Lines changed: 151 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,159 @@ fn aliases_can_be_defined_as_attributes() {
260260
Test::new()
261261
.justfile(
262262
"
263-
[alias('bar')]
264-
baz:
265-
",
263+
[alias('bar')]
264+
baz:
265+
",
266266
)
267267
.arg("bar")
268268
.status(EXIT_SUCCESS)
269269
.run();
270270
}
271+
272+
#[test]
273+
fn multiple_aliases_can_be_defined_as_attributes() {
274+
Test::new()
275+
.justfile(
276+
"
277+
[alias('bar')]
278+
[alias('foo')]
279+
baz:
280+
",
281+
)
282+
.arg("foo")
283+
.status(EXIT_SUCCESS)
284+
.run();
285+
}
286+
287+
#[test]
288+
fn duplicate_alias_attributes_are_forbidden() {
289+
Test::new()
290+
.justfile(
291+
"
292+
[alias('foo')]
293+
[alias('foo')]
294+
baz:
295+
",
296+
)
297+
.arg("foo")
298+
.stderr(
299+
"
300+
error: Alias `foo` first defined on line 1 is redefined on line 2
301+
β€”β€”β–Ά justfile:2:9
302+
β”‚
303+
2 β”‚ [alias('foo')]
304+
β”‚ ^^^
305+
",
306+
)
307+
.status(EXIT_FAILURE)
308+
.run();
309+
}
310+
311+
#[test]
312+
fn alias_attributes_duplicating_alias_definition_is_forbidden() {
313+
Test::new()
314+
.justfile(
315+
"
316+
alias foo := baz
317+
[alias('foo')]
318+
baz:
319+
",
320+
)
321+
.arg("foo")
322+
.stderr(
323+
"
324+
error: Alias `foo` first defined on line 1 is redefined on line 2
325+
β€”β€”β–Ά justfile:2:9
326+
β”‚
327+
2 β”‚ [alias('foo')]
328+
β”‚ ^^^
329+
",
330+
)
331+
.status(EXIT_FAILURE)
332+
.run();
333+
}
334+
335+
#[test]
336+
fn alias_definitions_duplicating_alias_attributes_is_forbidden() {
337+
Test::new()
338+
.justfile(
339+
"
340+
[alias('foo')]
341+
baz:
342+
343+
alias foo := baz
344+
",
345+
)
346+
.arg("foo")
347+
.stderr(
348+
"
349+
error: Alias `foo` first defined on line 1 is redefined on line 4
350+
β€”β€”β–Ά justfile:4:7
351+
β”‚
352+
4 β”‚ alias foo := baz
353+
β”‚ ^^^
354+
",
355+
)
356+
.status(EXIT_FAILURE)
357+
.run();
358+
}
359+
360+
#[test]
361+
fn alphanumeric_and_underscores_are_valid_alias_attributes() {
362+
Test::new()
363+
.justfile(
364+
"
365+
[alias('alpha_numeric_123')]
366+
baz:
367+
",
368+
)
369+
.arg("alpha_numeric_123")
370+
.status(EXIT_SUCCESS)
371+
.run();
372+
}
373+
374+
#[test]
375+
fn nonalphanumeric_alias_attribute_is_forbidden() {
376+
Test::new()
377+
.justfile(
378+
"
379+
[alias('invalid name!')]
380+
baz:
381+
",
382+
)
383+
.arg("foo")
384+
.stderr(
385+
"
386+
error: `invalid name!` is not a valid alias. Aliases must only contain alphanumeric characters and underscores.
387+
β€”β€”β–Ά justfile:1:9
388+
β”‚
389+
1 β”‚ [alias('invalid name!')]
390+
β”‚ ^^^^^^^^^^^^^
391+
",
392+
)
393+
.status(EXIT_FAILURE)
394+
.run();
395+
}
396+
397+
#[test]
398+
fn empty_alias_attribute_is_forbidden() {
399+
Test::new()
400+
.justfile(
401+
"
402+
[alias('')]
403+
baz:
404+
",
405+
)
406+
.arg("baz")
407+
.stderr(
408+
"
409+
error: `` is not a valid alias. Aliases must only contain alphanumeric characters and underscores.
410+
β€”β€”β–Ά justfile:1:9
411+
β”‚
412+
1 β”‚ [alias('')]
413+
β”‚ ^
414+
",
415+
)
416+
.status(EXIT_FAILURE)
417+
.run();
418+
}

0 commit comments

Comments
Β (0)