Implement a parser for a literate testing system for the repl
This parser can be reused for other purposes. It's inspired by https://bitheap.org/cram/ Although eelco's impostor exists https://github.com/mobusoperandi/eelco, it is not very nice to depend on out of tree testing frameworks with no way to customize them. Change-Id: Ifca50177e09730182baf0ebf829c3505bbb0274a
This commit is contained in:
@@ -131,7 +131,7 @@ ifeq ($(HAVE_LIBCPUID), 1)
|
||||
endif
|
||||
|
||||
ifeq ($(ENABLE_BUILD), yes)
|
||||
nix_tests += test-libstoreconsumer.sh
|
||||
nix_tests += test-libstoreconsumer.sh test-repl-characterization.sh
|
||||
|
||||
ifeq ($(BUILD_SHARED_LIBS), 1)
|
||||
nix_tests += plugins.sh
|
||||
@@ -142,6 +142,8 @@ $(d)/test-libstoreconsumer.sh.test $(d)/test-libstoreconsumer.sh.test-debug: \
|
||||
$(buildprefix)$(d)/test-libstoreconsumer/test-libstoreconsumer
|
||||
$(d)/plugins.sh.test $(d)/plugins.sh.test-debug: \
|
||||
$(buildprefix)$(d)/plugins/libplugintest.$(SO_EXT)
|
||||
$(d)/test-repl-characterization.sh.test $(d)/test-repl-characterization.sh.test-debug: \
|
||||
$(buildprefix)$(d)/repl_characterization/test-repl-characterization
|
||||
|
||||
install-tests += $(foreach x, $(nix_tests), $(d)/$(x))
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
test-repl-characterization
|
||||
@@ -0,0 +1,11 @@
|
||||
Commentary "meow meow meow"
|
||||
Command "command"
|
||||
Output "output output one"
|
||||
Output ""
|
||||
Output ""
|
||||
Output "output output two"
|
||||
Commentary "meow meow"
|
||||
Command "command two"
|
||||
Output "output output output"
|
||||
Commentary "commentary"
|
||||
Output "output output output"
|
||||
@@ -0,0 +1,11 @@
|
||||
meow meow meow
|
||||
nix-repl> command
|
||||
output output one
|
||||
|
||||
|
||||
output output two
|
||||
meow meow
|
||||
nix-repl> command two
|
||||
output output output
|
||||
commentary
|
||||
output output output
|
||||
@@ -0,0 +1,15 @@
|
||||
programs += test-repl-characterization
|
||||
|
||||
test-repl-characterization_DIR := $(d)
|
||||
|
||||
# do not install
|
||||
test-repl-characterization_INSTALL_DIR :=
|
||||
|
||||
test-repl-characterization_SOURCES := \
|
||||
$(wildcard $(d)/*.cc) \
|
||||
|
||||
test-repl-characterization_CXXFLAGS += -I src/libutil -I tests/unit/libutil-support -DNIX_BIN_DIR="\"$(bindir)\""
|
||||
|
||||
test-repl-characterization_LIBS = libutil libutil-test-support
|
||||
|
||||
test-repl-characterization_LDFLAGS = $(THREAD_LDFLAGS) $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) $(LOWDOWN_LIBS) $(GTEST_LIBS)
|
||||
@@ -0,0 +1,42 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <optional>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "tests/characterization.hh"
|
||||
#include "tests/cli-literate-parser.hh"
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
namespace nix {
|
||||
|
||||
static constexpr const char * REPL_PROMPT = "nix-repl> ";
|
||||
|
||||
class ReplSessionTest : public CharacterizationTest
|
||||
{
|
||||
Path unitTestData = getUnitTestData();
|
||||
|
||||
public:
|
||||
Path goldenMaster(std::string_view testStem) const override
|
||||
{
|
||||
return unitTestData + "/" + testStem;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(ReplSessionTest, parses)
|
||||
{
|
||||
writeTest("basic.ast", [this]() {
|
||||
const std::string content = readFile(goldenMaster("basic.test"));
|
||||
auto parser = CLILiterateParser{REPL_PROMPT};
|
||||
parser.feed(content);
|
||||
|
||||
std::ostringstream out{};
|
||||
for (auto & bit : parser.syntax()) {
|
||||
out << bit.print() << "\n";
|
||||
}
|
||||
return out.str();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
source common.sh
|
||||
|
||||
# You might think that this can trivially be moved into a makefile, however,
|
||||
# there is various environmental initialization of this shell framework that
|
||||
# seems load bearing and seemingly prevents the tests working inside the
|
||||
# builder.
|
||||
_NIX_TEST_UNIT_DATA=$(pwd)/repl_characterization/data ./repl_characterization/test-repl-characterization
|
||||
Reference in New Issue
Block a user