Blame src/misc/basename.c
|
nsz |
7308b3 |
#define _GNU_SOURCE
|
|
nsz |
7308b3 |
#include "test.h"
|
|
nsz |
7308b3 |
#include <stdlib.h>
|
|
nsz |
7308b3 |
#include <string.h>
|
|
nsz |
7308b3 |
#include <libgen.h>
|
|
nsz |
7308b3 |
|
|
nsz |
7308b3 |
static void t(char *p, char *b) {
|
|
nsz |
7308b3 |
char *tmp = strdup(p);
|
|
nsz |
7308b3 |
char *s = basename(tmp);
|
|
nsz |
7308b3 |
|
|
nsz |
7308b3 |
if (strcmp(b,s) != 0)
|
|
nsz |
7308b3 |
error("basename(\"%s\") returned \"%s\"; expected \"%s\"\n", p, s, b);
|
|
nsz |
7308b3 |
free(tmp);
|
|
nsz |
7308b3 |
}
|
|
nsz |
7308b3 |
|
|
nsz |
7308b3 |
void test_basename() {
|
|
nsz |
7308b3 |
if (strcmp(".", basename(0)) != 0)
|
|
nsz |
7308b3 |
error("basename(0) returned \"%s\"; expected \".\"\n", basename(0));
|
|
nsz |
7308b3 |
t("", ".");
|
|
nsz |
7308b3 |
t("/usr/lib", "lib");
|
|
nsz |
7308b3 |
t("/usr/", "usr");
|
|
nsz |
7308b3 |
t("/", "/");
|
|
nsz |
7308b3 |
t("///", "/");
|
|
nsz |
7308b3 |
t("//usr//lib//", "lib");
|
|
nsz |
7308b3 |
}
|