summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Jenkinsfile6
-rw-r--r--test/suite/ctor_files/ctor.cc.generated48
-rw-r--r--test/suite/test.cc333
-rwxr-xr-xtest/suite/test.sh118
4 files changed, 385 insertions, 120 deletions
diff --git a/Jenkinsfile b/Jenkinsfile
index e518b6c..aad3052 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -15,7 +15,7 @@ pipeline {
echo 'Testing (clang) ...'
sh './ctor check'
echo 'Testing suite (clang) ...'
- sh '(cd test/suite; CTORDIR=../../build CXXFLAGS=-Werror CXX=/usr/local/opt/llvm/bin/clang++ LDFLAGS="-L/usr/local/opt/llvm/lib/c++ -L/usr/local/opt/llvm/lib/unwind -lunwind" ./test.sh)'
+ sh '(cd test/suite; /usr/local/opt/llvm/bin/clang++ -std=c++20 test.cc -L/usr/local/opt/llvm/lib/c++ -L/usr/local/opt/llvm/lib/unwind -lunwind -o test && CTORDIR=../../build CXXFLAGS=-Werror CXX=/usr/local/opt/llvm/bin/clang++ LDFLAGS="-L/usr/local/opt/llvm/lib/c++ -L/usr/local/opt/llvm/lib/unwind -lunwind" ./test)'
}
post {
always {
@@ -36,7 +36,7 @@ pipeline {
echo 'Testing (gcc) ...'
sh './ctor check'
echo 'Testing suite (gcc) ...'
- sh '(cd test/suite; CTORDIR=../../build CXXFLAGS=-Werror CXX=g++ ./test.sh)'
+ sh '(cd test/suite; g++ -std=c++20 test.cc -o test && CTORDIR=../../build CXXFLAGS=-Werror CXX=g++ ./test)'
}
post {
always {
@@ -57,7 +57,7 @@ pipeline {
echo 'Testing (clang) ...'
sh './ctor check'
echo 'Testing suite (clang) ...'
- sh '(cd test/suite; CTORDIR=../../build CXXFLAGS=-Werror CXX=clang++ ./test.sh)'
+ sh '(cd test/suite; clang++ -std=c++20 test.cc -o test && CTORDIR=../../build CXXFLAGS=-Werror CXX=clang++ ./test)'
}
post {
always {
diff --git a/test/suite/ctor_files/ctor.cc.generated b/test/suite/ctor_files/ctor.cc.generated
new file mode 100644
index 0000000..5f82fd4
--- /dev/null
+++ b/test/suite/ctor_files/ctor.cc.generated
@@ -0,0 +1,48 @@
+// -*- c++ -*-
+// Distributed under the BSD 2-Clause License.
+// See accompanying file LICENSE for details.
+#include <ctor.h>
+#include <filesystem>
+#include <iostream>
+
+namespace
+{
+ctor::build_configurations ctorConfigs(const ctor::settings& settings)
+{
+ return
+ {
+ {
+ .target = "world",
+ .sources = {
+ { "world.cc", ctor::source_type::generated },
+ },
+ },
+ {
+ .target = "foo",
+ .sources = {
+ { "foo.cc", ctor::source_type::generated },
+ },
+ },
+ {
+ .target = "this_is_unused",
+ .sources = {
+ {"hello.cc", ctor::output_file{"world.cc"}},
+ {"hello.cc", ctor::output_file{"foo.cc"}},
+ },
+ .function = [](const std::string& input,
+ const std::string& output,
+ const ctor::build_configuration& config,
+ const ctor::settings& settings)
+ {
+ namespace fs = std::filesystem;
+ std::cout << "Input: " << input << '\n';
+ std::cout << "Output: " << output << '\n';
+ fs::copy_file(input, output, fs::copy_options::overwrite_existing);
+ return 0;
+ }
+ },
+ };
+}
+}
+
+REG(ctorConfigs);
diff --git a/test/suite/test.cc b/test/suite/test.cc
new file mode 100644
index 0000000..b9a6cc3
--- /dev/null
+++ b/test/suite/test.cc
@@ -0,0 +1,333 @@
+// -*- c++ -*-
+// Distributed under the BSD 2-Clause License.
+// See accompanying file LICENSE for details.
+#include "../../src/util.cc"
+#include "../../src/pointerlist.cc"
+#include "../../src/execute.cc"
+
+#include <iostream>
+#include <string>
+#include <filesystem>
+#include <thread>
+#include <chrono>
+#include <sstream>
+
+std::vector<std::string> tokenize(const std::string& str)
+{
+ std::vector<std::string> tokens;
+ std::stringstream ss(str);
+ std::string token;
+ while(getline(ss, token, ' '))
+ {
+ tokens.push_back(token);
+ }
+ return tokens;
+}
+
+int fail(int value = 1,
+ const std::source_location location = std::source_location::current())
+{
+ std::cout << "*** Failure at line " << location.line() << '\n';
+ return value;
+}
+
+int main()
+{
+ using namespace std::chrono_literals;
+ ctor::settings settings{};
+ settings.verbose = 2;
+ auto paths = get_paths();
+
+ std::string CXX = "g++";
+ get_env("CXX", CXX);
+ std::string CTORDIR = "../../build";
+ get_env("CTORDIR", CTORDIR);
+ std::string BUILDDIR = "build";
+ get_env("BUILDDIR", BUILDDIR);
+ std::string CXXFLAGS;
+ get_env("CXXFLAGS", CXXFLAGS);
+ std::string LDFLAGS;
+ get_env("LDFLAGS", LDFLAGS);
+
+ auto cxx_prog = locate(CXX, paths);
+
+ // Wipe the board
+ std::filesystem::remove_all(BUILDDIR);
+ std::filesystem::remove("configuration.cc");
+ std::filesystem::remove("config.h");
+ std::filesystem::remove("ctor");
+
+ //////////////////////////////////////////////////////////////////////////////
+ std::cout << "** ctor_files/ctor.cc.base\n";
+ std::filesystem::copy("ctor_files/ctor.cc.base", "ctor.cc",
+ std::filesystem::copy_options::overwrite_existing);
+
+ // Compile bootstrap binary
+ std::vector<std::string> args =
+ {"-pthread", "-std=c++20", "-L", CTORDIR, "-lctor", "-I", "../../src",
+ "ctor.cc", "-o", "ctor"};
+
+ // TODO: add support for quoted strings with spaces
+ if(!CXXFLAGS.empty())
+ {
+ auto tokens = tokenize(CXXFLAGS);
+ for(const auto& token : tokens)
+ {
+ args.push_back(token);
+ }
+ }
+ if(!LDFLAGS.empty())
+ {
+ auto tokens = tokenize(LDFLAGS);
+ for(const auto& token : tokens)
+ {
+ args.push_back(token);
+ }
+ }
+
+ auto ret = execute(settings, cxx_prog, args);
+ if(ret != 0)
+ {
+ return fail(ret);
+ }
+
+ // No build files should have been created yet
+ if(std::filesystem::exists(BUILDDIR))
+ {
+ return fail();
+ }
+
+ // capture ctor binary before configure is called
+ auto ctor_bin = readFile("ctor");
+ args = {"configure", "--ctor-includedir", "../../src",
+ "--ctor-libdir="+CTORDIR, "--build-dir="+BUILDDIR};
+ ret = execute(settings, "./ctor", args);
+ if(ret != 0)
+ {
+ return fail(ret);
+ }
+
+ // ctor should be rebuilt at this point, so binary should have changed
+ auto ctor_bin2 = readFile("ctor");
+ if(ctor_bin == ctor_bin2)
+ {
+ return fail();
+ }
+
+ // configuration.cc should have been generated now
+ if(!std::filesystem::exists("configuration.cc"))
+ {
+ return fail();
+ }
+ if(!std::filesystem::exists("config.h"))
+ {
+ return fail();
+ }
+
+ // Shouldn't compile anything yet - only configure
+ if(std::filesystem::exists(BUILDDIR+"/hello-hello_cc.o"))
+ {
+ return fail();
+ }
+
+ ctor_bin = readFile("ctor");
+
+ // Run normally to build project
+ args = {"-v"};
+ ret = execute(settings, "./ctor", args);
+ if(ret != 0)
+ {
+ return fail(ret);
+ }
+
+ // Compiled object should now exist
+ if(!std::filesystem::exists(BUILDDIR+"/hello-hello_cc.o"))
+ {
+ return fail();
+ }
+
+ // ctor should not have been rebuilt, so binary should be the same
+ ctor_bin2 = readFile("ctor");
+ if(ctor_bin != ctor_bin2)
+ {
+ return fail();
+ }
+
+ std::this_thread::sleep_for(1100ms);
+
+ auto time = std::filesystem::last_write_time(BUILDDIR+"/hello-hello_cc.o");
+ std::filesystem::last_write_time("hello.cc", time + 1s);
+ std::this_thread::sleep_for(1100ms);
+
+ // Run normally to rebuild hello.cc
+ args = {"-v"};
+ ret = execute(settings, "./ctor", args);
+ if(ret != 0)
+ {
+ return fail(ret);
+ }
+
+ // Object file should have been recompiled
+ auto time2 = std::filesystem::last_write_time(BUILDDIR+"/hello-hello_cc.o");
+ if(time == time2)
+ {
+ return fail();
+ }
+
+ //////////////////////////////////////////////////////////////////////////////
+ // Replace -DFOO with -DBAR in foo external.cxxflags
+ std::cout << "** ctor_files/ctor.cc.bar\n";
+ std::filesystem::copy("ctor_files/ctor.cc.bar", "ctor.cc",
+ std::filesystem::copy_options::overwrite_existing);
+
+ auto configuration_cc_bin = readFile("configuration.cc");
+ ctor_bin = readFile("ctor");
+ time = std::filesystem::last_write_time(BUILDDIR+"/hello-hello_cc.o");
+ std::this_thread::sleep_for(1100ms);
+
+ // Run normally to reconfigure, rebuild ctor and rebuild hello.cc
+ args = {"-v"};
+ ret = execute(settings, "./ctor", args);
+ if(ret != 0)
+ {
+ return fail(ret);
+ }
+
+ time2 = std::filesystem::last_write_time(BUILDDIR+"/hello-hello_cc.o");
+ if(time == time2)
+ {
+ return fail();
+ }
+
+ auto configuration_cc_bin2 = readFile("configuration.cc");
+ if(configuration_cc_bin == configuration_cc_bin2)
+ {
+ return fail();
+ }
+
+ ctor_bin2 = readFile("ctor");
+ if(ctor_bin == ctor_bin2)
+ {
+ return fail();
+ }
+
+ //////////////////////////////////////////////////////////////////////////////
+ std::cout << "** ctor_files/ctor.cc.multi\n";
+ std::filesystem::copy("ctor_files/ctor.cc.multi", "ctor.cc",
+ std::filesystem::copy_options::overwrite_existing);
+
+ configuration_cc_bin = readFile("configuration.cc");
+ ctor_bin = readFile("ctor");
+ time = std::filesystem::last_write_time(BUILDDIR+"/hello-hello_cc.o");
+ std::this_thread::sleep_for(1100ms);
+
+ // Run normally to reconfigure, rebuild ctor and rebuild hello.cc
+ args = {"-v"};
+ ret = execute(settings, "./ctor", args);
+ if(ret != 0)
+ {
+ return fail(ret);
+ }
+
+ time2 = std::filesystem::last_write_time(BUILDDIR+"/hello-hello_cc.o");
+ if(time == time2)
+ {
+ return fail();
+ }
+
+ configuration_cc_bin2 = readFile("configuration.cc");
+ if(configuration_cc_bin == configuration_cc_bin2)
+ {
+ return fail();
+ }
+
+ ctor_bin2 = readFile("ctor");
+ if(ctor_bin == ctor_bin2)
+ {
+ return fail();
+ }
+
+ // now touching foobar.h, should retrigger re-configuration
+ time = std::filesystem::last_write_time("ctor");
+ std::filesystem::last_write_time("foobar.h", time + 1s);
+ time = std::filesystem::last_write_time("ctor");
+ std::this_thread::sleep_for(1100ms);
+
+ // Run normally to reconfigure, rebuild ctor and rebuild hello.cc
+ args = {"-v"};
+ ret = execute(settings, "./ctor", args);
+ if(ret != 0)
+ {
+ return fail(ret);
+ }
+
+ time2 = std::filesystem::last_write_time("ctor");
+ if(time == time2)
+ {
+ return fail();
+ }
+
+ //////////////////////////////////////////////////////////////////////////////
+ std::cout << "** ctor_files/ctor.cc.generated\n";
+ std::filesystem::copy("ctor_files/ctor.cc.generated", "ctor.cc",
+ std::filesystem::copy_options::overwrite_existing);
+
+ std::filesystem::remove(BUILDDIR+"/world.cc");
+ std::filesystem::remove(BUILDDIR+"/foo.cc");
+
+ configuration_cc_bin = readFile("configuration.cc");
+ ctor_bin = readFile("ctor");
+ std::this_thread::sleep_for(1100ms);
+
+ // Run normally to reconfigure, rebuild ctor and build world.cc
+ args = {"-v", "world"};
+ ret = execute(settings, "./ctor", args);
+ if(ret != 0)
+ {
+ return fail(ret);
+ }
+
+ configuration_cc_bin2 = readFile("configuration.cc");
+ if(configuration_cc_bin == configuration_cc_bin2)
+ {
+ return fail();
+ }
+
+ ctor_bin2 = readFile("ctor");
+ if(ctor_bin == ctor_bin2)
+ {
+ return fail();
+ }
+
+ // foo.cc should not be generated at this point
+ if(std::filesystem::exists(BUILDDIR+"/foo.cc"))
+ {
+ return fail();
+ }
+
+ auto time_w = std::filesystem::last_write_time(BUILDDIR+"/world.cc");
+ auto time_wo = std::filesystem::last_write_time(BUILDDIR+"/"+BUILDDIR+"/world-world_cc.o");
+ std::this_thread::sleep_for(1100ms);
+
+ // now touching hello.cc, should trigger regeneration of world.cc and rebuild
+ std::filesystem::last_write_time("hello.cc", time_w + 1s);
+ args = {"-v", "world"};
+ ret = execute(settings, "./ctor", args);
+ if(ret != 0)
+ {
+ return fail(ret);
+ }
+
+ auto time_w2 = std::filesystem::last_write_time(BUILDDIR+"/world.cc");
+ auto time_wo2 = std::filesystem::last_write_time(BUILDDIR+"/"+BUILDDIR+"/world-world_cc.o");
+ if(time_w == time_w2)
+ {
+ return fail();
+ }
+ if(time_wo == time_wo2)
+ {
+ return fail();
+ }
+
+ return 0;
+}
diff --git a/test/suite/test.sh b/test/suite/test.sh
index c54137a..4638c0d 100755
--- a/test/suite/test.sh
+++ b/test/suite/test.sh
@@ -1,120 +1,4 @@
#!/bin/bash
: ${CXX:=g++}
-: ${CTORDIR:=../../build}
-: ${BUILDDIR:=build}
-CXX=$(which $CXX)
-
-function fail
-{
- echo "*** Failure at line $1"
- exit 1
-}
-
-function ctor
-{
- echo "*** Running: ./ctor $*"
- ./ctor $*
-}
-
-STAT_FORMAT="-c %Y"
-if [[ "$OSTYPE" == "darwin"* ]]; then
- # Mac OSX
- STAT_FORMAT="-f %B"
-fi
-
-# Wipe the board
-rm -Rf ${BUILDDIR}
-rm -f configuration.cc
-rm -f ctor
-
-echo "** ctor_files/ctor.cc.base"
-cp ctor_files/ctor.cc.base ctor.cc
-
-# Compile bootstrap binary
-$CXX -pthread $LDFLAGS $CXXFLAGS -std=c++20 -L${CTORDIR} -lctor -I../../src ctor.cc -o ctor || fail ${LINENO}
-
-# No build files should have been created yet
-[ -d ${BUILDDIR} ] && fail ${LINENO}
-
-# capture md5 sum of ctor binary before configure is called
-MD5=`md5sum ctor`
-ctor configure --ctor-includedir ../../src --ctor-libdir=${CTORDIR} --build-dir=${BUILDDIR}
-
-# ctor should be rebuilt at this point, so md5 sum should have changed
-(echo $MD5 | md5sum --status -c) && fail ${LINENO}
-
-# configuration.cc should have been generated now
-[ ! -f configuration.cc ] && fail ${LINENO}
-
-# Shouldn't compile anything yet - only configure
-[ -f ${BUILDDIR}/hello-hello_cc.o ] && fail ${LINENO}
-
-MD5=`md5sum ctor`
-
-# Run normally to build project
-ctor -v
-
-# Compiled object should now exist
-[ ! -f ${BUILDDIR}/hello-hello_cc.o ] && fail ${LINENO}
-
-# ctor should not have been rebuilt, so md5 sum should be the same
-(echo $MD5 | md5sum --status -c) || fail ${LINENO}
-
-MOD1=`stat $STAT_FORMAT ${BUILDDIR}/hello-hello_cc.o`
-touch hello.cc
-sleep 1.1
-
-# Run normally to rebuild hello.cc
-ctor -v
-
-# Object file should have been recompiled
-MOD2=`stat $STAT_FORMAT ${BUILDDIR}/hello-hello_cc.o`
-[[ $MOD1 == $MOD2 ]] && fail ${LINENO}
-
-# Replacve -DFOO with -DBAR in foo external.cxxflags
-echo "** ctor_files/ctor.cc.bar"
-cp ctor_files/ctor.cc.bar ctor.cc
-
-MD5C=`md5sum configuration.cc`
-MD5=`md5sum ctor`
-MOD1=`stat $STAT_FORMAT build/hello-hello_cc.o`
-sleep 1.1
-
-# Run normally to reconfigure, rebuild ctor and rebuild hello.cc
-ctor -v
-
-MOD2=`stat $STAT_FORMAT ${BUILDDIR}/hello-hello_cc.o`
-[[ $MOD1 == $MOD2 ]] && fail ${LINENO}
-(echo $MD5C | md5sum --status -c) && fail ${LINENO}
-(echo $MD5 | md5sum --status -c) && fail ${LINENO}
-
-echo "** ctor_files/ctor.cc.multi"
-cp ctor_files/ctor.cc.multi ctor.cc
-
-MD5C=`md5sum configuration.cc`
-MD5=`md5sum ctor`
-MOD1=`stat $STAT_FORMAT ${BUILDDIR}/hello-hello_cc.o`
-sleep 1.1
-
-# Run normally to reconfigure, rebuild ctor and rebuild hello.cc
-ctor -v
-
-MOD2=`stat $STAT_FORMAT ${BUILDDIR}/hello-hello_cc.o`
-[[ $MOD1 == $MOD2 ]] && fail ${LINENO}
-(echo $MD5C | md5sum --status -c) && fail ${LINENO}
-(echo $MD5 | md5sum --status -c) && fail ${LINENO}
-
-# now touching foobar.h, should retrigger re-configuration
-touch foobar.h
-
-MOD1=`stat $STAT_FORMAT ctor`
-sleep 1.1
-
-# Run normally to reconfigure, rebuild ctor and rebuild hello.cc
-ctor -v
-
-MOD2=`stat $STAT_FORMAT ctor`
-[[ $MOD1 == $MOD2 ]] && fail ${LINENO}
-
-exit 0
+$CXX $LDFLAGS $CXXFLAGS -std=c++20 -Wall test.cc -o test && ./test