diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-04-23 22:43:20 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-04-24 10:05:04 +0200 |
commit | 250e9fadbcc0ca90e697d7efb40855b054ed3b8f (patch) | |
tree | dc7a2c14372d378e114fdd634d55d80afb179534 /src/test | |
parent | man: fix description of %N in systemd.unit(5) (diff) | |
download | systemd-250e9fadbcc0ca90e697d7efb40855b054ed3b8f.tar.xz systemd-250e9fadbcc0ca90e697d7efb40855b054ed3b8f.zip |
Add %j/%J unit specifiers
Those are quite similar to %i/%I, but refer to the last dash-separated
component of the name prefix.
The new functionality of dash-dropins could largely supersede the template
functionality, so it would be tempting to overload %i/%I. But that would
not be backwards compatible. So let's add the two new letters instead.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-unit-file.c | 1 | ||||
-rw-r--r-- | src/test/test-unit-name.c | 58 |
2 files changed, 40 insertions, 19 deletions
diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index 6b72fc90fd..3fd4ac9e5d 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -662,6 +662,7 @@ static void test_install_printf(void) { expect(i, "%N", "name"); expect(i, "%p", "name"); expect(i, "%i", ""); + expect(i, "%j", "name"); expect(i, "%u", user); expect(i, "%U", uid); diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c index 347c586663..300a1c5a82 100644 --- a/src/test/test-unit-name.c +++ b/src/test/test-unit-name.c @@ -198,7 +198,7 @@ static void test_unit_name_mangle(void) { static int test_unit_printf(void) { _cleanup_free_ char *mid = NULL, *bid = NULL, *host = NULL, *uid = NULL, *user = NULL, *shell = NULL, *home = NULL; _cleanup_(manager_freep) Manager *m = NULL; - Unit *u, *u2; + Unit *u; int r; assert_se(specifier_machine_id('m', NULL, NULL, &mid) >= 0 && mid); @@ -245,6 +245,9 @@ static int test_unit_printf(void) { expect(u, "%p", "blah"); expect(u, "%P", "blah"); expect(u, "%i", ""); + expect(u, "%I", ""); + expect(u, "%j", "blah"); + expect(u, "%J", "blah"); expect(u, "%u", user); expect(u, "%U", uid); expect(u, "%h", home); @@ -254,24 +257,41 @@ static int test_unit_printf(void) { expect(u, "%t", "/run/user/*"); /* templated */ - assert_se(u2 = unit_new(m, sizeof(Service))); - assert_se(unit_add_name(u2, "blah@foo-foo.service") == 0); - assert_se(unit_add_name(u2, "blah@foo-foo.service") == 0); - - expect(u2, "%n", "blah@foo-foo.service"); - expect(u2, "%N", "blah@foo-foo"); - expect(u2, "%f", "/foo/foo"); - expect(u2, "%p", "blah"); - expect(u2, "%P", "blah"); - expect(u2, "%i", "foo-foo"); - expect(u2, "%I", "foo/foo"); - expect(u2, "%u", user); - expect(u2, "%U", uid); - expect(u2, "%h", home); - expect(u2, "%m", mid); - expect(u2, "%b", bid); - expect(u2, "%H", host); - expect(u2, "%t", "/run/user/*"); + assert_se(u = unit_new(m, sizeof(Service))); + assert_se(unit_add_name(u, "blah@foo-foo.service") == 0); + assert_se(unit_add_name(u, "blah@foo-foo.service") == 0); + + expect(u, "%n", "blah@foo-foo.service"); + expect(u, "%N", "blah@foo-foo"); + expect(u, "%f", "/foo/foo"); + expect(u, "%p", "blah"); + expect(u, "%P", "blah"); + expect(u, "%i", "foo-foo"); + expect(u, "%I", "foo/foo"); + expect(u, "%j", "blah"); + expect(u, "%J", "blah"); + expect(u, "%u", user); + expect(u, "%U", uid); + expect(u, "%h", home); + expect(u, "%m", mid); + expect(u, "%b", bid); + expect(u, "%H", host); + expect(u, "%t", "/run/user/*"); + + /* templated with components */ + assert_se(u = unit_new(m, sizeof(Slice))); + assert_se(unit_add_name(u, "blah-blah\\x2d.slice") == 0); + + expect(u, "%n", "blah-blah\\x2d.slice"); + expect(u, "%N", "blah-blah\\x2d"); + expect(u, "%f", "/blah/blah-"); + expect(u, "%p", "blah-blah\\x2d"); + expect(u, "%P", "blah/blah-"); + expect(u, "%i", ""); + expect(u, "%I", ""); + expect(u, "%j", "blah\\x2d"); + expect(u, "%J", "blah-"); + #undef expect return 0; |