CASM
AClustersApproachtoStatisticalMechanics
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
App_test.cpp
Go to the documentation of this file.
1 #define BOOST_TEST_DYN_LINK
2 #include <boost/test/unit_test.hpp>
3 
6 
8 #include <boost/filesystem.hpp>
9 
10 #include "Common.hh"
11 
12 using namespace CASM;
13 
14 struct Checks {
15 
16  Checks(std::string _type,
17  std::string _no_proj_command,
18  std::string _help_command) :
19  type(_type),
20  no_proj_command(_no_proj_command),
21  help_command(_help_command) {}
22 
23  std::string type;
24  std::string no_proj_command;
25  std::string help_command;
26 };
27 
28 BOOST_AUTO_TEST_SUITE(AppTest)
29 
30 BOOST_AUTO_TEST_CASE(ProjectCommands) {
31 
32  Popen p;
33  Log &log = default_log();
34 
35  // checks for what happens when running casm from a non-project directory
36  std::vector<Checks> command = {
37  Checks("composition", "-d", "-h"),
38  Checks("sym", "", "-h"),
39  Checks("bset", "", "-h"),
40  Checks("enum", "", "-h"),
41  Checks("select", "", "-h"),
42  Checks("query", "", "-h")
43  };
44 
45  // check help doesn't need to be in a project
46  p.popen("ccasm init -h");
47  BOOST_CHECK_MESSAGE(p.exit_code() == 0, p.gets());
48 
49  for(auto it = command.begin(); it != command.end(); ++it) {
50  p.popen("ccasm " + it->type + " " + it->no_proj_command);
51  BOOST_CHECK_MESSAGE(p.exit_code() == 3, p.gets());
52 
53  p.popen("ccasm " + it->type + " " + it->help_command);
54  BOOST_CHECK_MESSAGE(p.exit_code() == 0, p.gets());
55  }
56 
57  // checks of 'ccasm X' commands for several projects
58  std::vector<std::unique_ptr<test::Proj> > proj;
59  proj.push_back(notstd::make_unique<test::FCCTernaryProj>());
60  proj.push_back(notstd::make_unique<test::ZrOProj>());
61 
62  for(auto proj_it = proj.begin(); proj_it != proj.end(); ++proj_it) {
63  log.custom<Log::standard>("Test project: " + (*proj_it)->title);
64  log << "root: " << (*proj_it)->dir << std::endl;
65 
66  log << "testing 'ccasm init'" << std::endl;
67  (*proj_it)->check_init();
68 
69  log << "testing 'ccasm sym'" << std::endl;
70  (*proj_it)->check_symmetry();
71 
72  log << "testing 'ccasm composition'" << std::endl;
73  (*proj_it)->check_composition();
74 
75  log << "testing 'ccasm bset'" << std::endl;
76  (*proj_it)->check_bset();
77 
78  log << "testing 'ccasm enum'" << std::endl;
79  (*proj_it)->check_enum();
80 
81  log << "testing 'ccasm select'" << std::endl;
82  (*proj_it)->check_select();
83 
84  log << "testing 'ccasm query'" << std::endl;
85  (*proj_it)->check_query();
86 
87  log << "done" << std::endl;
88  log << std::endl;
89 
90  }
91 
92  log << "delete test projects" << std::endl;
93 
94  log << "delete proj[0]:" << std::endl;
95  proj[0].reset();
96  log << " done" << std::endl;
97 
98  log << "delete proj[1]:" << std::endl;
99  proj[1].reset();
100  log << " done" << std::endl;
101 
102  log << "leaving test cast ProjectCommands" << std::endl;
103 }
104 
105 BOOST_AUTO_TEST_SUITE_END()
std::string gets() const
Returns the stdout resulting from the last popen call.
Definition: Popen.cc:44
void popen(std::string _command)
Execute popen for a given command.
Definition: Popen.cc:19
Main CASM namespace.
Definition: complete.cpp:8
Log & log
Definition: settings.cc:105
Remember how to use popen.
Definition: Popen.hh:12
void custom(const std::string &what)
Definition: Log.hh:96
std::string no_proj_command
Definition: App_test.cpp:24
static const int standard
Definition: Log.hh:15
Checks(std::string _type, std::string _no_proj_command, std::string _help_command)
Definition: App_test.cpp:16
BOOST_AUTO_TEST_CASE(ProjectCommands)
Definition: App_test.cpp:30
void reset(std::ostream &_ostream=std::cout, int _verbosity=standard, bool _show_clock=false)
Definition: Log.cc:47
int help_command(const CommandArgs &args)
Print CASM help info to args.log.
int exit_code() const
Returns pclose(fp)/256.
Definition: Popen.cc:55
Log & default_log()
Definition: Log.hh:201
Definition: Log.hh:9
std::string type
Definition: App_test.cpp:23
std::string help_command
Definition: App_test.cpp:25