Clownfish-CFC
view release on metacpan or search on metacpan
src/CFCTest.c view on Meta::CPAN
510511512513514515516517518519520521522523524525526527528529530
CFCBase
*result
= CFCParser_parse(parser, src);
OK(test, result != NULL,
"parse class"
);
STR_EQ(test, CFCBase_get_cfc_class(result),
"Clownfish::CFC::Model::Class"
,
"result class"
);
return
(struct CFCClass*)result;
}
time_t
CFCTest_get_file_mtime(const char
*path
) {
struct
stat
buf;
if
(
stat
(path,
&buf
)) {
CFCUtil_die(
"Can't stat '%s': %s"
, path, strerror(errno));
}
return
buf.st_mtime;
}
#if defined(CHY_HAS_WINDOWS_H)
#include <windows.h>
void
src/CFCUtil.c view on Meta::CPAN
354355356357358359360361362363364365366367368369370371372373374375376377378379char
CFCUtil_toupper(char c) {
if
(!IS_ASCII(c)) {
return
c; }
return
(char)toupper(c);
}
int
CFCUtil_current(const char
*orig
, const char
*dest
) {
// If the destination file doesn
't exist, we'
re not current.
struct
stat
dest_stat;
if
(
stat
(dest,
&dest_stat
) == -1) {
return
false;
}
// If the source file is newer than the dest, we're not current.
struct
stat
orig_stat;
if
(
stat
(orig,
&orig_stat
) == -1) {
CFCUtil_die(
"Missing source file '%s': %s"
, orig, strerror(errno));
}
if
(orig_stat.st_mtime > dest_stat.st_mtime) {
return
false;
}
// Current!
return
1;
}
src/CFCUtil.c view on Meta::CPAN
478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
if
(len == -1) { CFCUtil_die(
"ftell error : %s\n"
, strerror(errno)); }
/* Return to where we were. */
check_val = fseek(f, bookmark, SEEK_SET);
if
(check_val == -1) { CFCUtil_die(
"fseek error : %s\n"
, strerror(errno)); }
return
len;
}
// Note: this
has
to be
defined
before
including the Perl headers because they
// redefine
stat
() in an incompatible way on certain systems (Windows).
int
CFCUtil_is_dir(const char
*path
) {
struct
stat
stat_buf;
int
stat_check =
stat
(path,
&stat_buf
);
if
(stat_check == -1) {
return
false;
}
return
(stat_buf.st_mode & S_IFDIR) ? true : false;
}
int
CFCUtil_make_path(const char
*path
) {
CFCUTIL_NULL_CHECK(path);
char
*target
= CFCUtil_strdup(path);
size_t orig_len = strlen(target);
size_t len = orig_len;
for
(size_t i = 0; i <= len; i++) {
if
(target[i] == CHY_DIR_SEP_CHAR || i == len) {
target[i] = 0; // NULL-terminate.
struct
stat
stat_buf;
int
stat_check =
stat
(target,
&stat_buf
);
if
(stat_check != -1) {
if
(!(stat_buf.st_mode & S_IFDIR)) {
CFCUtil_die(
"%s isn't a directory"
, target);
}
}
else
{
int
success = CFCUtil_make_dir(target);
if
(!success) {
FREEMEM(target);
return
false;
src/CFCUtil.c view on Meta::CPAN
525526527528529530531532533534535536537538539540541542543544545
FREEMEM(target);
return
true;
}
void
CFCUtil_walk(const char
*path
, CFCUtil_walk_callback_t callback,
void
*context
) {
// If it's a valid file
system
entry, invoke the callback.
struct
stat
stat_buf;
int
stat_check =
stat
(path,
&stat_buf
);
if
(stat_check == -1) {
return
;
}
callback(path, context);
// Recurse into directories.
if
(!(stat_buf.st_mode & S_IFDIR)) {
return
;
}
void
*dirhandle
= CFCUtil_opendir(path);
t/001-util.t view on Meta::CPAN
363738394041424344454647484950515253545556575859ok( current(
$foo_txt
,
$foo_txt
),
"current"
);
ok( !current(
$foo_txt
,
't'
),
"not current"
);
ok( !current(
$foo_txt
,
"nonexistent_file"
),
"not current when dest file mising"
);
my
$ten_seconds_ago
=
time
() - 10;
utime
(
$ten_seconds_ago
,
$ten_seconds_ago
,
$foo_txt
)
or
die
"utime failed"
;
write_if_changed(
$foo_txt
,
"foo"
);
is(
stat
(
$foo_txt
)->mtime,
$ten_seconds_ago
,
"write_if_changed does nothing if contents not changed"
);
write_if_changed(
$foo_txt
,
"foofoo"
);
ok(
stat
(
$foo_txt
)->mtime !=
$ten_seconds_ago
,
"write_if_changed writes if contents changed"
);
unlink
$foo_txt
;
my
%defaults
= (
foo
=>
undef
);
sub
test_verify_args {
return
verify_args( \
%defaults
,
@_
) }
ok( test_verify_args(
foo
=>
'foofoo'
),
"args verified"
);
ok( !test_verify_args(
'foo'
),
"odd args fail verification"
);
( run in 0.463 second using v1.01-cache-2.11-cpan-49f99fa48dc )