CLI test
This commit is contained in:
+7
-3
@@ -2,14 +2,18 @@
|
||||
set -e
|
||||
|
||||
# Test cppipe functions
|
||||
OKs=$(cppipe test/functions_test.cppipe | grep OK | wc -l)
|
||||
OKs=$(cppipe test/functions_test.cppipe 2>/dev/null | grep OK | wc -l)
|
||||
if ! [ $OKs = 12 ]
|
||||
then
|
||||
echo "EXPECTED 1 OKs, got $OKs"
|
||||
echo "Functions test failed: EXPECTED 12 OKs, got $OKs"
|
||||
exit 1
|
||||
fi
|
||||
echo Functions test OK!
|
||||
|
||||
# Test on a C file
|
||||
echo OK | cppipe test/c_file.c
|
||||
cppipe test/c_file.c
|
||||
|
||||
# Test the cppipe command
|
||||
./test/command_line_test.sh
|
||||
|
||||
echo ALL TESTS PASSED
|
||||
|
||||
+13
-17
@@ -59,6 +59,7 @@ SrcType find_src_type(string_view path);
|
||||
const char DEBUG_PREFIX[] = "__DBG";
|
||||
|
||||
// Context
|
||||
fs::path HOME;
|
||||
bool debug = false;
|
||||
fs::path src_file;
|
||||
SrcType src_type;
|
||||
@@ -72,6 +73,7 @@ int main(int argc, char* argv[])
|
||||
int src_arg = parse_args_until_src(argc, argv);
|
||||
|
||||
// Init context
|
||||
HOME = getenv("HOME");
|
||||
src_file = find_path_to_src( argv[src_arg] );
|
||||
src_type = find_src_type( argv[src_arg] );
|
||||
cache_dir = get_cache_dir_path(src_file);
|
||||
@@ -146,12 +148,6 @@ fs::path find_path_to_src(string_view src_file)
|
||||
return src_file;
|
||||
}
|
||||
|
||||
// Search in ~/cppipe
|
||||
if(fs::path p = fs::path(getenv("HOME")) / "cppipe" / src_file; fs::exists(p))
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
// Search files on CPPIPEPATH
|
||||
const char* cppipepath_var = getenv("CPPIPEPATH");
|
||||
if(cppipepath_var) // is set
|
||||
@@ -161,16 +157,11 @@ fs::path find_path_to_src(string_view src_file)
|
||||
;
|
||||
begin = end+1, end = cppipepath.find(':', begin) )
|
||||
{
|
||||
const string_view path_entry = cppipepath.substr(begin, end - begin);
|
||||
if( fs::is_directory(path_entry) )
|
||||
const fs::path path_entry = cppipepath.substr(begin, end - begin);
|
||||
|
||||
if( fs::path p = path_entry / src_file; fs::exists(p) )
|
||||
{
|
||||
for(const fs::directory_entry& e: fs::directory_iterator(path_entry))
|
||||
{
|
||||
if(fs::is_regular_file(e) && e.path().filename() == src_file)
|
||||
{
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
if(end == string::npos)
|
||||
@@ -178,6 +169,12 @@ fs::path find_path_to_src(string_view src_file)
|
||||
}
|
||||
}
|
||||
|
||||
// Search in ~/cppipe
|
||||
if(fs::path p = HOME / "cppipe" / src_file; fs::exists(p)) // todo: what if ~/cppipe/../... matches
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
// Couln't find the src
|
||||
cerr << "File: " << src_file << " doesn't exist\n";
|
||||
exit(1);
|
||||
@@ -193,8 +190,7 @@ fs::path get_cache_dir_path(const fs::path& src_file)
|
||||
}
|
||||
else
|
||||
{
|
||||
char* home( getenv("HOME") );
|
||||
cache_dir = home;
|
||||
cache_dir = HOME;
|
||||
cache_dir /= ".cache/cppipe";
|
||||
}
|
||||
cache_dir += fs::canonical( src_file ).parent_path();
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ int main()
|
||||
x = y; /* should only work on C */
|
||||
if(x == 0)
|
||||
{
|
||||
printf("C compilation OK!\n");
|
||||
printf("C compilation: OK!\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
export CPPIPEPATH="/:test::/usr"
|
||||
|
||||
cppipe c_file.c > /dev/null
|
||||
|
||||
echo Command line test: OK!
|
||||
@@ -3,20 +3,18 @@ tips (sigaction SIGCHILD, SIG_IGN, SIG_DFL)
|
||||
make sure file descriptors are closed when no longer used
|
||||
cppipe compile options from tft
|
||||
respect CXXFLAGS LDFLAGS
|
||||
remove append_args
|
||||
|
||||
?
|
||||
run(cmd)
|
||||
string args
|
||||
args before src file go to compiler
|
||||
use exceptions (open_or_die)
|
||||
throw when a command couldnt be ran
|
||||
precompiled header cppipe.h
|
||||
-Wno-unused-result in install.sh
|
||||
file operations, lack of uniformity (C++ vs POSIX)
|
||||
Check all return codes and report errors
|
||||
shaded obj
|
||||
uninstall
|
||||
throw when a command couldnt be ran
|
||||
improve debug (the src file shown is the .ii)
|
||||
no optimizations option
|
||||
split
|
||||
|
||||
Reference in New Issue
Block a user