mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Squashed: Added integration and standalone tests, read more
This wasn't an easy fix, as it was primarily the test pipelines that were failing. I resorted to using forced pushes to run the CI, to try and track down the problems. The primary cause seems to be the differences in how each supported platform handles file paths, specifically, slash vs. backslash. I've also added gdb scripts to set up automated breakpoints, and to run operations on them to check for issues - the 'gdb_init' files are mostly empty for the time being. commit a34b0ff5d407bbe7d70ff9504aa035ec6fbecb7c Author: Kayne Ruse <kayneruse@gmail.com> Date: Fri Oct 18 11:45:40 2024 +1100 Restored the workflows commit eb3d94f30d4dc4150139517f44cc874f2901124f Author: Kayne Ruse <kayneruse@gmail.com> Date: Fri Oct 18 11:35:39 2024 +1100 I think the library path on macos is fixed commit 964572b5e93c7cb464686f19ddbe3e9d315f391b Author: Kayne Ruse <kayneruse@gmail.com> Date: Fri Oct 18 11:22:56 2024 +1100 I think the file paths are fixed commit 1721f3da7252b4063f4347926e800ef4f7c9bf4c Author: Kayne Ruse <kayneruse@gmail.com> Date: Thu Oct 17 15:57:28 2024 +1100 Added standalone tests commit 90c783f4059d88f4a7bbaf18215a9b414f3ab66f Author: Kayne Ruse <kayneruse@gmail.com> Date: Thu Oct 17 15:01:18 2024 +1100 Trying to fix the integration test pipeline commit fccced1396568a55c1385e2f1b04fedf7c2585a5 Author: Kayne Ruse <kayneruse@gmail.com> Date: Wed Oct 16 00:31:39 2024 +1100 Workflow integration tests are not passing commit 6b1e0d1e0f89291e89768bf6102f4f7ed4581496 Author: Kayne Ruse <kayneruse@gmail.com> Date: Tue Oct 15 20:07:20 2024 +1100 Fixed file paths in workflow commit c0f1ec78fe79a5abb34c3e05308236cb18c23b97 Author: Kayne Ruse <kayneruse@gmail.com> Date: Tue Oct 15 19:46:14 2024 +1100 Moved example scripts into proper integration tests Also adjusted makefiles to allow easy invoking of the tests. Adjusted and updated CI to invoke tests correctly. Fixed #141
This commit is contained in:
83
repl/main.c
83
repl/main.c
@@ -1,12 +1,27 @@
|
||||
#include "toy.h"
|
||||
#include "toy_print.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
//utilities
|
||||
#define APPEND(dest, src) \
|
||||
strncpy((dest) + (strlen(dest)), (src), strlen((src)) + 1);
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define FLIPSLASH(str) for (int i = 0; str[i]; i++) str[i] = str[i] == '/' ? '\\' : str[i];
|
||||
#else
|
||||
#define FLIPSLASH(str) for (int i = 0; str[i]; i++) str[i] = str[i] == '\\' ? '/' : str[i];
|
||||
#endif
|
||||
|
||||
unsigned char* readFile(char* path, int* size) {
|
||||
//BUGFIX: fix the path based on platform - it might be slower, but it's better than dealing with platform crap
|
||||
int pathLength = strlen(path);
|
||||
char realPath[pathLength + 1];
|
||||
strncpy(realPath, path, pathLength);
|
||||
realPath[pathLength] = '\0';
|
||||
FLIPSLASH(realPath);
|
||||
|
||||
//open the file
|
||||
FILE* file = fopen(path, "rb");
|
||||
if (file == NULL) {
|
||||
@@ -26,29 +41,38 @@ unsigned char* readFile(char* path, int* size) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//
|
||||
//read the file
|
||||
if (fread(buffer, sizeof(unsigned char), *size, file) < *size) {
|
||||
fclose(file);
|
||||
*size = -2; //singal a read error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
|
||||
buffer[(*size)++] = '\0';
|
||||
|
||||
//clean up and return
|
||||
fclose(file);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int getDirPath(char* dest, const char* src) {
|
||||
//extract the directory from src, and store it in dest
|
||||
int getFilePath(char* dest, const char* src) {
|
||||
char* p = NULL;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
char* p = strrchr(src, '\\');
|
||||
#else
|
||||
char* p = strrchr(src, '/');
|
||||
#endif
|
||||
//find the last slash, regardless of platform
|
||||
p = strrchr(src, '\\');
|
||||
if (p == NULL) {
|
||||
p = strrchr(src, '/');
|
||||
}
|
||||
if (p == NULL) {
|
||||
int len = strlen(src);
|
||||
strncpy(dest, src, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
int len = p != NULL ? p - src + 1 : 0;
|
||||
//determine length of the path
|
||||
int len = p - src + 1;
|
||||
|
||||
//copy to the dest
|
||||
strncpy(dest, src, len);
|
||||
dest[len] = '\0';
|
||||
|
||||
@@ -56,30 +80,31 @@ int getDirPath(char* dest, const char* src) {
|
||||
}
|
||||
|
||||
int getFileName(char* dest, const char* src) {
|
||||
//extract the directory from src, and store it in dest
|
||||
char* p = NULL;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
char* p = strrchr(src, '\\') + 1;
|
||||
#else
|
||||
char* p = strrchr(src, '/') + 1;
|
||||
#endif
|
||||
//find the last slash, regardless of platform
|
||||
p = strrchr(src, '\\');
|
||||
if (p == NULL) {
|
||||
p = strrchr(src, '/');
|
||||
}
|
||||
if (p == NULL) {
|
||||
int len = strlen(src);
|
||||
strncpy(dest, src, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
p++; //skip the slash
|
||||
|
||||
//determine length of the file name
|
||||
int len = strlen(p);
|
||||
|
||||
//copy to the dest
|
||||
strncpy(dest, p, len);
|
||||
dest[len] = '\0';
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
#define APPEND(dest, src) \
|
||||
strncpy((dest) + (strlen(dest)), (src), strlen((src)) + 1);
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define FLIPSLASH(str) for (int i = 0; str[i]; i++) str[i] = str[i] == '/' ? '\\' : str[i];
|
||||
#else
|
||||
#define FLIPSLASH(str) for (int i = 0; str[i]; i++) str[i] = str[i] == '\\' ? '/' : str[i];
|
||||
#endif
|
||||
|
||||
//handle command line arguments
|
||||
typedef struct CmdLine {
|
||||
bool error;
|
||||
@@ -96,6 +121,8 @@ void usageCmdLine(int argc, const char* argv[]) {
|
||||
void helpCmdLine(int argc, const char* argv[]) {
|
||||
usageCmdLine(argc, argv);
|
||||
|
||||
printf("The Toy Programming Language, leave arguments blank for an interactive REPL.\n\n");
|
||||
|
||||
printf(" -h, --help\t\t\tShow this help then exit.\n");
|
||||
printf(" -v, --version\t\t\tShow version and copyright information then exit.\n");
|
||||
printf(" -f, --file infile\t\tParse, compile and execute the source file then exit.\n");
|
||||
@@ -159,7 +186,7 @@ CmdLine parseCmdLine(int argc, const char* argv[]) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
getDirPath(cmd.infile, argv[0]);
|
||||
getFilePath(cmd.infile, argv[0]);
|
||||
APPEND(cmd.infile, argv[i]);
|
||||
FLIPSLASH(cmd.infile);
|
||||
}
|
||||
|
||||
@@ -46,37 +46,6 @@ $(REPL_OUTDIR)/$(REPL_TARGETNAME): $(REPL_OBJFILES)
|
||||
ifeq ($(shell uname),Darwin) #dylib fix
|
||||
otool -L $@
|
||||
install_name_tool -add_rpath @executable_path/. $@
|
||||
install_name_tool -change ../out/libToy.dylib @executable_path/libToy.dylib $@
|
||||
install_name_tool -change $(REPL_OUTDIR)/libToy.dylib @executable_path/libToy.dylib $@
|
||||
otool -L $@
|
||||
endif
|
||||
|
||||
#util commands
|
||||
.PHONY: clean
|
||||
clean:
|
||||
ifeq ($(shell uname),Linux)
|
||||
find . -type f -name '*.o' -delete
|
||||
find . -type f -name '*.a' -delete
|
||||
find . -type f -name '*.exe' -delete
|
||||
find . -type f -name '*.dll' -delete
|
||||
find . -type f -name '*.lib' -delete
|
||||
find . -type f -name '*.so' -delete
|
||||
find . -type f -name '*.dylib' -delete
|
||||
find . -type d -name 'out' -delete
|
||||
find . -type d -name 'obj' -delete
|
||||
else ifeq ($(OS),Windows_NT)
|
||||
$(RM) *.o *.a *.exe *.dll *.lib *.so *.dylib
|
||||
$(RM) out
|
||||
$(RM) obj
|
||||
else ifeq ($(shell uname),Darwin)
|
||||
find . -type f -name '*.o' -delete
|
||||
find . -type f -name '*.a' -delete
|
||||
find . -type f -name '*.exe' -delete
|
||||
find . -type f -name '*.dll' -delete
|
||||
find . -type f -name '*.lib' -delete
|
||||
find . -type f -name '*.so' -delete
|
||||
find . -type f -name '*.dylib' -delete
|
||||
find . -type d -name 'out' -delete
|
||||
find . -type d -name 'obj' -delete
|
||||
else
|
||||
@echo "Deletion failed - what platform is this?"
|
||||
endif
|
||||
|
||||
Reference in New Issue
Block a user