Makefile: re-write `make test` in V

pull/1625/head
Alexander Medvednikov 2019-08-16 15:05:11 +03:00
parent 5ea4b463bb
commit b188ecf680
7 changed files with 106 additions and 71 deletions

View File

@ -48,7 +48,7 @@ script:
if [[ "${TRAVIS_OS_NAME}" != "windows" ]]; then if [[ "${TRAVIS_OS_NAME}" != "windows" ]]; then
make make
./v install glfw ./v install glfw
make test ./v test v
fi fi
- | - |
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then

View File

@ -9,13 +9,5 @@ all:
rm v.c rm v.c
@echo "V has been successfully built" @echo "V has been successfully built"
test: v
./v -prod -o vprod compiler # Test prod build
echo "Running V tests..."
find . -name '*_test.v' -print0 | xargs -0 -n1 ./v
echo "Building V examples..."
find examples -name '*.v' -print0 | xargs -0 -n1 ./v
bash ./compiler/tests/repl/repl.sh
symlink: v symlink: v
ln -sf `pwd`/v ${PREFIX}/bin/v ln -sf `pwd`/v ${PREFIX}/bin/v

View File

@ -1434,6 +1434,26 @@ fn update_v() {
} }
fn test_v() { fn test_v() {
test_files := os.walk_ext('.', '_test.v')
for file in test_files {
print(file + ' ')
if os.system('v $file') != 0 {
println('failed')
exit(1)
} else {
println('OK')
}
}
println('\nBuilding examples...')
examples := os.walk_ext('examples', '.v')
for file in examples {
print(file + ' ')
if os.system('v $file') != 0 {
println('failed')
exit(1)
} else {
println('OK')
}
}
} }

View File

@ -41,9 +41,7 @@ pub fn tos_clone(s byteptr) string {
if isnil(s) { if isnil(s) {
panic('tos: nil string') panic('tos: nil string')
} }
len := strlen(s) return tos2(s).clone()
res := tos(s, len)
return res.clone()
} }
// Same as `tos`, but calculates the length. Called by `string(bytes)` casts. // Same as `tos`, but calculates the length. Called by `string(bytes)` casts.

View File

@ -20,10 +20,6 @@ struct dirent {
} }
*/ */
struct C.dirent {
d_name byteptr
}
const ( const (
args = []string args = []string
MAX_PATH = 4096 MAX_PATH = 4096
@ -804,61 +800,27 @@ mut:
wFinderFlags u16 wFinderFlags u16
} }
pub fn ls(path string) []string {
$if windows { // walk_ext returns a recursive list of all file paths ending with `ext`.
mut find_file_data := win32finddata{} pub fn walk_ext(path, ext string) []string {
mut dir_files := []string if !os.is_dir(path) {
// We can also check if the handle is valid. but using dir_exists instead return []string
// h_find_dir := C.FindFirstFile(path.str, &find_file_data)
// if (INVALID_HANDLE_VALUE == h_find_dir) {
// return dir_files
// }
// C.FindClose(h_find_dir)
if !dir_exists(path) {
println('ls() couldnt open dir "$path" (does not exist).')
return dir_files
}
// NOTE: Should eventually have path struct & os dependant path seperator (eg os.PATH_SEPERATOR)
// we need to add files to path eg. c:\windows\*.dll or :\windows\*
path_files := '$path\\*'
// NOTE:TODO: once we have a way to convert utf16 wide character to utf8
// we should use FindFirstFileW and FindNextFileW
h_find_files := C.FindFirstFile(path_files.to_wide(), &find_file_data)
first_filename := string_from_wide(&u16(find_file_data.cFileName))
if first_filename != '.' && first_filename != '..' {
dir_files << first_filename
}
for C.FindNextFile(h_find_files, &find_file_data) {
filename := string_from_wide(&u16(find_file_data.cFileName))
if filename != '.' && filename != '..' {
dir_files << filename.clone()
}
}
C.FindClose(h_find_files)
return dir_files
} }
$else { mut files := os.ls(path)
mut res := []string mut res := []string
dir := C.opendir(path.str) for i, file in files {
if isnil(dir) { if file.starts_with('.') {
println('ls() couldnt open dir "$path"') continue
print_c_errno()
return res
} }
mut ent := &C.dirent{!} p := path + '/' + file
for { if os.is_dir(p) {
ent = C.readdir(dir) res << walk_ext(p, ext)
if isnil(ent) { }
break else if file.ends_with(ext) {
} res << p
name := tos_clone(ent.d_name)
if name != '.' && name != '..' && name != '' {
res << name
}
} }
C.closedir(dir)
return res
} }
return res
} }
pub fn signal(signum int, handler voidptr) { pub fn signal(signum int, handler voidptr) {

View File

@ -7,6 +7,13 @@ const (
PathSeparator = '/' PathSeparator = '/'
) )
struct C.dirent {
d_name byteptr
}
fn C.readdir(voidptr) C.dirent
// get_error_msg return error code representation in string. // get_error_msg return error code representation in string.
pub fn get_error_msg(code int) string { pub fn get_error_msg(code int) string {
_ptr_text := C.strerror(code) // voidptr? _ptr_text := C.strerror(code) // voidptr?
@ -15,3 +22,26 @@ pub fn get_error_msg(code int) string {
} }
return tos(_ptr_text, C.strlen(_ptr_text)) return tos(_ptr_text, C.strlen(_ptr_text))
} }
pub fn ls(path string) []string {
mut res := []string
dir := C.opendir(path.str)
if isnil(dir) {
println('ls() couldnt open dir "$path"')
print_c_errno()
return res
}
mut ent := &C.dirent{!}
for {
ent = C.readdir(dir)
if isnil(ent) {
break
}
name := tos_clone(ent.d_name)
if name != '.' && name != '..' && name != '' {
res << name
}
}
C.closedir(dir)
return res
}

View File

@ -11,6 +11,39 @@ const (
// A handle to an object. // A handle to an object.
type HANDLE voidptr type HANDLE voidptr
pub fn ls(path string) []string {
mut find_file_data := win32finddata{}
mut dir_files := []string
// We can also check if the handle is valid. but using dir_exists instead
// h_find_dir := C.FindFirstFile(path.str, &find_file_data)
// if (INVALID_HANDLE_VALUE == h_find_dir) {
// return dir_files
// }
// C.FindClose(h_find_dir)
if !dir_exists(path) {
println('ls() couldnt open dir "$path" (does not exist).')
return dir_files
}
// NOTE: Should eventually have path struct & os dependant path seperator (eg os.PATH_SEPERATOR)
// we need to add files to path eg. c:\windows\*.dll or :\windows\*
path_files := '$path\\*'
// NOTE:TODO: once we have a way to convert utf16 wide character to utf8
// we should use FindFirstFileW and FindNextFileW
h_find_files := C.FindFirstFile(path_files.to_wide(), &find_file_data)
first_filename := string_from_wide(&u16(find_file_data.cFileName))
if first_filename != '.' && first_filename != '..' {
dir_files << first_filename
}
for C.FindNextFile(h_find_files, &find_file_data) {
filename := string_from_wide(&u16(find_file_data.cFileName))
if filename != '.' && filename != '..' {
dir_files << filename.clone()
}
}
C.FindClose(h_find_files)
return dir_files
}
// Ref - https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=vs-2019 // Ref - https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=vs-2019
// get_file_handle retrieves the operating-system file handle that is associated with the specified file descriptor. // get_file_handle retrieves the operating-system file handle that is associated with the specified file descriptor.
pub fn get_file_handle(path string) HANDLE { pub fn get_file_handle(path string) HANDLE {