first commit of tester tool

This commit is contained in:
Bob Polis 2020-04-29 15:27:40 +02:00
parent 50b9fd3af7
commit 5272dc7edd
3 changed files with 114 additions and 0 deletions

45
tester/Makefile Normal file
View File

@ -0,0 +1,45 @@
BIN := $(shell basename $$(pwd))
SRCS := $(wildcard *.cpp)
OBJS := $(subst .cpp,.o,$(SRCS))
DEPS := $(subst .cpp,.d,$(SRCS))
CXX ?= g++
PKG_CONFIG ?= pkg-config
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
DATADIR ?= $(PREFIX)/share
MANDIR ?= $(DATADIR)/man
RM := /bin/rm -f
INSTALL := /usr/bin/install -c
CXXFLAGS := $(CXXFLAGS) -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -pthread
ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0
else
CXXFLAGS += -D NDEBUG -O3
endif
LDLIBS := -lm -lpthread -lsclogging
all: $(BIN)
$(BIN): $(OBJS) $(DEPS)
$(CXX) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $(BIN)
%.o: %.cpp %.d Makefile
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
-include *.d
%.d: ;
.PHONY: clean install
clean:
$(RM) $(OBJS) $(DEPS) $(BIN)
install: $(BIN)
$(INSTALL) $(BIN) $(DESTDIR)$(BINDIR)

69
tester/main.cpp Normal file
View File

@ -0,0 +1,69 @@
//
// main.cpp
// tester
//
// Created by Bob Polis at 2020-04-29
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include <iostream>
#include <cstdlib>
#include <string>
#include <getopt.h>
#include <libsclogging.hpp>
void print_help() {
std::cout << "usage: tester [-h][-v]\n";
std::cout << " -h, --help show this help text and exit\n";
std::cout << " -v, --version show version number and exit\n";
}
void print_version() {
std::cout << "tester version 1.0\n";
}
int main(int argc, const char * argv[]) {
try {
struct option long_options[] = {
{"help", no_argument, nullptr, 'h'},
{"test", required_argument, nullptr, 't'},
{"version", no_argument, nullptr, 'v'},
{nullptr, 0, nullptr, 0}
};
int opt_char, option_index;
while ((opt_char = getopt_long(argc, const_cast<char* const *>(argv), "ht:v", long_options, &option_index)) != -1) {
switch (opt_char) {
case 0: {
// handle long-only options here
std::string optname {long_options[option_index].name};
break;
}
case 'h':
print_help();
return EXIT_SUCCESS;
case 'v':
print_version();
return EXIT_SUCCESS;
case '?':
throw std::runtime_error("unrecognized option");
}
}
if (optind == argc) {
// here when no file args
}
for (int i = optind; i < argc; ++i) {
try {
// process file argv[i]
} catch (const std::runtime_error& ex) {
std::cerr << "tester: " << ex.what() << '\n';
}
}
std::cout << "hello, tester\n";
sc::logger logger(sc::loglevel::debug);
logger.msg(sc::loglevel::info, 42, " = ", 6, " x ", 7);
} catch (const std::exception& ex) {
std::cerr << "tester: " << ex.what() << '\n';
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

BIN
tester/tester Executable file

Binary file not shown.