Fix whitespace and other formatting issues
This commit: -- replaces space-based indents with tabs per the coding standards -- removes extraneous whitespace (e.g. extra spaces between function args) -- adds missing braces for a one-line if statement Signed-off-by: Jason St. John <jstjohn@purdue.edu>
This commit is contained in:
parent
b7b3f9c5e7
commit
230bd5c2fd
25 changed files with 116 additions and 115 deletions
|
@ -298,8 +298,8 @@ pkgcount=${#candidates[*]}
|
|||
|
||||
# copy the list, merging in any found sigs
|
||||
for cand in "${candidates[@]}"; do
|
||||
candtemp+=("$cand")
|
||||
[[ -f $cand.sig ]] && candtemp+=("$cand.sig")
|
||||
candtemp+=("$cand")
|
||||
[[ -f $cand.sig ]] && candtemp+=("$cand.sig")
|
||||
done
|
||||
candidates=("${candtemp[@]}")
|
||||
unset candtemp
|
||||
|
|
|
@ -184,7 +184,7 @@ elif [[ $FILE ]]; then
|
|||
fi
|
||||
|
||||
timesarray=()
|
||||
for line in "${linearray[@]}"; do
|
||||
for line in "${linearray[@]}"; do
|
||||
if [[ $line =~ ^[[:space:]]*# ]]; then
|
||||
[[ $TIMESONLY ]] || echo $line
|
||||
elif [[ $line =~ ^[[:space:]]*Server ]]; then
|
||||
|
|
|
@ -671,7 +671,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
|
|||
break;
|
||||
}
|
||||
|
||||
/* run the post-install script if it exists */
|
||||
/* run the post-install script if it exists */
|
||||
if(alpm_pkg_has_scriptlet(newpkg)
|
||||
&& !(trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
||||
char *scriptlet = _alpm_local_db_pkgpath(db, newpkg, "install");
|
||||
|
|
|
@ -79,17 +79,17 @@ typedef enum _alpm_pkgvalidation_t {
|
|||
|
||||
/** Types of version constraints in dependency specs. */
|
||||
typedef enum _alpm_depmod_t {
|
||||
/** No version constraint */
|
||||
/** No version constraint */
|
||||
ALPM_DEP_MOD_ANY = 1,
|
||||
/** Test version equality (package=x.y.z) */
|
||||
/** Test version equality (package=x.y.z) */
|
||||
ALPM_DEP_MOD_EQ,
|
||||
/** Test for at least a version (package>=x.y.z) */
|
||||
/** Test for at least a version (package>=x.y.z) */
|
||||
ALPM_DEP_MOD_GE,
|
||||
/** Test for at most a version (package<=x.y.z) */
|
||||
/** Test for at most a version (package<=x.y.z) */
|
||||
ALPM_DEP_MOD_LE,
|
||||
/** Test for greater than some version (package>x.y.z) */
|
||||
/** Test for greater than some version (package>x.y.z) */
|
||||
ALPM_DEP_MOD_GT,
|
||||
/** Test for less than some version (package<x.y.z) */
|
||||
/** Test for less than some version (package<x.y.z) */
|
||||
ALPM_DEP_MOD_LT
|
||||
} alpm_depmod_t;
|
||||
|
||||
|
@ -250,7 +250,7 @@ typedef struct _alpm_sigresult_t {
|
|||
|
||||
/**
|
||||
* Signature list. Contains the number of signatures found and a pointer to an
|
||||
* array of results. The array is of size count.
|
||||
* array of results. The array is of size count.
|
||||
*/
|
||||
typedef struct _alpm_siglist_t {
|
||||
size_t count;
|
||||
|
|
|
@ -423,7 +423,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
|
|||
}
|
||||
config = 1;
|
||||
continue;
|
||||
} else if(strcmp(entry_name, ".INSTALL") == 0) {
|
||||
} else if(strcmp(entry_name, ".INSTALL") == 0) {
|
||||
newpkg->scriptlet = 1;
|
||||
} else if(*entry_name == '.') {
|
||||
/* for now, ignore all files starting with '.' that haven't
|
||||
|
|
|
@ -381,8 +381,8 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(alpm_handle_t *handle,
|
|||
/* 1. check upgrade list for satisfiers */
|
||||
/* 2. check dblist for satisfiers */
|
||||
if(causingpkg &&
|
||||
!find_dep_satisfier(upgrade, depend) &&
|
||||
!find_dep_satisfier(dblist, depend)) {
|
||||
!find_dep_satisfier(upgrade, depend) &&
|
||||
!find_dep_satisfier(dblist, depend)) {
|
||||
alpm_depmissing_t *miss;
|
||||
char *missdepstring = alpm_dep_compute_string(depend);
|
||||
_alpm_log(handle, ALPM_LOG_DEBUG, "checkdeps: transaction would break '%s' dependency of '%s'\n",
|
||||
|
|
|
@ -357,7 +357,7 @@ int _alpm_check_downloadspace(alpm_handle_t *handle, const char *cachedir,
|
|||
size_t j;
|
||||
int error = 0;
|
||||
|
||||
/* resolve the cachedir path to ensure we check the right mountpoint. We
|
||||
/* resolve the cachedir path to ensure we check the right mountpoint. We
|
||||
* handle failures silently, and continue to use the possibly unresolved
|
||||
* path. */
|
||||
if(realpath(cachedir, resolved_cachedir) != NULL) {
|
||||
|
|
|
@ -465,7 +465,7 @@ static int curl_download_internal(struct dload_payload *payload,
|
|||
payload->curlerr);
|
||||
|
||||
/* disconnect relationships from the curl handle for things that might go out
|
||||
* of scope, but could still be touched on connection teardown. This really
|
||||
* of scope, but could still be touched on connection teardown. This really
|
||||
* only applies to FTP transfers. */
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, (char *)NULL);
|
||||
|
|
|
@ -97,7 +97,7 @@ alpm_list_t *_alpm_filelist_intersection(alpm_filelist_t *filesA,
|
|||
} else {
|
||||
/* TODO: this creates conflicts between a symlink to a directory in
|
||||
* one package and a real directory in the other. For example,
|
||||
* lib -> /usr/lib in pkg1 and /lib in pkg2. This would be allowed
|
||||
* lib -> /usr/lib in pkg1 and /lib in pkg2. This would be allowed
|
||||
* when installing one package at a time _provided_ pkg1 is installed
|
||||
* first. This will need adjusted if the order of package install can
|
||||
* be guaranteed to install the symlink first */
|
||||
|
|
|
@ -52,7 +52,7 @@ do { \
|
|||
|
||||
struct __alpm_handle_t {
|
||||
/* internal usage */
|
||||
alpm_db_t *db_local; /* local db pointer */
|
||||
alpm_db_t *db_local; /* local db pointer */
|
||||
alpm_list_t *dbs_sync; /* List of (alpm_db_t *) */
|
||||
FILE *logstream; /* log file stream pointer */
|
||||
int lockfd; /* lock file descriptor */
|
||||
|
@ -64,10 +64,10 @@ struct __alpm_handle_t {
|
|||
#endif
|
||||
|
||||
/* callback functions */
|
||||
alpm_cb_log logcb; /* Log callback function */
|
||||
alpm_cb_download dlcb; /* Download callback function */
|
||||
alpm_cb_log logcb; /* Log callback function */
|
||||
alpm_cb_download dlcb; /* Download callback function */
|
||||
alpm_cb_totaldl totaldlcb; /* Total download callback function */
|
||||
alpm_cb_fetch fetchcb; /* Download file callback function */
|
||||
alpm_cb_fetch fetchcb; /* Download file callback function */
|
||||
alpm_cb_event eventcb;
|
||||
alpm_cb_question questioncb;
|
||||
alpm_cb_progress progresscb;
|
||||
|
|
|
@ -672,7 +672,7 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
|
|||
_alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n",
|
||||
pkgname, pkgver);
|
||||
|
||||
/* run the pre-remove scriptlet if it exists */
|
||||
/* run the pre-remove scriptlet if it exists */
|
||||
if(alpm_pkg_has_scriptlet(oldpkg) &&
|
||||
!(handle->trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
||||
char *scriptlet = _alpm_local_db_pkgpath(handle->db_local,
|
||||
|
@ -692,7 +692,7 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
|
|||
oldpkg->name, oldpkg->version);
|
||||
}
|
||||
|
||||
/* run the post-remove script if it exists */
|
||||
/* run the post-remove script if it exists */
|
||||
if(!newpkg && alpm_pkg_has_scriptlet(oldpkg) &&
|
||||
!(handle->trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
||||
char *scriptlet = _alpm_local_db_pkgpath(handle->db_local,
|
||||
|
|
|
@ -85,27 +85,27 @@ static alpm_list_t *list_sigsum(gpgme_sigsum_t sigsum)
|
|||
/* The docs say this can be a bitmask...not sure I believe it, but we'll code
|
||||
* for it anyway and show all possible flags in the returned string. */
|
||||
|
||||
/* The signature is fully valid. */
|
||||
/* The signature is fully valid. */
|
||||
sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_VALID, "valid");
|
||||
/* The signature is good. */
|
||||
/* The signature is good. */
|
||||
sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_GREEN, "green");
|
||||
/* The signature is bad. */
|
||||
/* The signature is bad. */
|
||||
sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_RED, "red");
|
||||
/* One key has been revoked. */
|
||||
/* One key has been revoked. */
|
||||
sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_KEY_REVOKED, "key revoked");
|
||||
/* One key has expired. */
|
||||
/* One key has expired. */
|
||||
sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_KEY_EXPIRED, "key expired");
|
||||
/* The signature has expired. */
|
||||
/* The signature has expired. */
|
||||
sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_SIG_EXPIRED, "sig expired");
|
||||
/* Can't verify: key missing. */
|
||||
/* Can't verify: key missing. */
|
||||
sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_KEY_MISSING, "key missing");
|
||||
/* CRL not available. */
|
||||
/* CRL not available. */
|
||||
sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_CRL_MISSING, "crl missing");
|
||||
/* Available CRL is too old. */
|
||||
/* Available CRL is too old. */
|
||||
sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_CRL_TOO_OLD, "crl too old");
|
||||
/* A policy was not met. */
|
||||
/* A policy was not met. */
|
||||
sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_BAD_POLICY, "bad policy");
|
||||
/* A system error occurred. */
|
||||
/* A system error occurred. */
|
||||
sigsum_test_bit(sigsum, &summary, GPGME_SIGSUM_SYS_ERROR, "sys error");
|
||||
/* Fallback case */
|
||||
if(!sigsum) {
|
||||
|
@ -679,7 +679,7 @@ error:
|
|||
return ret;
|
||||
}
|
||||
|
||||
#else /* HAVE_LIBGPGME */
|
||||
#else /* HAVE_LIBGPGME */
|
||||
int _alpm_key_in_keychain(alpm_handle_t UNUSED *handle, const char UNUSED *fpr)
|
||||
{
|
||||
return -1;
|
||||
|
|
|
@ -289,7 +289,7 @@ int _alpm_runscriptlet(alpm_handle_t *handle, const char *filepath,
|
|||
|
||||
if(!is_archive && !grep(filepath, script)) {
|
||||
/* script not found in scriptlet file; we can only short-circuit this early
|
||||
* if it is an actual scriptlet file and not an archive. */
|
||||
* if it is an actual scriptlet file and not an archive. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -920,7 +920,7 @@ char SYMEXPORT *alpm_compute_sha256sum(const char *filename)
|
|||
return hex_representation(output, 32);
|
||||
}
|
||||
|
||||
/** Calculates a file's MD5 or SHA2 digest and compares it to an expected value.
|
||||
/** Calculates a file's MD5 or SHA-2 digest and compares it to an expected value.
|
||||
* @param filepath path of the file to check
|
||||
* @param expected hash value to compare against
|
||||
* @param type digest type to use
|
||||
|
|
|
@ -1336,8 +1336,8 @@ extract_sources() {
|
|||
for netfile in "${source[@]}"; do
|
||||
local file=$(get_filename "$netfile")
|
||||
if in_array "$file" "${noextract[@]}"; then
|
||||
#skip source files in the noextract=() array
|
||||
# these are marked explicitly to NOT be extracted
|
||||
# skip source files in the noextract=() array
|
||||
# these are marked explicitly to NOT be extracted
|
||||
continue
|
||||
fi
|
||||
local proto=$(get_protocol "$netfile")
|
||||
|
@ -2488,7 +2488,7 @@ usage() {
|
|||
printf -- "$(gettext "Options:")\n"
|
||||
printf -- "$(gettext " -A, --ignorearch Ignore incomplete %s field in %s")\n" "arch" "$BUILDSCRIPT"
|
||||
printf -- "$(gettext " -c, --clean Clean up work files after build")\n"
|
||||
printf -- "$(gettext " -C, --cleanbuild Remove %s dir before building the package")\n" "\$srcdir/"
|
||||
printf -- "$(gettext " -C, --cleanbuild Remove %s dir before building the package")\n" "\$srcdir/"
|
||||
printf -- "$(gettext " -d, --nodeps Skip all dependency checks")\n"
|
||||
printf -- "$(gettext " -e, --noextract Do not extract source files (use existing %s dir)")\n" "\$srcdir/"
|
||||
printf -- "$(gettext " -f, --force Overwrite existing package")\n"
|
||||
|
|
|
@ -142,8 +142,8 @@ msg "$(gettext "Making and MD5sum'ing the new database...")"
|
|||
mkdir "$localdb.new"
|
||||
bsdtar -xpf "$workdir/pacman-db.tar.gz" -C "$localdb.new"
|
||||
if (( $? )); then
|
||||
rm -rf "$workdir"
|
||||
die_r "$(gettext "Untar'ing %s failed.")" "$localdb"
|
||||
rm -rf "$workdir"
|
||||
die_r "$(gettext "Untar'ing %s failed.")" "$localdb"
|
||||
fi
|
||||
# immediate sync following extraction should get it written continuously on HDD
|
||||
msg "$(gettext "Syncing database to disk...")"
|
||||
|
|
|
@ -82,9 +82,9 @@ char *mdirname(const char *path)
|
|||
*/
|
||||
static size_t strnlen(const char *s, size_t max)
|
||||
{
|
||||
register const char *p;
|
||||
for(p = s; *p && max--; ++p);
|
||||
return (p - s);
|
||||
register const char *p;
|
||||
for(p = s; *p && max--; ++p);
|
||||
return (p - s);
|
||||
}
|
||||
|
||||
/** Copies a string.
|
||||
|
@ -95,14 +95,15 @@ static size_t strnlen(const char *s, size_t max)
|
|||
*/
|
||||
char *strndup(const char *s, size_t n)
|
||||
{
|
||||
size_t len = strnlen(s, n);
|
||||
char *new = (char *) malloc(len + 1);
|
||||
size_t len = strnlen(s, n);
|
||||
char *new = (char *) malloc(len + 1);
|
||||
|
||||
if(new == NULL)
|
||||
return NULL;
|
||||
if(new == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new[len] = '\0';
|
||||
return (char *)memcpy(new, s, len);
|
||||
new[len] = '\0';
|
||||
return (char *)memcpy(new, s, len);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -156,7 +156,7 @@ void cb_event(alpm_event_t event, void *data1, void *data2)
|
|||
}
|
||||
switch(event) {
|
||||
case ALPM_EVENT_CHECKDEPS_START:
|
||||
printf(_("checking dependencies...\n"));
|
||||
printf(_("checking dependencies...\n"));
|
||||
break;
|
||||
case ALPM_EVENT_FILECONFLICTS_START:
|
||||
if(config->noprogressbar) {
|
||||
|
@ -294,7 +294,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2,
|
|||
case ALPM_QUESTION_INSTALL_IGNOREPKG:
|
||||
if(!config->op_s_downloadonly) {
|
||||
*response = yesno(_("%s is in IgnorePkg/IgnoreGroup. Install anyway?"),
|
||||
alpm_pkg_get_name(data1));
|
||||
alpm_pkg_get_name(data1));
|
||||
} else {
|
||||
*response = 1;
|
||||
}
|
||||
|
@ -698,7 +698,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
|
|||
fname[len] = '\0';
|
||||
|
||||
/* 1 space + filenamelen + 1 space + 6 for size + 1 space + 3 for label +
|
||||
* + 2 spaces + 4 for rate + 1 for label + 2 for /s + 1 space +
|
||||
* + 2 spaces + 4 for rate + 1 for label + 2 for /s + 1 space +
|
||||
* 8 for eta, gives us the magic 30 */
|
||||
filenamelen = infolen - 30;
|
||||
/* see printf() code, we omit 'HH:' in these conditions */
|
||||
|
|
|
@ -689,7 +689,7 @@ static int setup_libalpm(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* Set GnuPG's home directory. This is not relative to rootdir, even if
|
||||
/* Set GnuPG's home directory. This is not relative to rootdir, even if
|
||||
* rootdir is defined. Reasoning: gpgdir contains configuration data. */
|
||||
config->gpgdir = config->gpgdir ? config->gpgdir : strdup(GPGDIR);
|
||||
ret = alpm_option_set_gpgdir(handle, config->gpgdir);
|
||||
|
|
|
@ -189,7 +189,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
|
|||
}
|
||||
if(from == ALPM_PKG_FROM_FILE || from == ALPM_PKG_FROM_LOCALDB) {
|
||||
string_display(_("Install Script :"),
|
||||
alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"), cols);
|
||||
alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No"), cols);
|
||||
}
|
||||
|
||||
if(from == ALPM_PKG_FROM_SYNCDB && extra) {
|
||||
|
@ -206,7 +206,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
|
|||
}
|
||||
|
||||
string_display(_("MD5 Sum :"), alpm_pkg_get_md5sum(pkg), cols);
|
||||
string_display(_("SHA256 Sum :"), alpm_pkg_get_sha256sum(pkg), cols);
|
||||
string_display(_("SHA-256 Sum :"), alpm_pkg_get_sha256sum(pkg), cols);
|
||||
list_display(_("Signatures :"), keys, cols);
|
||||
} else {
|
||||
list_display(_("Validated By :"), validation, cols);
|
||||
|
|
|
@ -601,7 +601,7 @@ static void checkargs_query(void)
|
|||
|
||||
invalid_opt(config->op_q_deps && config->op_q_explicit, "--deps", "--explicit");
|
||||
invalid_opt((config->op_q_locality & PKG_LOCALITY_NATIVE) &&
|
||||
(config->op_q_locality & PKG_LOCALITY_FOREIGN),
|
||||
(config->op_q_locality & PKG_LOCALITY_FOREIGN),
|
||||
"--native", "--foreign");
|
||||
}
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ static int query_fileowner(alpm_list_t *targets)
|
|||
}
|
||||
|
||||
if(lstat(filename, &buf) == -1) {
|
||||
/* if it is not a path but a program name, then check in PATH */
|
||||
/* if it is not a path but a program name, then check in PATH */
|
||||
if(strchr(filename, '/') == NULL) {
|
||||
if(search_path(&filename, &buf) == -1) {
|
||||
pm_printf(ALPM_LOG_ERROR, _("failed to find '%s' in PATH: %s\n"),
|
||||
|
|
|
@ -1569,7 +1569,7 @@ int pm_asprintf(char **string, const char *format, ...)
|
|||
/* print the message using va_arg list */
|
||||
va_start(args, format);
|
||||
if(vasprintf(string, format, args) == -1) {
|
||||
pm_printf(ALPM_LOG_ERROR, _("failed to allocate string\n"));
|
||||
pm_printf(ALPM_LOG_ERROR, _("failed to allocate string\n"));
|
||||
ret = -1;
|
||||
}
|
||||
va_end(args);
|
||||
|
|
|
@ -5,43 +5,43 @@ declare -i testcount=0 fail=0 pass=0 total=15
|
|||
# source the library function
|
||||
lib=${1:-${PMTEST_SCRIPTLIB_DIR}human_to_size.sh}
|
||||
if [[ -z $lib || ! -f $lib ]]; then
|
||||
echo "Bail out! human_to_size library ($lib) could not be located\n"
|
||||
exit 1
|
||||
echo "Bail out! human_to_size library ($lib) could not be located\n"
|
||||
exit 1
|
||||
fi
|
||||
. "$lib"
|
||||
|
||||
if ! type -t human_to_size &>/dev/null; then
|
||||
printf 'Bail out! human_to_size function not found\n'
|
||||
exit 1
|
||||
printf "Bail out! human_to_size function not found\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
parse_hts() {
|
||||
local input=$1 expected=$2 result
|
||||
local input=$1 expected=$2 result
|
||||
|
||||
(( ++testcount ))
|
||||
(( ++testcount ))
|
||||
|
||||
result=$(human_to_size "$1")
|
||||
if [[ $result = "$expected" ]]; then
|
||||
(( ++pass ))
|
||||
printf "ok %d - %s\n" "$testcount" "$input"
|
||||
else
|
||||
(( ++fail ))
|
||||
printf "not ok %d - %s\n" "$testcount" "$input"
|
||||
printf '# [TEST %3s]: FAIL\n' "$testcount"
|
||||
printf '# input: %s\n' "$input"
|
||||
printf '# output: %s\n' "$result"
|
||||
printf '# expected: %s\n' "$expected"
|
||||
fi
|
||||
result=$(human_to_size "$1")
|
||||
if [[ $result = "$expected" ]]; then
|
||||
(( ++pass ))
|
||||
printf "ok %d - %s\n" "$testcount" "$input"
|
||||
else
|
||||
(( ++fail ))
|
||||
printf "not ok %d - %s\n" "$testcount" "$input"
|
||||
printf '# [TEST %3s]: FAIL\n' "$testcount"
|
||||
printf '# input: %s\n' "$input"
|
||||
printf '# output: %s\n' "$result"
|
||||
printf '# expected: %s\n' "$expected"
|
||||
fi
|
||||
}
|
||||
|
||||
summarize() {
|
||||
if (( !fail )); then
|
||||
printf '# All %s tests successful\n\n' "$testcount"
|
||||
exit 0
|
||||
else
|
||||
printf '# %s of %s tests failed\n\n' "$fail" "$testcount"
|
||||
exit 1
|
||||
fi
|
||||
if (( !fail )); then
|
||||
printf '# All %s tests successful\n\n' "$testcount"
|
||||
exit 0
|
||||
else
|
||||
printf '# %s of %s tests failed\n\n' "$fail" "$testcount"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
trap 'summarize' EXIT
|
||||
|
||||
|
|
|
@ -5,14 +5,14 @@ declare -i testcount=0 pass=0 fail=0 total=25
|
|||
# source the library function
|
||||
lib=${1:-${PMTEST_SCRIPTLIB_DIR}parseopts.sh}
|
||||
if [[ -z $lib || ! -f $lib ]]; then
|
||||
printf "Bail out! parseopts library ($lib) could not be located\n"
|
||||
exit 1
|
||||
printf "Bail out! parseopts library ($lib) could not be located\n"
|
||||
exit 1
|
||||
fi
|
||||
. "$lib"
|
||||
|
||||
if ! type -t parseopts &>/dev/null; then
|
||||
printf 'Bail out! parseopts function not found\n'
|
||||
exit 1
|
||||
printf "Bail out! parseopts function not found\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# borrow opts from makepkg
|
||||
|
@ -24,38 +24,38 @@ OPT_LONG=('allsource' 'asroot' 'ignorearch' 'check' 'clean:' 'cleanall' 'nodeps'
|
|||
'noconfirm' 'noprogressbar')
|
||||
|
||||
parse() {
|
||||
local result=$1 tokencount=$2; shift 2
|
||||
local result=$1 tokencount=$2; shift 2
|
||||
|
||||
(( ++testcount ))
|
||||
parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@" 2>/dev/null
|
||||
test_result "$result" "$tokencount" "$*" "${OPTRET[@]}"
|
||||
unset OPTRET
|
||||
(( ++testcount ))
|
||||
parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@" 2>/dev/null
|
||||
test_result "$result" "$tokencount" "$*" "${OPTRET[@]}"
|
||||
unset OPTRET
|
||||
}
|
||||
|
||||
test_result() {
|
||||
local result=$1 tokencount=$2 input=$3; shift 3
|
||||
local result=$1 tokencount=$2 input=$3; shift 3
|
||||
|
||||
if [[ $result = "$*" ]] && (( tokencount == $# )); then
|
||||
(( ++pass ))
|
||||
printf 'ok %d - %s\n' "$testcount" "$input"
|
||||
else
|
||||
printf 'not ok %d - %s\n' "$testcount" "$input"
|
||||
printf '# [TEST %3s]: FAIL\n' "$testcount"
|
||||
printf '# input: %s\n' "$input"
|
||||
printf '# output: %s (%s tokens)\n' "$*" "$#"
|
||||
printf '# expected: %s (%s tokens)\n' "$result" "$tokencount"
|
||||
(( ++fail ))
|
||||
fi
|
||||
if [[ $result = "$*" ]] && (( tokencount == $# )); then
|
||||
(( ++pass ))
|
||||
printf 'ok %d - %s\n' "$testcount" "$input"
|
||||
else
|
||||
printf 'not ok %d - %s\n' "$testcount" "$input"
|
||||
printf '# [TEST %3s]: FAIL\n' "$testcount"
|
||||
printf '# input: %s\n' "$input"
|
||||
printf '# output: %s (%s tokens)\n' "$*" "$#"
|
||||
printf '# expected: %s (%s tokens)\n' "$result" "$tokencount"
|
||||
(( ++fail ))
|
||||
fi
|
||||
}
|
||||
|
||||
summarize() {
|
||||
if (( !fail )); then
|
||||
printf '# All %s tests successful\n\n' "$testcount"
|
||||
exit 0
|
||||
else
|
||||
printf '# %s of %s tests failed\n\n' "$fail" "$testcount"
|
||||
exit 1
|
||||
fi
|
||||
if (( !fail )); then
|
||||
printf '# All %s tests successful\n\n' "$testcount"
|
||||
exit 0
|
||||
else
|
||||
printf '# %s of %s tests failed\n\n' "$fail" "$testcount"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
trap 'summarize' EXIT
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue